Jump to content

Global Delete


laPistola

Recommended Posts

Im writing some software for a training company and one of the features is to delete a student from the system. Now just deleting a student from the students DB table would cause errors as the information regarding what course they was on and which units had been assigned to them and IV forms and list goes on. All this would still be in the DB and come up on some pages within the application, but when clicked on an error would appear as it wouldn't be able to find the student in the DB. So instead of doing a few queries to target and delete the rows that contain there id from each table, I wondered if there was a faster way not just to write it (this way would only take 5 mins to code anyway) but server load times. There are a few times where a command such as I have inquired about would be an advantage. Mostly when deleting information.

Link to comment
https://forums.phpfreaks.com/topic/241007-global-delete/#findComment-1238207
Share on other sites

So if im right you are saying the only real way would be to run a SELECT command on the COLUMNS table within the information schema eg

 

SELECT TABLE_NAME FROM COLUMNS WHERE COLUMN_NAME = 'sid'

 

Then run a loop that does a query on each table_name returned?

 

If so this would run one more query then if I just manually told the script which tables to target.

Link to comment
https://forums.phpfreaks.com/topic/241007-global-delete/#findComment-1238210
Share on other sites

So if im right you are saying the only real way would be to run a SELECT command on the COLUMNS table within the information schema eg

 

SELECT TABLE_NAME FROM COLUMNS WHERE COLUMN_NAME = 'sid'

 

Then run a loop that does a query on each table_name returned?

 

If so this would run one more query then if I just manually told the script which tables to target.

Would do the same thing.

The advantage of doing the deletion per table on a loop than by manually doing it, is that the whole functionality is automated. If in the future, a new table with the field(s) of your interest is introduced, you need not edit your script.

Link to comment
https://forums.phpfreaks.com/topic/241007-global-delete/#findComment-1238227
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.