触发器

exec sp_rename '原名','新名'

select * into tbsales from sales

例子1:

create trigger [dbo].[DeleteFileCommentById] 
on [dbo].[INFO_FILE_ATTRIBUTE] 
for delete 
as 
begin 
DECLARE @FileIndex int 
SELECT @FileIndex = FileIndex FROM deleted 
delete dbo.INFO_FILE_COMMENT where fileindex=@FileIndex 
end

例子2:

create trigger updateVoteSum

on voteDetails

for update

as

begin

update voteMaster set voteSum = voteSum+1 where id=(select top 1 id from inserted)

end

go

例子3:

Create trigger trInsUpdsales

on tblSales

for insert,update as

if(select count(*) from tblstores,inserted where tblstores.stor_id=inserted.stor_id)=0

Begin

print 'the stor_id you have entered does not exist'

Rollback transaction

End

例子4:(havescore)

CREATE TRIGGER tr_updates ON dbo.AICC_BLOCK_HIGH_SCORE

FOR  update

AS

declare @id1 char(10)

declare @id2 decimal(10)

declare @id3 varchar(255)

declare @id4 varchar(255)

select @id1=browse_score,@id2=block_high_num,@id3=COURSE_ID,@id4=student_id

from inserted

if @id1 < 0

begin

      update aicc_block_high_score set browse_score='0' where block_high_num= @id2

end

if  @id1 >=90

begin  

      update user_course_reg set credit_hour=(select credit_hour from courseware where course_number=@id3),active_date=getdate() where course_id=(select course_id from courseware where course_number=@id3)  and user_nm=(select user_nm from users where user_id=@id4)   and (credit_hour='0' or credit_hour is null ) 

end 

if @id1 > 90

begin

      update aicc_block_high_score set browse_score='100' where block_high_num= @id2

end

原文地址:https://www.cnblogs.com/cw_volcano/p/1947524.html