3、 在数据库中创建一张表EXAM_USER

3、 在数据库中创建一张表EXAM_USER,第1张

Create table  EXAM_USER

( 

  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


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/10074276.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存