Home > database >  Used to trigger 2008 home UPDATE to UPDATE fields are not fixed
Used to trigger 2008 home UPDATE to UPDATE fields are not fixed

Time:11-19

Home used 2008 trigger the UPDATE UPDATE fields are not fixed

Update the fields in the table are not fixed how to write a trigger

CodePudding user response:

 
Declare fields varchar (255)
Remember - field assignment
The Update table Set field





CodePudding user response:

To write a complete? I am on a field update, now there is a problem, update the other fields prompt implementation success, but I can't update to the data

CodePudding user response:

CREATE the TRIGGER TRIGER_YYDATA_INSERT
ON YYDATA
Home UPDATE
AS
IF the update (signno)
The BEGIN
DECLARE @ count INT
Select @ count=count (1) the from INSERTED A where clause A.S IGNNO in (select signno from YYDATA where LEFT (APPOINT_DATE, 10)=LEFT (A.A PPOINT_DATE, 10))
IF @ count & gt; 0
The begin
Raiserror (' SIGNNO REPEAT ', 16, 1)
The rollback transaction
END
The ELSE
The begin
The UPDATE YYDATA SET
SIGNTIME=T2 SIGNTIME,
SIGNNO=T2 SIGNNO,
SIGNSTATE=T2. SIGNSTATE
The FROM YYDATA AS t1, inserted AS t2 WHERE t1. APPOINT_ID=t2. APPOINT_ID
End
END

CodePudding user response:

The
reference 3 floor JunZiLianJH response:
CREATE TRIGGER TRIGER_YYDATA_INSERT
ON YYDATA
Home UPDATE
AS
IF the update (signno)
The BEGIN
DECLARE @ count INT
Select @ count=count (1) the from INSERTED A where clause A.S IGNNO in (select signno from YYDATA where LEFT (APPOINT_DATE, 10)=LEFT (A.A PPOINT_DATE, 10))
IF @ count & gt; 0
The begin
Raiserror (' SIGNNO REPEAT ', 16, 1)
The rollback transaction
END
The ELSE
The begin
The UPDATE YYDATA SET
SIGNTIME=T2 SIGNTIME,
SIGNNO=T2 SIGNNO,
SIGNSTATE=T2. SIGNSTATE
The FROM YYDATA AS t1, inserted AS t2 WHERE t1. APPOINT_ID=t2. APPOINT_ID
End
END

This is my SQL, but not update signno, update didn't effect

CodePudding user response:

reference 4 floor JunZiLianJH response:
Quote: reference JunZiLianJH reply: 3/f

CREATE the TRIGGER TRIGER_YYDATA_INSERT
ON YYDATA
Home UPDATE
AS
IF the update (signno)
The BEGIN
DECLARE @ count INT
Select @ count=count (1) the from INSERTED A where clause A.S IGNNO in (select signno from YYDATA where LEFT (APPOINT_DATE, 10)=LEFT (A.A PPOINT_DATE, 10))
IF @ count & gt; 0
The begin
Raiserror (' SIGNNO REPEAT ', 16, 1)
The rollback transaction
END
The ELSE
The begin
The UPDATE YYDATA SET
SIGNTIME=T2 SIGNTIME,
SIGNNO=T2 SIGNNO,
SIGNSTATE=T2. SIGNSTATE
The FROM YYDATA AS t1, inserted AS t2 WHERE t1. APPOINT_ID=t2. APPOINT_ID
End
END

This is my SQL, but not update signno, update didn't effect


You're here, IF the update (signno) limit the update fields to trigger, IF want to change every time triggered update statement will remove the judgment,

CodePudding user response:

Don't mean that, I wanted to have signno fields to trigger in the update statement, without this field in the update, according to the normal execution can update

CodePudding user response:

Do you BEGIN END write wrong, try the following?

 
REATE TRIGGER TRIGER_YYDATA_INSERT
ON YYDATA
Home UPDATE
AS
IF the update (signno)
The BEGIN
DECLARE @ count INT
Select @ count=count (1) the from INSERTED A where clause A.S IGNNO in (select signno from YYDATA where LEFT (APPOINT_DATE, 10)=LEFT (A.A PPOINT_DATE, 10))
IF @ count & gt; 0
The begin
Raiserror (' SIGNNO REPEAT ', 16, 1)
The rollback transaction
End
END
The ELSE
The BEGIN
The UPDATE YYDATA SET
SIGNTIME=T2 SIGNTIME,
SIGNNO=T2 SIGNNO,
SIGNSTATE=T2. SIGNSTATE
The FROM YYDATA AS t1, inserted AS t2 WHERE t1. APPOINT_ID=t2. APPOINT_ID
END

  • Related