set nocount on dropproc look createproc look as begin declare@nowRoomIDint,@nowRoomNamenvarchar(50) select@nowRoomID=RoomID from nowRoom select@nowRoomName=roomName from Room where RoomID=@nowRoomID print'You are in the '+@nowRoomName print'You can see the following things:' select GoodName from Goods g where inRoomID=@nowRoomIDandnotexists(select outerid from GoodsInGood where innerID=g.GoodID ) print'You may go to the following rooms:' select r2.RoomName from Room r1 join RoomContact rc on r1.RoomID=rc.id1 join Room r2 on rc.id2=r2.RoomID where r1.RoomID=@nowRoomID end dropproc go2 createproc go2 (@RoomNamenvarchar(50)) as begin declare@nowRoomIDint,@isLightedbit,@isLightOnbit select@nowRoomID=RoomID from nowRoom select@isLightOn=status from list join Goods on list.GoodID=Goods.GoodID and Goods.GoodName like'%flashlight%' set@isLightOn=isnull(@isLightOn,0) select@islighted=r2.isLighted from Room r1 join RoomContact rc on r1.RoomID=rc.id1 join Room r2 on rc.id2=r2.RoomID where r1.RoomID=@nowRoomIDand r2.RoomName=@RoomName printcast(@islightedaschar(1)) printcast(@islightonaschar(1)) if (@islighted|@isLightOn)=1 begin update nowRoom set RoomID=(select RoomID from Room where RoomName=@RoomName) end elseif (@islighted|@isLightOn)=0 print'You can'+''''+'t go to the '+@RoomName+' because it'+''''+'s dark in the cellar and you'+''''+'re afraid of the dark.' else print'You can'+''''+'t goto '+@RoomName+' from here' end go2 cellar select*from list dropproc turnon createproc turnon (@lightnvarchar(50)) as declare@GoodIDint,@lightIDint begin select@GoodID=list.GoodID from list join Goods on list.GoodID=Goods.GoodID and Goods.GoodName=@light if@GoodIDisnotnull begin select@lightID=list.GoodID from list join Goods_kind on List.GoodID=Goods_kind.GoodID join kind on Goods_kind.kindID=kind.id where list.GoodID=@GoodIDand kind.name like'%lighted%' if@lightIDisnotnull begin update list set status=1 where GoodID=@lightID print'flashlight turned on.' end else print@light+' not a light.' end else print'You don'+''''+'t have the '+@light end createproc turnoff (@lightnvarchar(50)) as declare@GoodIDint,@lightIDint begin select@GoodID=list.GoodID from list join Goods on list.GoodID=Goods.GoodID and Goods.GoodName=@light if@GoodIDisnotnull begin select@lightID=list.GoodID from list join Goods_kind on List.GoodID=Goods_kind.GoodID join kind on Goods_kind.kindID=kind.id where list.GoodID=@GoodIDand kind.name like'%lighted%' if@lightIDisnotnull begin update list set status=0 where GoodID=@lightID print'flashlight turned off.' end else print@light+' not a light.' end else print'You don'+''''+'t have the '+@light end dropproc release createproc release (@GoodNamenvarchar(50)) as declare@GoodIDint,@nowRoomIDint begin select@nowRoomID=RoomID from nowRoom select@GoodID=list.GoodID from list join Goods on list.GoodID=Goods.GoodID where GoodName=@GoodName if@GoodIDisnotnull begin begintran update Goods set inRoomID=@nowRoomID where GoodID=@GoodID delete list where GoodID=@GoodID print'You now release the '+@GoodName committran end else print'You don'+''''+'t have the '+@GoodName end release apple createproc list1 as begin print'You have:' select GoodName as'inventory' from list join Goods on list.GoodID=Goods.GoodID end dropproc eat createproc eat (@foodnvarchar(50)) as declare@GoodIDint,@foodIDint begin select@GoodID=list.GoodID from list join Goods on list.GoodID=Goods.GoodID and Goods.GoodName=@food if@GoodIDisnotnull begin select@foodID=list.GoodID from list join Goods_kind on List.GoodID=Goods_kind.GoodID join kind on Goods_kind.kindID=kind.id where list.GoodID=@GoodIDand kind.name like'%eat%' if@foodIDisnotnull begin begintran delete list where GoodID=@foodID update Goods set inRoomId=null where GoodID=@foodID print'Taste good.' committran end else print@food+' can'+''''+'t be edible' end else print'You don'+''''+'t have the '+@food end dropproc take createproc take (@GoodNamenvarchar(50)) as declare@GoodIDint,@canTakeIDint begin select@GoodID=GoodID from Goods where inRoomID=(select RoomID from nowRoom) and GoodName=@GoodName if@GoodIDisnull print'There is no '+@GoodName+' here' else begin select@canTakeID=GoodID from Goods_kind join kind on Goods_kind.kindID=kind.id where GoodID=@GoodID and kind.name like'%take%' if@canTakeIDisnotnull begin begintran insertinto list(GoodID) values(@canTakeID) update Goods set inRoomID=null where GoodID=@GoodID delete GoodsinGood where innerID=@GoodID print'You now have the '+@GoodName committran end else print'You can'+''''+'t pick up a '+@GoodName end end release [table] release [table] look list1 select*from Goods select*from goodsingood take 'washing maching' createfunction IDExistedInRoom(@namenvarchar(50)) returnsint as begin declare@idint select@id=GoodID from Goods where inRoomID=(select RoomID from nowRoom) and GoodName=@name return@id end declare@iint select@i=dbo.IDExistedInRoom('apple') go2 kitchen dropproc lookin createproc lookin (@GoodNamenvarchar(50)) as begin declare@GoodIDint select@GoodID=dbo.IDExistedInRoom(@GoodName) if@GoodIDisnull print'There is no '+@GoodName+' here' else begin print'You can see the following things:' select g2.GoodName from Goods g1 join GoodsinGood gig on g1.GoodID=gig.outerID join Goods g2 on gig.innerid=g2.GoodID where g1.GoodID=@GoodID end end lookin ee