简体   繁体   中英

Triggers in SQL

I am having trouble with the following problem, Just wondering if you could give me any guidance on how i would start this.

Write a trigger to capture an input before it's inserted into a table so that the value of the insert will be modified to be appended with the text -previous

Say I have a table called StaffDetails and i could insert info such as ID, How would i apply it to the above problem.

Thank You

Create Trigger trg_name
on StaffDetails 
instead of insert
referencing new as new_row
as
begin
@new_row.ID = (@new_row.ID + '_previous')
insert into StaffDetails (.....) values (@new_row.ID, .....)
end

it would probably look something like this, maybe youll have to change some syntax because its not the same for mysql and sql server, for detailed information on syntax for sql server you can look at https://msdn.microsoft.com/en-us/library/ms189799.aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM