数据库原理实验报告(一)

您所在的位置:网站首页 数据库原理实验报告答案怎么写 数据库原理实验报告(一)

数据库原理实验报告(一)

2024-07-14 07:15| 来源: 网络整理| 查看: 265

答案在后面 一、在studentdb中创建架构Production和Person并比较区别。

create schema Production --架构命名不能以数字开头

create schema Person AUTHORIZATION st

注意: 在创建Person架构前需要使用下面的三条语句先在当前数据库中添加用户,并仅仅授予该用户建表的权限。

CREATE LOGIN st WITH PASSWORD=‘suntao123’

CREATE USER st FOR LOGIN st

GRANT create table to st

然后用户st以SQL SERVER身份验证方式登录服务器,尝试执行如下的SQL语句:

create table Person.t1(id int,name char(10)) --成功

create table Production.t1(id int,name char(10)) --失败,原因?

二、修改表结构,具体要求如下:

(1) 将表course的cname列的数据类型改为varchar(40).

(2) 为表student增加一个新列: birthday(出生日期), 类型为datetime, 默认为空值.

(3) 将表sc中的grade列的取值范围改为小于等于150的正数.

(4) 为Student表的“Sex”字段创建一个缺省约束,缺省值为’男’

(5)为“Sdept”字段创建一个检查约束,使得所在系必须是’CS’、’MA’或’IS’之一。

(6)为Student表的“Sname”字段增加一个唯一性约束

(7)为SC表建立外键,依赖于Student表的fk_S_c约束。

(8)禁止启用Student表的“Sdept”的CHECK约束ck_student。

三、分别建立以下索引(如果不能成功建立,请分析原因)

(1) 在student表的sname列上建立普通降序索引.

(2) 在course表的cname列上建立唯一索引.

(3) 在sc表的sno列上建立聚集索引.

(4) 在spj表的sno(升序), pno(升序)和jno(降序)三列上建立一个普通索引.

create database spjdb; create database studentdb; use studentdb; create table student ( sno char(9) primary key not null, sname char(10) not null, ssex char(2), sage smallint, sdept char(15), check (sage >= 12) ); use studentdb; create table course ( cno char(4) primary key not null , cname char(20), cpno char(4), ccredit smallint, ); create table sc ( sno char(9) not null , cno char(4) not null , grade decimal(5,1), foreign key (sno)references student(sno), foreign key (cno)references course(cno), check (grade between 0 and 100) ); use spjdb; create table S( sno char(2) primary key not null , sname char(10) not null , status smallint, city char(10), check (status>0) ); create table P( pno char(2) primary key not null , pname char(10) not null , color char(2), weight smallint, check (weight>0) ); create table J( jno char(2) primary key not null , jname char(10) not null , city char(10) ); create table SPJ( sno char(2) not null , pno char(2) not null , jno char(2) not null , qty smallint, primary key (sno,pno,jno), foreign key (sno)references S(sno), foreign key (pno)references P(pno), foreign key (jno)references J(jno), check (qty>0) ); --use studentdb; --create schema Production; --CREATE LOGIN st WITH PASSWORD='本人mysql密码'; --CREATE USER st FOR LOGIN st; --GRANT create table to st; --create schema Person AUTHORIZATION st; --create table Person.t1(id int,name char(10)); --修改表 --(1) 将表course的cname列的数据类型改为varchar(40). --alter table course alter cname varchar(40); mysql alter table course alter column cname varchar(40); --(2) 为表student增加一个新列: birthday(出生日期), 类型为datetime, 默认为空值. alter table student add birthday datetime default null; --(3) 将表sc中的grade列的取值范围改为小于等于150的正数. --删除表中原有约束 alter table sc drop constraint CK__sc__grade__2A4B4B5E; --创建新约束 alter table sc add constraint grade_new check (grade


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3