小隐的博客

人生在世,笑饮一生
随笔 - 304, 文章 - 0, 评论 - 349, 阅读 - 50万
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

触发器的使用

Posted on   隐客  阅读(357)  评论(0编辑  收藏  举报
 -- ================================================
-- Template generated from Template Explorer using:
-- Create Trigger (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- See additional Create Trigger templates for more
-- examples of different Trigger statements.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
alter TRIGGER tgr_cbc_insert
   ON  checkbillc
   AFTER   INSERT
AS 
BEGIN
 
declare @checkid varchar(32), @checkidx varchar(50) ,@checkicode varchar(50),@qty numeric(24, 6),@bookicodexx varchar(50),@gcode varchar(50),@gname varchar(50)
 
 
    --更新后
    select @checkid = checkid ,@checkidx=checkidx ,@checkicode=checkicode,@qty=qty ,@bookicodexx=bookicodexx,@gcode=gcode ,@gname=gname  from inserted;

INSERT INTO  checkbak
           (checkid,checkidx,checkicode,qty,[bookicodexx],gcode,gname,[type])
     VALUES
           (@checkid,@checkidx,@checkicode,@qty,@bookicodexx,@gcode,@gname,'insert')
 
 
END
GO


alter TRIGGER tgr_cbc_delete
   ON  checkbillc
   AFTER   delete
AS 
BEGIN
 
declare @checkid varchar(32), @checkidx varchar(50) ,@checkicode varchar(50),@qty numeric(24, 6),@bookicodexx varchar(50),@gcode varchar(50),@gname varchar(50)
 
 
    --更新后
    select @checkid = checkid ,@checkidx=checkidx ,@checkicode=checkicode,@qty=qty ,@bookicodexx=bookicodexx,@gcode=gcode ,@gname=gname  from deleted;

INSERT INTO  checkbak
           (checkid,checkidx,checkicode,qty,[bookicodexx],gcode,gname,[type])
     VALUES
           (@checkid,@checkidx,@checkicode,@qty,@bookicodexx,@gcode,@gname,'delete')
 
 
END
GO

-- ================================================
-- Template generated from Template Explorer using:
-- Create Trigger (New Menu).SQL
--
-- Use the Specify Values for Template Parameters 
-- command (Ctrl-Shift-M) to fill in the parameter 
-- values below.
--
-- See additional Create Trigger templates for more
-- examples of different Trigger statements.
--
-- This block of comments will not be included in
-- the definition of the function.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
alter TRIGGER tgr_wb_update
   ON  warebalance
   AFTER   UPDATE
AS 
BEGIN
declare @gid nvarchar(50)
set @gid =NEWID ()
declare @bid varchar(32), @gcode varchar(50) ,@gname varchar(50),@qty2 numeric(24, 6),@bookicodexx varchar(50)
declare @bid0 varchar(32), @gcode0 varchar(50) ,@gname0 varchar(50),@qty20 numeric(24, 6),@bookicodexx0 varchar(50)
 --更新前的数据
    select @bid = bid ,@gcode=gcode ,@gname=gname,@qty2=qty2 ,@bookicodexx=bookicodexx from deleted;
    --更新后
    select @bid0 = bid ,@gcode0=gcode ,@gname0=gname,@qty20=qty2 ,@bookicodexx0=bookicodexx from inserted;

INSERT INTO  [warebak]
           ([bid],[gcode],[gname],[qty2],[bookicodexx],[gid])
     VALUES
           (@bid,@gcode,@gname,@qty2,@bookicodexx,@gid + 'delete')
 

INSERT INTO  [warebak]
           ([bid],[gcode],[gname],[qty2],[bookicodexx],[gid])
     VALUES
           (@bid0,@gcode0,@gname0,@qty20,@bookicodexx0,@gid + 'insert')
END
GO
 
/****** Object:  Table [dbo].[checkbak]    Script Date: 12/11/2015 09:04:46 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[checkbak](
[id] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
[checkid] [varchar](32) NULL,
[checkidx] [varchar](32) NULL,
[bookicodexx] [varchar](32) NULL,
[checkicode] [varchar](32) NULL,
[qty] [numeric](24, 6) NULL,
[gcode] [varchar](32) NULL,
[gname] [varchar](48) NULL,
[type] [varchar](50) NOT NULL,
 CONSTRAINT [checkbak_pk] PRIMARY KEY CLUSTERED 
(
[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


 

/****** Object:  Table [dbo].[warebak]    Script Date: 12/11/2015 09:05:10 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[warebak](
[bid] [varchar](32) NOT NULL,
[gcode] [nvarchar](50) NULL,
[gname] [nvarchar](50) NULL,
[qty2] [numeric](24, 6) NOT NULL,
[bookicodexx] [varchar](32) NULL,
[gid] [nvarchar](50) NOT NULL,
[id] [numeric](18, 0) IDENTITY(1,1) NOT NULL,
 CONSTRAINT [warebak_pk] PRIMARY KEY CLUSTERED 
(
[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO

ALTER TABLE [dbo].[warebak] ADD  CONSTRAINT [DF__warebak__qty2__76B82F6D]  DEFAULT ((0)) FOR [qty2]
GO

编辑推荐:
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
QQ交流
点击右上角即可分享
微信分享提示