当前位置:首页 > SQLServer2008实验五模板
)
Fworkother varchar(50)
--创建返回表信息的自定义函数,通过传入学生编号,返回有同学姓名和给其电脑信息的表 create function fnGetCOMInfo(@sno varchar(5)) returns table as return (
select
s.Fname,c.FNo,c.Ftype,c.FModule,FCPU,FMemory,FHardDisk,FVideo,FDisp,FOther
from Computer c,Student s
where c.FUserNo=s.FNo and c.FuserNo=@sno ) go
update Computer set FUserNO=null declare @cno varchar(5) --输出电脑编号 declare @count int
select @count=count(*) from Computer where FUserNo='001' --是否给该同学分配过电脑,不进行数据库操作 if(@count>0) begin
set @cno=0 end
else --未给该同学分配电脑 begin
select @cno=FNo from Computer where FUserNo is null order by NEWID() --随机产生一台未分配的电脑编号
update Computer set FUserNo='001' where FNO=@cno --修改表中分配情况
end go
SELECT * FROM dbo.fnGetCOMInfo('001')
/*执行自定义函数 通过修改学生编号即可
若以为该同学分配过电脑不做分配电脑的操作只查询其电脑信息 */
select * from Computer
实验结果 查询没有问题,之后最后一道题由于题目没有给出详细的要求,不知道表中的字段都应该有哪些,所以没有建完。其他的没有问题
疑难小结:本实验的疑难之处在于有时会忘记某些语法,其他的都没有什么问题。
共分享92篇相关文档