if OBJECT_ID('Data') is not null
drop table data
go
create table Data (
DataID int identity primary key,
ChildID int not null,
Time int not null,
Data varchar(255) not null,
Type tinyint not null,
Status varchar(255) null
)
go
create trigger mydata on Data for insert
as
begin
declare @status varchar(255),@dataID int
select @dataID=DataID from inserted
set @status=''
while(1=1)
begin
if (select data from Data where DataID=@dataID and Type=1)>37.0
set @status='发烧'
if(select data from Data where DataID=@dataID and Type=2)<6
set @status=@status+'睡眠质量差'
end
update Data set status=@status where DataID=@dataID
end
INSERT INTO Data(ChildID,Time,Data,Type ) VALUES(2,1429407000,40.1,1)
select * from data
哪位大神能告诉我有没有错误,为什么执行查询就一直在没有命令成功。。急
关于数据库的触发器的使用
答案:2 悬赏:30 手机版
解决时间 2021-01-30 20:45
- 提问者网友:未信
- 2021-01-30 06:34
最佳答案
- 五星知识达人网友:洎扰庸人
- 2021-01-30 07:46
while(1=1)
不能这样写,你那死循环了
WHILE(@@FETCH_STATUS=0)
不能这样写,你那死循环了
WHILE(@@FETCH_STATUS=0)
全部回答
- 1楼网友:轻雾山林
- 2021-01-30 08:44
完全可以做到:
create trigger del
on studen
instate of delete
as
begin
delete from student where existe(select a.xuehao,b.jiaofei from deleted a,jiaofei b where a.xuehao=b.xuehao and a.xuehao=student.xuehao and b.jiaofei='未交')
delete from info where existe(select a.xuehao,b.jiaofei from deleted a,jiaofei b where a.xuehao=b.xuehao and a.xuehao=info.xuehao and b.jiaofei='未交')
delete from jiaofei where existe(select xuehao from deleted where deleted.xuehao=jiaofei.xuehao and jiaofei.jiaofei='未交')
end
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯