(
USER_ID varchar(7) primary key,
USER_NAME varchar(10) not null,
USER_PWD varchar(20) not null,
SEX char(2) check(SEX='男'or SEX='女'),
AGE int check(Sage between 15 and 45)
)
下课后来我办公室CREATE TABLE [bdo].[user] (
[user_id] [nvarchar] (10) NULL ,
[password] [nvarchar] (10) NULL ,
[user_type] [nvarchar] (5)
) ON [PRIMARY]
GO
Create trigger student
on S
after insert,update,delete
as
declare @old_Snum char(10),@new_Snum char(10)
set @old_Snum=''
set @new_Snum=''
set @old_Snum=(select Snum from deleted)
set @new_Snum=(select Snum from inserted)
if (select count(*)from deleted)=0
insert into [User] values(@new_Snum,@new_Snum,'学生')
if(select count(*)from deleted)!=0 and
(select count(*)from inserted)!=0
update [User] set [User_id]=@new_Snum
where [User_id]=@old_Snum and User_type='学生'
if (select count(*)from inserted)=0
delete [User] where [User_id]=@old_Snum
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)