I have two tables. A device table and a location table. There can only be one device in the device table but there can be multiple devices with multiple locations in the location table.
If a user deletes a device, I need to also delete the locations with the same id from the location table.
Is there a way to delete from multiple tables in a Delete statement (using sql server) from within a cfc page?
I have tried to write a <cfif>
when I do my initial delete, to check if there were records deleted and if so, run the next delete statement that deletes the devices from the table.
I have also tried to use this format.
delete T1, T2
from T1
inner join T2 on T1.device_id = T2.device_id
where T2.device_id = '111';
T1 = device table, T2 = Location table
<cfif ARGUMENTS.submitButton eq 'btn_Delete'>
<cfquery name="DeleteDevice" datasource="#session.dsn#" maxRows=1 >
DELETE from #session.tq#device
WHERE device_id = <cfqueryparam value="#formStruct.deviceId#" cfsqltype="CF_SQL_VARCHAR">
</cfquery>
</cfif>
<cfif DeleteDevice.RecordCount eq 1>
<cfquery name="DeleteLocation" datasource="#session.dsn#" maxRows=1 >
DELETE from #session.tq#device_location_xref
WHERE device_location_xref_recno=<cfqueryparam value="#formStruct.deviceId#" cfsqltype="CF_SQL_VARCHAR">
</cfquery>