数据库系统原理 实验(实习)报告—— T-SQL编程

这篇实验报告详细介绍了T-SQL的使用,包括变量声明、运算符、控制语句、系统函数的应用,以及用户自定义函数的创建和调用。通过具体示例展示了如何在StudentCourse数据库上操作,如查询平均成绩、条件筛选、循环处理、日期获取、记录更新检测等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、实验目的

1、了解T-SQL变量的使用方法。

2、掌握T-SQL各种运算符、控制语句的功能及使用方法

3、掌握常用系统函数的调用方法。

4、掌握用户自定义函数的使用。

二、实验内容与步骤

在StudentCourse数据库上,用SQL语句实现下面操作:

1、局部变量的使用

(1)声明一个局部变量avggrade,并将StuCourse表中成绩的平均分赋值给变量avggrade(分别用set和select两种赋值方式)。(语法可参考教材例6.1)

语句:

结果:

DECLARE @avggrade REAL

SET @avggrade = (SELECT AVG(成绩) FROM StuCourse)

PRINT @avggrade

DECLARE @avggrade REAL

SELECT @avggrade = AVG(成绩) FROM StuCourse

PRINT @avggrade

结果:

(2)声明一个局部变量i并赋值为70,查询成绩大于i的学生学号和选修的课程号。

语句:

DECLARE @i INT

SET @i = 70

SELECT 学号,课程号

FROM StuCourse

WHERE 成绩 > @i

1、 Find the name, loan number and loan amount of all customers; rename the column name loan_number as loan_id. 2、 Find the names of all customers whose street includes the substring “Main”. 3、Find all customers who have a loan, an account, or both: 4、Find all customers who have both a loan and an account. 5、Find all customers who have an account but no loan. 6、Find the average account balance at the Perryridge branch. 7、 Find the number of tuples in the customer relation. 8、 Find the number of depositors in the bank. 9、 Find the number of depositors for each branch. 10、Find the names of all branches where the average account balance is more than $1,200. 11、Find all loan number which appear in the loan relation with null values for amount. 12、Find all customers who have both an account and a loan at the bank. 13、Find all customers who have a loan at the bank but do not have an account at the bank 14、Find all customers who have both an account and a loan at the Perryridge branch 15、Find all branches that have greater assets than some branch located in Brooklyn. 16、Find the names of all branches that have greater assets than all branches located in 1、创建一个School数据库,该数据库的主数据文件逻辑名称为SCHOOL_data,物理文件名为School.mdf,初始大小为10MB,最大尺寸为无限大,增长速度为10%;数据库的日志文件逻辑名称为School_log,物理文件名为School.ldf,初始大小为1MB,最大尺寸为5MB,增长速度为1MB。 2、用SQL语句建立上述表,自定义主键和外键,对于student表建立约束条件:ssex仅能取male或female;sage在18和22之间。并完成下面的查询语句。 1、查询所有选修过“Bibliometrics”课的学生的姓名和成绩; 2、查询考试成绩不及格的学生的个数; 3、查询名字中至少含有一个“z”字符的学生的姓名、学号和性别; 4、查询选修了“Introduction to the Internet”课程的学生的学号及其成绩,查询结果按分数的降序排列; 5、查询“Zuo li”同学选修课程的总学时(time)数 6、查询年龄不大于20岁的学生的平均考试成绩; 7、查询 “computer science”专业学生选修 “Database System”的人数; 8、查询同时选修课程“Database System”和“Introduction to the Internet”的学生姓名; 9、查询选修的课程中含有“Wang gang”同学所有选修课程的学生姓名。 10、查询“Information Technology for Information Management”考试成绩为空的学生姓名及专业名称。 11、查询“computer science”专业学生每个人的选修课总学分。 12、查询个人考试平均成绩高于专业平均成绩的学生姓名 13、查询个人考试平均成绩高于女生平均成绩的男生姓名 14、查询比“computer science”专业所有学生年龄都大的学生姓名。 15、查询考试成绩仅有一科不及格学生姓名
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值