文档详情

《SQL数据库上机考试题》.doc

发布:2015-10-17约1.11万字共12页下载文档
文本预览下载声明
一、用Transact-SQL语句定义数据库(每题6分,共12分) 1、创建名为School的数据库,该数据库包含二个大小为2MB的数据文件(文件名为:你的姓名_school_dat1和你的姓名_school_dat2)和一个大小为1MB的事务日志文件(文件名为:你的姓名_school_log)。限制数据文件大小为5MB、日志文件为2MB。对于所有文件,允许20%的文件增长。请将创建数据库的Transact-SQL脚本存为你的姓名_1_01.sql文件。 解: drop database school go create database school on primary (name=lts_school_dat1, filename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\lts_school_dat1.mdf, size=3MB, maxsize=5MB, filegrowth=20%), filegroup fgroup (name=lts_school_dat2, filename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\lts_school_dat2.ndf, size=2MB, maxsize=5MB, filegrowth=20%) log on (name=lts_school_log, filename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\lts_school_log.ldf, size=1MB, maxsize=2MB, filegrowth=20%) go 2、 修改数据文件你的姓名_school_dat1,增加其大小至3MB,并允许按0.5MB(512KB)的增量增至最大大小6MB;删除数据文件你的姓名_school_dat2;添加一个新的1MB的数据文件(文件名为:你的姓名_school_dat3),允许它以1MB增量增至磁盘被充满。请将Transact-SQL脚本存为你的姓名_1_02.sql文件。 解: alter database school modify file (name=lts_school_dat1, size=4MB, maxsize=6MB, filegrowth=512KB) go alter database school remove file 1 _school_dat2 go alter database school add file (name=lts_school_dat3, filename=C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\lts_school_dat3.ndf, size=1MB, maxsize=unlimited, filegrowth=1MB) go 二、用Transact-SQL语句在School数据库中定义表(每题6分,共30分) 根据所给的学生表建立表名为你的姓名_student的表,T-SQL脚本存为你的姓名_2_01.sql文件。要求: 设置学号列数据类型为char(11),主键约束,约束名为pk_xh; 设置身份证号码列唯一约束,约束名为un_xh; 在你的姓名_student表的姓名列上创建一个非聚集索引inx_sname。 其它列根据学生表的数据定义。 解: create table lts_student (学号char(11) not null constraint pk_xh primary key, 姓名char(20) not null , 身份证号int not null constraint un_xh unique, 籍贯char(20) not null, 家庭住址char(20) not null, 电话int not null, 特长char(20), 奖励char(40), 处分char(40), ) go create unique nonclustered index inx_sname on lts_student(姓名) gocreate table lts_course (课程代码char(5) not null constraint pk_kcdh primary key constraint ck_ccd check(char(0) in(0,1,2,3,4) and char(1) in(0,1)), 课程名char(40)
显示全部
相似文档