《SQL Server 2005实用教程》实验报告(6).doc
文本预览下载声明
《SQL Server 2005实用教程》实验报告(六) 班级: 学号: 姓名: 实验成绩: 优秀 □ 良好 □ 中□ 及格 □ 不及格 □ 实验题目:使用查询编辑器创建表 实验目的:掌握使用Transact_SQL语句创建和修改数据库表基本方法。 实验要求:
创建一个包含员工信息的表Employees
创建一个包含部门信息的表Departments
创建一个表Tmp
对上面的表作如下修改
查询其他系中比信息系所有学生年龄都小的学生姓名及年龄为Employees表添加一个日期型的出生日期字段,添加一个浮点型的工次字段,删除年龄字段.
将Departments表中的DepID字段设为主键。
将Employees表中的Department字段设为键,与Departments表中的主键关联,名为FK_emp_dep.
将Departments表中DepName字段长度改为20.
将Employees中的Salary字段的值限定为0~10000
5、删除表Tmp。 实验内容:
用T_SQL语句完成创建表的操作。
创建Employees表语句为:create table Employees(empID char(10) primary key,Name char(20) not null,Department tinyint not null,Age tinyint null,Memo varchar(60) null)
Employees表
创建Departments表。语句为:create table Departments(DepID tinyint not null,Depname char(10) not null,Meme varchar(10) null)
Departments表
创建表Tmp。语句为:create table Tmp(ID uniqueidentifier)
Tmp表
用T_SQL语句完成修改表的操作。
修改Employees表。语句为:alter table Employees add BirthDate smalldatetime,Salary float goalter table Employeesdrop column Agego
修改后的Employees表
修改Departments表。语句为:alter table Departmentsadd constraint PK_dep primary key(DepID)
修改后的Departments表
为表Employees添加外键。语句为:alter table Employees add constraint FK_emp_dep foreign key(Department)references Departments(DepID)
添加外键的语句的截图
将Departments表中的DepName字段长度改为20语句为:alter table Departmentsalter column DepName char(20)
修改DepName字段的表
为Employees表中的Salary设置约束。语句为:alter table [dbo].[Employees] add constraint CK_emp_salary check(Salary=0 and Salary=10000)
进行Salary设置后的Employees表
用T_SQL语句删除表Tmp。语句为:drop table Tmp
删除表Tmp所写的语句
实验总结:
显示全部