Modify a trigger

Source: Internet
Author: User
Modify the trigger SQLServerJDBCDriver to monitor the modification of a table and then automatically modify the data of another table: cf_userinfo table structure: CREATETABLE [dbo]. [cf_userinfo] ([id] intNOTNULLIDENTITY (1,1), [uid] intNOTNULL, [name] varchar (50) COLLATEChinese_PRC_CI_ASNULL, CONSTRAINT

Modify the trigger SQLServer JDBC Driver to monitor the modification of a TABLE and then automatically modify the data of another TABLE: cf_userinfo TABLE structure: create table [dbo]. [cf_userinfo] ([id] int not null identity (1,1), [uid] int not null, [name] varchar (50) COLLATE Chinese_PRC_CI_AS NULL, CONSTRAINT

Modify the SQL Server JDBC Driver
After monitoring the modification of a TABLE, the data of another TABLE is automatically modified: cf_userinfo TABLE structure: create table [dbo]. [cf_userinfo] ([id] int not null identity (1,1), [uid] int not null, [name] varchar (50) COLLATE Chinese_PRC_CI_AS NULL, CONSTRAINT [PK _ cf_userinfo _ 5535A963] primary key ([id]) ON [PRIMARY] GOuserinfo TABLE structure: create table [dbo]. [userinfo] ([id] int not null identity (1, 1), [name] varchar (50) COLLATE Chinese_PRC_CI_AS NULL, CONSTRAINT [PK _ userinfo _ 5 34D60F1] primary key ([id]) ON [PRIMARY] GO create trigger for userinfo table create trigger userinfoupdateon userinfo for update -- monitor userinfo table modification asif update (name) -- if the name field is changed to begin print, the userinfo table modification event is triggered. Modify the cf_userinfo data ...... '; Declare @ id INT, @ newName varchar (50), @ uid int; -- select @ ID = id from deleted; if (exists (select * from cf_userinfo where uid = @ id) begin -- select @ newName = name from inserted; -- select @ UID = ID from deleted; update cf_userinfo set cf_userinfo.name = @ newName from userinfo where cf_userinfo.uid = @ UID end else print 'you do not need to modify the cf_userinfo table 'end

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.