SQL数据库原理与设计-实验七“查询语句”数据

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

70B0A14155718F1746C9E61DECDDFCCA9FE601F7FF5D30B6389406271 102E38ED

--drop database school

create database school --创建数据库

go

/*CREATE DATABASE school

ON

( NAME = school_dat,

FILENAME = 'd:\school1.mdf',

SIZE = 2,

MAXSIZE = 4,

FILEGROWTH = 1 )

LOG ON

( NAME =school_log,

FILENAME = 'd:\school1.ldf',

SIZE = 2MB,

MAXSIZE = 3MB,

FILEGROWTH = 1MB ) */

go

use school

go

EXEC sp_addtype ud_sno,'char(6)'

go

--创建表

create table Student (

Sno ud_sno ,

Sname char(10) not null unique ,

Ssex char(2) check (ssex='男' or ssex='女') ,

Sage smallint check(sage>16) ,

Sdept char(10) not null default 'JSJ' ,

primary key (sno)

)

create index ix_student_sname ON student(sname)

create table course(

Cno char(4) ,

Cname char(16) ,

Cpno char(4) ,

Ccredit int check (Ccredit >=0 and Ccredit<=5),

check( cno<>cpno) , --约束

primary key (cno)

)

create index ix_course_cpno ON course(cpno)

create table SC(

Sno ud_sno ,

Cno char(4) ,

Grade int check(grade<=100) ,

constraint pk_sc primary key (sno,cno),

foreign key (sno) references student(sno) ,

foreign key (cno) references course(cno) ,

)

create index ix_sc_cno ON sc(cno)

--添加数据

insert into Student (Sno,Sname,Ssex,Sage,Sdept) values ('0003','陈小明','男',20,'SX')

insert into Student (Sno,Sname,Ssex,Sage,Sdept) values ('0004','杨秀红','女',21,'JSJ')

相关文档
最新文档