I would like to delete a specific record from two or more tables which are linked to one another.
For Example: I have two tables, Students and winners I would like to delete the names Roy and Peter from both the tables in one shot.
table: Students
> ID name class
> 1 Roy 2
> 2 James 3
> 3 Carl 4
> 4 Peter 4
> 5 Alice 5
table: Winners
St_ID achievement
1 1
2 1
3 3
4 5
5 5
I have more than 100 tables with 50 specific records to be deleted from all the tables.
Best Answer
You have to achieve this using Dynamic SQL Query
1- First you have to list all Tables With there Corresponding Databases in a Temp Table 2- Building Query for databases that contains
Students
andWinners
dataTableYour script should look like
This Will Result a query like the following (If these databases contains
Students
andWinners
Table)I don't Now if that is what you was asking for in your question below (Your question was not specific like this one, so my answer was providing the dynamic sql logic in general)