下载本文档
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 秋冬换季感冒高发期家庭预防护理方案
- 2026 年夏季护理实习生实习期间压力管理与心理健康课
- 2026 年扁桃体炎病例护理研讨
- 2026 年输血护理知识在临床带教中的落实
- 2026年急诊科止血包扎固定护理实操培训
- 区位优势测试题及答案展示
- 2026年《花卉学》期末考试综合提升试卷附答案详解(能力提升)
- 2026年产品质量与售后服务改进方案
- 2026年度保密教育线上培训真题和答案
- 2026年高职农学(作物栽培学)试题及答案
- 新疆油气田钻井固体废物综合利用污染控制要求(DB 65-T 3997-2017)
- 2026年共青团入团考试试题附标准答案
- 2026郑州市新初一三科分班摸底卷摸底卷
- 2026年渭南市大荔县数学三下期末统考模拟试题含答案
- (2024版)中国成人暴发性心肌炎诊断和治疗指南课件
- (2026年)痔疮的诊断和治疗健康宣教课件
- 老年人慢性病管理与护理
- (2026年)血气分析临床解读课件
- 复温新技术汇报
- JG/T 335-2011混凝土结构防护用成膜型涂料
- 安全经验分享:中石油触电事故安全经验分享
评论
0/150
提交评论