求数据库触发器代码(SQL)
酒店管理表client(cid(客户编号),cname(客户名字),entretime(入住时间),leavetime(离开时间),rid(房间标号))表room(rid...
酒店管理
表client(cid(客户编号),cname(客户名字),entretime(入住时间),leavetime(离开时间),rid(房间标号))
表room(rid(房间编号号),roomstatue(房间状态),cid(客户编号))
求触发器 当客户入住选定房间时 room表roomstatue,cid改变
同理 离开时做相应操作 展开
表client(cid(客户编号),cname(客户名字),entretime(入住时间),leavetime(离开时间),rid(房间标号))
表room(rid(房间编号号),roomstatue(房间状态),cid(客户编号))
求触发器 当客户入住选定房间时 room表roomstatue,cid改变
同理 离开时做相应操作 展开
2个回答
展开全部
CREATE TRIGGER Trig_client_update ON T_Item
FOR Update
AS
if Update(entretime)
begin
declare @rid int
SELECT @rid= rid FROM Inserted
if not @rid is null
begin
update room
set roomstatue='离开'
where rid=@rid
end
end
go
CREATE TRIGGER Trig_client_insert ON T_Item
FOR insert
AS
if @@Rowcount = 0
return
begin
declare @rid int
SELECT @rid= rid FROM Inserted
if not @rid is null
begin
update room
set roomstatue='入住'
where rid=@rid
end
end
FOR Update
AS
if Update(entretime)
begin
declare @rid int
SELECT @rid= rid FROM Inserted
if not @rid is null
begin
update room
set roomstatue='离开'
where rid=@rid
end
end
go
CREATE TRIGGER Trig_client_insert ON T_Item
FOR insert
AS
if @@Rowcount = 0
return
begin
declare @rid int
SELECT @rid= rid FROM Inserted
if not @rid is null
begin
update room
set roomstatue='入住'
where rid=@rid
end
end
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询