Skip to content Skip to sidebar Skip to footer

Query For My First Row Admin For Never Delete

Possible Duplicate: How to prevent deletion of the first row in table (PostgreSQL)? i have a table users in which my first row is admin as seen below guid

Solution 1:

Why don't you use following simply mysql query...

DELETE FROM users_tbl WHERE id = 2 AND username != 'admin';

It would never delete admin row.


Solution 2:

Define a trigger on the table, tied to the before delete event that calls a stored procedure where you check the ID they want to delete against the ID you stored in the DB for the admin. If they match, then raise an exception to stop postgresql from executing the actual delete.


Post a Comment for "Query For My First Row Admin For Never Delete"