Translate

Monday, 15 December 2014

inserted trigger in sql server


CREATE TABLE [dbo].[tblTRIGGERMAST1](
[ID] [varchar](10) NOT NULL PRIMARY KEY,
[NAME] [varchar](20) NULL,
[PHONE] [int] NULL
)

CREATE TABLE [dbo].[tblTRIGGER2](
[ID] [int] IDENTITY(1001,1) PRIMARY KEY NOT NULL,
[IDMAST] [varchar](10) NULL,
[PHONE] [int] NULL,
[DATE] [datetime] NULL
)
CREATE  TRIGGER Triger_On_tblTRIGGERMAST1
ON  tblTRIGGERMAST1
AFTER INSERT
AS
BEGIN

SET NOCOUNT ON;
declare @ID int
declare @Phone int
declare @Result varchar(100)
select @ID=ID from inserted
select @Phone =PHONE from inserted
INSERT INTO tblTRIGGER2(IDMAST,PHONE)VALUES(@ID,@Phone)
set @Result=convert(varchar,'The Inserted Values Are Inserted in Table tblTRIGGER2:ID IS:  ')
+convert(varchar,@ID)+convert(varchar,' pHONE nO  Is: ')+convert(varchar,@Phone)
Print @Result

END
insert into tblTRIGGERMAST1(ID,NAME,PHONE)values(1004,'PABITRA BEHERA',828989)

-------------
---THE RESULT WILL BE
The Inserted Values Are Insert1004 pHONE nO  Is: 828989

(1 row(s) affected)

No comments:

Post a Comment