SQL - Server - SQL实验与练习题参考答案

2020-05-05 16:16

数据库原理与应用(SQL Server)练习题 - 1 -

实验1 数据库操作

1.创建数据库:

操作1.1:创建一个test数据库,其主数据文件逻辑名test_data,物理文件名test_data.mdf,初始大小10MB,最大尺寸为无限大,增长速度1MB;数据库日志文件逻辑名称为test_log,物理文件名为test_log.ldf,初始大小为1MB,最大尺寸为5MB,增长速度为10%。

参考答案:

create database Test ON primary (

name = test_data,

filename = 'd:\\test\\test_data.mdf', size = 5MB,

maxsize = unlimited, filegrowth = 1MB ) LOG ON (

name = test_log,

filename = 'd:\\test\\test_log.ldf', size = 1MB, maxsize = 5MB,

数据库原理与应用(SQL Server)练习题 - 2 -

filegrowth = 10% ) GO

2.查看数据库属性:

操作1.2:使用T-SQL语句查看数据库test属性 参考答案:

EXEC sp_helpdb test 3.删除数据库:

操作1.3:使用T-SQL语句删除数据库test 参考答案:

drop database Test

实验2 表操作

1.创建表:

操作2.1:创建学生表: 表名:student

说明:学生基本信息表

列约束 PK 说明 属性列 数据类型 长度 空值 Not Null Not st_id st_nm nVarChar nVarChar 9 8 学生学号 学生姓名 数据库原理与应用(SQL Server)练习题 - 3 -

Null st_sex nVarChar 2 Null Null Null Null 学生性别 出生日期 入学成绩 入学日期 学生来源 所在系编号 学生职务 st_birth datetime st_score int st_date datetime st_from nChar st_dpid nVarChar st_mnt tinyint 20 Null 2 Null Null 参考答案: USE test GO

CREATE TABLE student (

st_id nVarChar(9) primary key NOT NULL , st_nm nVarChar(8) NOT NULL , st_sex nVarChar(2) NULL , st_birth datetime NULL , st_score int NULL , st_date datetime NULL , st_ from nVarChar(20) NULL , st_dpid nVarChar(2) NULL , st_ mnt tinyint NULL

数据库原理与应用(SQL Server)练习题 - 4 -

) GO

操作2.2:创建课程信息表: 表名:couse

说明:课程信息表

列约束 PK 说明 属性列 数据类型 长度 空值 Not Null Not Null Null Null cs_id nVarChar 4 课程编号 cs_nm nVarChar 20 cs_tm int cs_sc int 参考答案: USE test GO

CREATE TABLE couse (

课程名称 课程学时 课程学分 cs_id nVarChar(4) primary key NOT NULL , cs_nm nVarChar(20) NOT NULL , cs_tm int NULL , cs_sc int NULL )

数据库原理与应用(SQL Server)练习题 - 5 -

GO

操作2.3:创建选课表: 表名:slt_couse 属性列 数据类型 长度 说明:选课表 空值 Not Null Not Null Null Null 列约束 FK 说明 cs_id nVarChar 4 课程编号 st_id score nVarChar int 9 FK 学生编号 课程成绩 选课日期 sltdate datetime 参考答案: USE test GO

CREATE TABLE couse (

cs_id nVarChar(4) NOT NULL , st_id nVarChar(9) NOT NULL , score int NULL , sltdate datetime NULL ) GO


SQL - Server - SQL实验与练习题参考答案.doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:《可爱的家乡》主题活动反思

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: