I have never written a SQL Server trigger before. After a day of hard work, I finally wrote it. Now I want to record my experiences. The syntax of the SQL Server trigger is not mentioned. It mainly records the main items. Each start has a Begin content end. if you do not understand this before, it is inaccurate to trigger the write condition many times. The following is an example: if (object_id (inser
I have never written a SQL Server trigger before. After a day of hard work, I finally wrote it. Now I want to record my experiences. The syntax of the SQL Server trigger is not mentioned. It mainly records the main items. Each start has a Begin content end. if you do not understand this before, it is inaccurate to trigger the write condition many times. The following is an example: if (object_id ('inser
I have never written a SQL Server trigger before. After a day of hard work, I finally wrote it. Now I want to record my experiences.
The syntax of the SQL Server trigger is not mentioned. It mainly records the main items. Each start has a Begin content end. If you do not understand this before, it is inaccurate to trigger the write condition many times. The following is an example:
If (object_id ('insert _ black_list ', 'tr') is not null) drop trigger insert_black_list
Go
Create TRIGGER insert_black_list
On User_Infor_Message
After insert
As
Declare @ messagetype varchar (1)
Declare @ cardno varchar (10)
BEGIN
Select @ messagetype = messagetype, @ cardno = cardno from User_Infor_Message
If @ messagetype = '1' or @ messagetype = '5'
Begin
If (select count (cardno) from Balck_List where cardno = @ cardno) = 0
Begin
Insert into Balck_List select Inserted. cardno, Inserted. cardid, convert (varchar (8), getdate (), 112) from Inserted
End
End
Else if @ messagetype = '6'
Begin
Delete from Balck_List where cardno = @ cardno
End
END
Go