-- 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 A
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