zoukankan      html  css  js  c++  java
  • mssql 怎么配置指定的表 不允许删除数据?

    http://www.maomao365.com/?p=5089

    <span style="color:red;font-weight:bold;">
    前言: 前几天收到群友提问,如何禁止某一张表里面的数据被删除掉?
    </span>
    <hr />
    当我们看见这个问题的时,首先想到的是拦截器,sql数据操作拦截器,首先第一个想到的是sql instead of触发器,
    instead of触发器可以拦截insert update delete操作。
    下文将举例说明,instead of触发器对表删除的拦截
     

    /*建表*/
    create table A(keyId int,info varchar(20))
    go
    
    insert into A(keyId,info)values(1,'a'),(2,'b'),(3,'c'),(4,'d')
    go
    
    /*创建 instead of 触发器*/
    create trigger tr_A on A 
    instead of delete 
    as 
    begin
    select '禁止对表进行删除操作' ---将对表delete 全部锁定禁止操作
    return;
    
    /*
    if system_user ='sa'
    begin
    select '禁止账户(sa)对表进行删除操作' 
    return;
    
    end
    */
    
    end
    go
    
    delete from A 
    go
    
    select * from A 
    go
    
    truncate table A
    drop table A 
    go

    insteadof触发器禁止表删除内容

  • 相关阅读:
    csp-s模拟103
    csp-s模拟102
    csp-s模拟101
    csp-s模拟100
    csp-s模拟99
    csp-s模拟98
    csp-s模拟97
    csp-s模拟96
    csp-s模拟95
    csp-s模拟94
  • 原文地址:https://www.cnblogs.com/lairui1232000/p/7685418.html
Copyright © 2011-2022 走看看