Use of triggers

Source: Internet
Author: User

-- ================================================
--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 is not being 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 (+), @checkidx varchar (@checkicode varchar), @qty numeric (6), @bookicodexx varchar ( , @gcode varchar (+), @gname varchar (50)


--After the update
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 (+), @checkidx varchar (@checkicode varchar), @qty numeric (6), @bookicodexx varchar ( , @gcode varchar (+), @gname varchar (50)


--After the update
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 is not being 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 (+), @gcode varchar (@gname varchar), @qty2 numeric (6), @bookicodexx varchar (50)
DECLARE @bid0 varchar (+), @gcode0 varchar (@gname0 varchar), @qty20 numeric (6), @bookicodexx0 varchar (50)
--Pre-update data
Select @bid = Bid, @gcode =gcode, @gname =gname, @qty2 =qty2, @bookicodexx =bookicodexx from deleted;
--After the update
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] (0) IDENTITY (+) not NULL,
[Checkid] [varchar] (+) NULL,
[Checkidx] [varchar] (+) NULL,
[Bookicodexx] [varchar] (+) NULL,
[Checkicode] [varchar] (+) NULL,
[Qty] [Numeric] (24, 6) Null
[Gcode] [varchar] (+) NULL,
[Gname] [varchar] () NULL,
[Type] [varchar] () 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 = O N) 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] (+) Not NULL,
[Gcode] [nvarchar] () NULL,
[Gname] [nvarchar] () NULL,
[Qty2] [Numeric] (24, 6) Not NULL,
[Bookicodexx] [varchar] (+) NULL,
[GID] [nvarchar] () not NULL,
[ID] [numeric] (0) IDENTITY (+) 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 = O N) 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

Use of triggers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.