| Author |
Topic |
|
Sparky_
Starting Member
6 Posts |
Posted - 2012-04-12 : 15:48:44
|
| Greetings,I have run into the need to delete some data out of my Sequel database at work.I am not a SQL programmer. I have been going through some tutorials and the "dummies" book.Because deleting from our main data is involved, before I pull the trigger, can I post the script and ask for your input?I would hate to mess up for lack of asking for some input.I have 2 scripts, I "think" both may delete the same way.Thanks-Sparky_ |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Sparky_
Starting Member
6 Posts |
Posted - 2012-04-12 : 16:33:01
|
| First – pardon my lingo regarding Sequel – I may call something incorrectlyI have a program that feeds our Sequel database.Within each line of data that I want deleted I was able to set a variable called, “Delete_This” to 1 through the program that feeds Sequel.So I believe bottom line everything I want deleted has Delete_This = 1.However, as a safety check every piece of data that I want deleted from our MAIN tables should also exist in a received table.What I want to do is delete (from our 12 tables within our Main database) all the lines that have Delete_This = 1 AND the data also exists in “received_table”I have an ID field for every piece of data.Here are my 2 scripts attempting to do the above description.Select * from [Main_Tables].[dbo].[_Table1] Table1 where Exists (Select * FROM [Received_Table].[dbo].[_Table1] ReceivedTable1 Where Table1.Delete_This = 1 AND ReceivedTable1.ID = Table1. ID ); Select * from [Main_Tables].[dbo].[_Table1] Table1 where Table1.Delete_This = 1 AND Exists (Select * FROM [Received_Table].[dbo].[_Table1] ReceivedTable1 where ReceivedTable1. ID = Table1.WMGUID );I would repeat this for Tables 1-12Again – I want to delete from Main_Tables, those lines that have “Delete_This = 1” ANDThe same ID exists in both Main Tables and Received Table.The data was imported from Received_Tables INTO Main and there was a problem – I want to delete those and get back to pre-import.Thanks for the help.-Sparky |
 |
|
|
Sparky_
Starting Member
6 Posts |
Posted - 2012-04-12 : 16:44:44
|
| Oh - and I realize the above do not "delete" - my intention is to replace "Select" with "Delete" if you agree with my script.The above scripts - just selecting - seem to give the correct counts - I want to delete from "Main" only and then import again from "received"Thanks againSparky_ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Sparky_
Starting Member
6 Posts |
Posted - 2012-04-12 : 17:33:13
|
| And am I correct that I simply change the word Select to Delete?Thanks so much!!Sparky_ |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
Sparky_
Starting Member
6 Posts |
Posted - 2012-04-13 : 08:22:29
|
| Thanks!! |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|