




下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、实验五 T-SQL编程实验目的:(1)进一步巩固第2章第4章所学内容;(2)掌握用户自定义类型的使用;(3)掌握变量的分类及其使用;(4)掌握各种控制语句的使用;(5)掌握系统函数及用户自定义函数的使用。实验内容:(1)在yggl数据库中创建Employees3表,表结构与Employees类似,只是EmployeeID列使用的数据类型为用户自定义数据类型ID_typeexec sp_addtype 'id_type','char(6)','not null'-自定义一数据类型id_type,描述员工编号if exists(select name
2、 from sysobjectswhere name='employees3')drop table employees3create table employees3(employeeid id_type,name char(10) not null,education char(4) not null,birthday datetime not null,sex bit not null default 1,workyear tinyint null,address varchar(40) null,phonenumber char(12) null,departmenti
3、d char(3) not null,primary key(employeeid)(2) 定义一个变量,用于描述YGGL数据库中的Salary表中员工的实际收入,然后查询该变量。declare gongzi char(10)Set gongzi=(select income-outcome as realcome from salary where EmployeeID='000001'); Select gongzi as realcome; (3)判断姓名为"王林"的员工实际收入是否高于,如果是则显示其收入,否则显示"收入不高于"。
4、if exists(select income-outcome from salary,employees where salary.employeeid=employees.employeeid and income-outcome>3000 and name='王林')select income-outcome from salary,employees where salary.employeeid=employees.employeeid and income-outcome>3000 and name='王林'elseselect name
5、,'收入不高于' from employees where name='王林'(4)用循环输出一个用"*"组成的三角形。实心三角形:declare lines int,i intset lines=10set i=1while i<=lines begin print space(lines-i)+replicate('*',2*i-1) set i=i+1end空心三角形:declare lines int,i intset lines=10set i=1print space(lines)+'*'wh
6、ile i<lines begin print space(lines-i)+'*'+space(2*i-1) +'*' set i=i+1endprint replicate('* ',lines+1)(5)自定义一个函数,能够计算一个数的阶乘create function factorial(num int)returns bigint as begindeclare result bigint;declare i int;select result=1;select i=1;if(num<1)beginselect result
7、=1endelse beginwhile(i<=num)beginselect result=result*i;select i=i+1;endendreturn result;endselect dbo.factorial(5);select dbo.factorial(7);select dbo.factorial(9);(6)求财务部收入最高的员工姓名select name from departments,employees e1,salary s1 where e1.employeeid=s1.employeeid and e1.departmentid=departments
8、.departmentidand departmentname='财务部' and income=(select max(income) from employees e2,salary s2where e2.employeeid=s2.employeeid and e2.departmentid=e1.departmentid)(7)查询员工收入的平均数select avg(income) as 员工收入的平均数 from salary (8)查询员工收入的平均数select left('abcdef',3)(9)使用day()函数返回指定日期的天数select day('2013-12-31')(10)列举出其他的时间日期函数。select getdate()select datename(yyyy,'2013-11-11')select datediff(dd,'2012-11-11','2013-11-11')sele
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 续保团队数据分析工作总结
- 2024年份11月携程平台客房销售不可抗力应对条款
- 班主任个人年度工作方案2025年演讲稿
- 2025年春季幼儿园幼师个人工作方案
- 学校称职校长2025年学期工作方案
- 2025年老师个人师德工作方案
- 生产安全月主题
- 物流技术与设备
- 甘肃省庆阳市合水县2025届数学三下期末调研模拟试题含解析
- 北京市首都师大附中2025年高三5月教学质量调研化学试题含解析
- 人教版(新教材)高中物理选择性必修3第三章 热力学定律章末检测试卷(三)
- 2024-2025年度安徽省职业院校技能大赛(中职组)竞赛规程-农机检修(教师赛)
- 2022年中国联通智家工程师技能大赛题库-上(单选题部分)
- 《职业卫生》专题培训
- 汽修厂安全事故应急预案(4篇)
- DB52T 046-2018 贵州省建筑岩土工程技术规范
- 混凝土安全晨会(班前会)
- (完整版)减数分裂课件
- 露天矿山开采施工组织方案
- 人教版英语八年级下册 Unit1-Unit2检测试题
- 2024小学语文教学及说课课件:二年级下册《沙滩上的童话》
评论
0/150
提交评论