CopyCode The Code is as follows: -- member table
If object_id ('userinfo', 'U') is not null
Drop table userinfo
Go
Create Table userinfo (userid int primary key, user_tegral int, level INT)
Insert into userinfo select 1, 0, 0
Go
-- Member level table
If object_id ('userlevel', 'U') is not null
Drop table userlevel
Go
-- Insert Test Data
Create Table userlevel (Level int primary key, mlevel_point decimal (10, 2 ))
Insert into userlevel select 0, 0
Insert into userlevel select 1,100
Insert into userlevel select 2,200
Insert into userlevel select 3,300
Go
-- Trigger
Create trigger tr_userinfor
On userinfo for update
As
Begin
Update
Set a. Level = B. Level
From userinfo A, userlevel B
Where a. userid in (select userid from inserted) and A. user_tegral> = B. mlevel_point and
A. user_tegral <(select Min (mlevel_point)
From userlevel where mlevel_point> B. mlevel_point)
End
-- Test
Update userinfo
Set user_tegral = 100
Where userid = 1
Select * From userinfo
-- Another trigger
set ansi_nulls on
set quoted_identifier on
go
alter trigger [altername]
on [DBO]. [fs_user]
for insert
as
begin
set nocount on;
Update DBO. fs_user set uname = (select uname from inserted) + '@ ml'
where ID in (select ID from inserted)
end