Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2006-08-12 : 06:47:22
|
| hi all,i am tryin to use the FOR UPDATE option for a table with duplicate rows.. but i cant do it as FOR UPDATE option wants the table to have primary key... is thr any way in which i can overcome this problem? |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2006-08-12 : 06:53:59
|
| I am using the "FOR UPDATE" option with a cursor in the above scenario |
 |
|
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-08-12 : 06:54:47
|
| Can you post code and table structure what you are trying to doChirag |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-12 : 07:07:29
|
quote: Originally posted by pravin14u hi all,i am tryin to use the FOR UPDATE option for a table with duplicate rows.. but i cant do it as FOR UPDATE option wants the table to have primary key... is thr any way in which i can overcome this problem?
create an identity as primary key in the table KH |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2006-08-12 : 07:38:01
|
| Don't use a cursor?==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
pravin14u
Posting Yak Master
246 Posts |
Posted - 2006-08-16 : 02:27:37
|
| fine, how can i accompalish the task without cursors(deleting the duplicate rows(i,e) if thr r 3 duplicate, i need to delete only 2 of them) |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-08-16 : 03:12:23
|
| [code]-- create temp table for testingcreate table #temp( data int)-- insert some test datainsert into #temp select 10 union allselect 10 union allselect 10 union allselect 20 union allselect 20 union allselect 30 union allselect 40 select * from #temp/*data ----------- 10101020203040(7 row(s) affected)*/alter table #temp add id int identity(1,1)select * from #temp/*data id ----------- ----------- 10 110 210 320 420 530 640 7(7 row(s) affected)*/delete tfrom #temp twhere t.id not in (select min(id) from #temp x where x.data = t.data)select * from #temp/*data id ----------- ----------- 10 120 430 640 7(4 row(s) affected)*/alter table #temp drop column idselect * from #temp/*data ----------- 10203040(4 row(s) affected)*/-- drop the table after testingdrop table #temp[/code] |
 |
|
|
|
|
|