第二章:数据库的实现
来源:互联网 发布:淘宝卖家钱多久到账 编辑:程序博客网 时间:2024/06/04 23:18
use master go exec sp_configure 'show advanced options',1 go reconfigure go exec sp_configure 'xp_cmdshell',1 go reconfigure go exec xp_cmdshell 'mkdir d:\project' go if exists(select * from sysdatabases where name='myschool') drop database myschool create database myschool on primary(name='myschool_data',filename='d:\project\myschool.mdf',size=10,filegrowth=20%) log on(name='myschool_log',filename='d:\project\myschool.ldf',size=3,maxsize=20,filegrowth=1) use myschool go if exists(select * from sysobjects where name='subject') drop table subject create table subject( subjectno int identity(1,1) not null, subjectname nvarchar(50), classhour int, gradeid int) if exists(select * from sysobjects where name='result') drop table result create table result( studentno int not null, subjectno int not null, examdate datetime not null, studentresult int not null) if exists(select * from sysobjects where name='student') drop table student create table student( studentno int not null, loginpwd nvarchar(50) not null, studentname nvarchar(50) not null, sex bit not null, gradeid int not null, phone varchar(50), address nvarchar(255), borndate datetime not null, email varchar(50), id varchar(18) not null) if exists(select * from sysobjects where name='grade') drop table grade create table grade( gradeid int not null, gradename nvarchar(50) not null) alter table grade add constraint pk_gradeid primary key(gradeid) alter table student add constraint pk_studentno1 primary key(studentno) alter table student add constraint uq_id unique(id) alter table student add constraint ck_borndate check(borndate>='1980-01-01') alter table student add constraint df_address default('地址不详') for address alter table student add constraint fk_studentno1 foreign key(studentno) references student(studentno) alter table subject add constraint pk_subjectno primary key(subjectno) alter table subject add constraint ck_subjectname check(subjectname!=null) alter table subject add constraint ck_classhour check(classhour>=0) alter table subject add constraint fk_gradeid foreign key(gradeid) references grade(gradeid) alter table result add constraint pk_studentno2 primary key(studentno,subjectno,examdate) alter table result add constraint df_examdate default(getdate()) for examdate alter table result add constraint ck_studentresult check(studentresult<=100 or studentresult>=0) alter table result add constraint fk_studentno2 foreign key(studentno) references student(studentno) alter table result add constraint fk_studentno3 foreign key(subjectno) references subject(subjectno)
0 0
- 第二章--数据库的实现
- 第二章:数据库的实现
- 优化MySchool 第二章:数据库的实现
- SQL高级 第二章 数据库的实现
- S2 优化MySchool 第二章 数据库的实现
- 优化MySchool第二章s数据库的实现
- 第二章:数据库的实现 (课后简答题二)
- 第二章 数据库的操作
- 二期 , 第二章 数据库的实现---- 课后作业--- 创建图书馆管理系统数据库
- 第二章:第二节:PVPlayerDriver的实现。
- 数据库系统实现 第二章 辅助存储管理
- 第二章 数据库基本概念
- 第二章、关系数据库
- 数据库第二章习题
- 数据库第二章作业
- 数据库第二章
- 数据库第二章
- 数据库练习第二章
- 学习笔记1--协方差矩阵
- 第四章:高级查询
- WEB入门之十六 操作DOM节点
- 第三章:SQL 编程
- docker简介及使用国内镜像源安装docker
- 第二章:数据库的实现
- 开源数据库最全盘点
- bzoj 4031: [HEOI2015]小Z的房间 (矩阵树定理+高斯消元)
- 转载-面试感悟----一名3年工作经验的程序员应该具备的技能
- 最长公共子序列(LCS)
- (Java学习笔记5.2)选择排序
- 新建数据库-添加数据-添加约束
- SQL编程
- Linux下用gdb调试多进程与多线程程序