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.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Delete all rows except one

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-04-10 : 09:38:38
Sam writes "See, i need to delete all the rows except one from a table in Sql Server. The table may or may not have any unique key,but the problem is i dont know the structure of the table...just the name of the table is given. Thers no such restriction on the row which should be left after deletion. I need that Sql query...
Reply soon...
Thanks.."

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-04-10 : 09:45:56
Refer this
http://sqlteam.com/forums/topic.asp?TOPIC_ID=6256

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2006-04-10 : 09:46:03
declare @i int
select @i = count(*) - 1 from tbl
set rowcount @i
delete tbl
set rowcount 0



==========================================
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.
Go to Top of Page
   

- Advertisement -