设为首页 加入收藏

TOP

如何防止表被清空
2014-11-24 07:11:22 来源: 作者: 【 】 浏览:0
Tags:如何 防止 清空

一般来说,我们未来阻止用户删除或者清空表以及数据, 可以直接从权限下手,给他少量的权限即可。

t_girl=# create role ytt3 with login connection limit 1 password 'ytt3'; CREATE ROLE t_girl=# alter schema ytt owner to ytt3; ALTER SCHEMA t_girl=# grant select on all tables in schema ytt to ytt3; GRANT

bash-4.1$ psql -U ytt3 t_girl psql (9.3.4) Type "help" for help. t_girl=> truncate table j2; ERROR: permission denied for relation j2

t_girl=# \sf prevent_truncate CREATE OR REPLACE FUNCTION public.prevent_truncate() RETURNS trigger LANGUAGE plpgsql AS $functio$ BEGIN RAISE EXCEPTION 'Prevent "%" to be truncated!', TG_TABLE_SCHEMA||TG_TABLE_NAME; RETURN NEW; END; $function$

t_girl=# \d j2 Table "ytt.j2" Column | Type | Modifiers --------+---------+----------- id | integer | str2 | text | Triggers: trigger_truncate_before BEFORE TRUNCATE ON j2 FOR EACH STATEMENT EXECUTE PROCEDURE ytt.prevent_truncate()

t_girl=# truncate table j2; ERROR: Prevent "ytt.j2" to be truncated!

mysql> truncate table j2; ERROR 1142 (42000): DROP command denied to user 'ytt3'@'localhost' for table 'j2'

+------------------------------------+ | Error | +------------------------------------+ | Prevent t_girl.j2 to be truncated! | +------------------------------------+ 1 row in set (0.00 sec)

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇MongoDB中的_id和ObjectId 下一篇分区表的基本操作

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Java 学习线路图是怎 (2025-12-25 15:19:15)
·关于 Java 学习,有 (2025-12-25 15:19:12)
·有没有Java swing教 (2025-12-25 15:19:09)
·Start, Stop, and Di (2025-12-25 14:50:57)
·C语言入门教程:零基 (2025-12-25 14:50:54)