I created one database table. The Attributes in that table are Question_no,question,ans1,ans2,ans3,ans4,correct ans,practical_lab,sub_topic...
I created 100 rows.
My question is...
whether it is possible to insert a new row inbetween..How to insert the rows inbetween..
Eg: if ten(1,2,3,4,5,6,7,8,9,10) rows are there.Then How to insert a new row between 5 and 6.
kindly send me the answer yaar..I will be very much thankfull to you...
Jignesh TrivediPosted Mar 18, 2013, 8:26 AM
hi,
you can achive this using adding column called questionOrder that contain ordering of question.
so in you example you can get two 5 no question.
how this will help you.
Nitesh SinghalPosted Mar 18, 2013, 7:17 AM
you wants to insert row at 6
you need to take five steps
1.first put data into temp table rows 6 to 100
2. delete rows from 6 to 100
3.set auto identity key of your table to 5
4.insert your row
5.Insert your data from temp table to your table
6.Drop temp table
now lets see in practical..
assume you have Id as your primary key of your table
1.select Question_no,question,ans1,ans2,ans3,ans4,correct ans,practical_lab,sub_topic
into #temp from table where Id>5
2.delete from table where where Id>5
3.DBCC CHECKIDENT (table , reseed, 5)
4.insert into table(Question_no,question,ans1,ans2,ans3,ans4,correct ans,practical_lab,sub_topic) values(value1,value2,......etc.)
5.insert into table(Question_no,question,ans1,ans2,ans3,ans4,correct ans,practical_lab,sub_topic) select Question_no,question,ans1,ans2,ans3,ans4,correct ans,practical_lab,sub_topic from #temp
6.drop table #temp