zoukankan      html  css  js  c++  java
  • T-SQL触发器,限制一次只能删除一条数据

    /****** Object:  Trigger [dbo].[trg_del]    Script Date: 01/01/2016 12:58:28 ******/
    SET ANSI_NULLS ON
    GO
    
    SET QUOTED_IDENTIFIER ON
    GO
    
    CREATE TRIGGER [dbo].[trg_del] ON [dbo].[Common_Header]
        INSTEAD OF DELETE
    AS
        BEGIN
            DECLARE @cou INT
            DECLARE @headerid UNIQUEIDENTIFIER
            SELECT  @cou = COUNT(*)
            FROM    deleted;
            SELECT  @headerid = id
            FROM    deleted
            IF ( @cou > 1 )
                RAISERROR('数据不允许删除!', 16, 1)
            ELSE
                DELETE  FROM [Common_Header]
                WHERE   id = @headerid
        END
    GO
    CREATE TABLE [dbo].[Common_Header]
    (
    [ID] [uniqueidentifier] NOT NULL,
    [Subject] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [ApplicantAD] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [ApplicantName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [CountryCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [CountryName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [CompanyCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [CompanyName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [DivisionCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [DivisionName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [LBUCode] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [LBUName] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [CostCenter] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL,
    [Email] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NULL,
    [CreatedDate] [datetime] NULL,
    [QueueID] [uniqueidentifier] NULL,
    [Status] [nvarchar] (50) COLLATE Chinese_PRC_CI_AS NULL
    ) ON [PRIMARY]
    GO
    ALTER TABLE [dbo].[Common_Header] ADD CONSTRAINT [PK_Common_Header] PRIMARY KEY CLUSTERED  ([ID]) ON [PRIMARY]
    GO
    CREATE NONCLUSTERED INDEX [NonClusteredIndex-20150603-113054] ON [dbo].[Common_Header] ([QueueID]) ON [PRIMARY]
    GO
  • 相关阅读:
    C#+Arcengine创建内存图层
    Creating a Feature Set via C#
    ArcGIS Server for JavaScript api安装部署
    Lucene.Net 3.0.3如何从TokenStream中获取token对象
    MMSEG 中文算法说明
    java DotNet char 代码对应
    Lucene.Net 3.0.3如何从TokenStream中获取token对象
    java DotNet char 代码对应
    9.7
    9.6
  • 原文地址:https://www.cnblogs.com/wanghaibin/p/5093208.html
Copyright © 2011-2022 走看看