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 2005 Forums
 Transact-SQL (2005)
 Deleting Non sequential records

Author  Topic 

Steve95
Starting Member

19 Posts

Posted - 2007-05-11 : 06:13:15
Hi All

I have need to know of an effective way to delete 2000 records from a table holding 4000 records. Their is a unique key ie. originalno. which identifies each record and also I have the originalno. of all the records that need to be deleted from a excel sheet provided by the business. The records to be deleted are in a non sequential format.

But what syntax/way do I use to make this quick and correct rather than going through each originalno, and placing comers after each to extract the relevant records for deletion?

Many Thanks in advance.......

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-05-11 : 07:24:34
This forum is not for posting questions. Please post in appropriate forum.

Mods, here is a work for you !!

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2007-05-11 : 07:38:44
Import the numbers from Excel into a temporary "staging" table, and then delete joining to that table:

DELETE D
FROM MyTable AS D
JOIN MyStagingTable AS S
ON S.originalno = D.originalno

Kristen
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-05-11 : 08:26:46
moved from Script library to here.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-05-11 : 11:23:07
Also asked here http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=23&messageid=364750


Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -