There's an issue in our software which sometimes requires a row to be deleted from a table, but this has links to other tables that's also need to be deleted, so I wanted to write a script to be able to delete all of these at one.
The issue I'm having is that I want these all in one script, but I only know the PC Name, which is referenced in only 1 table, so I cant to use another value in that row that's the same throughout.
| CabID | CabName |
| 7 | PC25 |
So I know the 'CabName', and want to enter this in the script but then replace '#' with CabID'
First part I have is
SELECT *
FROM Cabinets
WHERE CabName= 'PC25'
Then
DELETE FROM Room_Cab_Assoc
WHERE CabID= '#',
DELETE FROM PatientCabAssignment
WHERE CabID= '#',
DELETE FROM BinAssignments
WHERE CabID= '#',
DELETE FROM Drawers
WHERE CabID= '#',
DELETE FROM FeatureLogins
WHERE CabID= '#',
DELETE FROM Cabinets
WHERE CabID= '#';
Or is there a better way of doing this?