Copy codeThe 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