开发者

query for my first row admin for never delete [duplicate]

开发者 https://www.devze.com 2023-03-03 21:55 出处:网络
This question already has answers here: Closed 11 years ago. Pos开发者_如何转开发sible Duplicate:
This question already has answers here: Closed 11 years ago.

Pos开发者_如何转开发sible 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                | username |             password             |         firstname | lastname  | location | emailaddress  |   userrole
-----------------------------------+----------+----------------------------------+-------------------+-----------+----------+---------------+---------------
 2644885344cecd6f2973b35.63257615  | admin    | 21232f297a57a5a743894a0e4a801fc3 |         System    | Generated |          |               | administrator
 11980380874dc3b542363526.78672935 | gds      | a5f9a8e4d375eb82ca70f7ab7b08ec7c |         gag       | gsdg      | dsf      | fdsf@fdsd.jgh | administrator
(2 rows)

can anyone sugest me the query for my first row admin for never delete ... means this

can not be deleted if user goes to delete then an alert generate "do not delete

admin"

nd if user want to delete 2nd,3rd,4th or any other row then it is posible ..... i m using php


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消