数据库中定义表和建立完整性代码
来源:互联网 发布:淘宝买steam游戏步骤 编辑:程序博客网 时间:2024/05/17 06:39
--***************************************实验一******************************************
--**********************************建立表和定义完整性约束**************************
create database js
use js
drop table 院系
create table 院系( 编号 smallint Primary key,
名称 char(20) not null,
负责人 char(10),
办公地点 char(20),
constraint uniquea unique (名称)
)
create table 学生( 学号 char(8) Primary key,
院系 smallint,
姓名 char(10),
性别 char(2) check(性别 in('男','女')),
生源 char(6),
状态 char(4) check(状态 in('正常','留级','休学','退学')))
drop table 教师
create table 教师( 教师编号 char(8) Primary key,
院系 smallint foreign key references 院系(编号),
姓名 char(10),
性别 char(2) check(性别 in('男','女')),
职称 char(6) check(职称 in('教授','副教授','讲师','助教')),
专业 char(10))
drop table 课程
create table 课程( 课程编号 char(8)Primary key,
课程名称 char(20)not null,
责任教师 char(8)foreign key references 教师(教师编号),
学时 smallint not null,
课程性质 char(10) check(课程性质 in('公共基础','专业基础','专业选修','任意选修')))
drop table 选课
create table 选课( 学号 char(8)foreign key references 学生(学号) on delete cascade,
课程编号 char(8) foreign key references 课程(课程编号),
成绩 smallint check(成绩>=0 and 成绩<=100)default null,
primary key(学号,课程编号))
--实验要求
alter table 学生 add 平均成绩 smallint default null
alter table 课程 add constraint chk_xueshi check(学时%8=0)
alter table 课程 alter column 学时 smallint not null
alter table 院系 drop constraint uniquea
alter table 院系 alter column 名称 varchar(30)
alter table 院系 add constraint uniquea unique(名称)
alter table 教师 add 工资 numeric(5,2)
--**********************************建立表和定义完整性约束**************************
create database js
use js
drop table 院系
create table 院系( 编号 smallint Primary key,
名称 char(20) not null,
负责人 char(10),
办公地点 char(20),
constraint uniquea unique (名称)
)
create table 学生( 学号 char(8) Primary key,
院系 smallint,
姓名 char(10),
性别 char(2) check(性别 in('男','女')),
生源 char(6),
状态 char(4) check(状态 in('正常','留级','休学','退学')))
drop table 教师
create table 教师( 教师编号 char(8) Primary key,
院系 smallint foreign key references 院系(编号),
姓名 char(10),
性别 char(2) check(性别 in('男','女')),
职称 char(6) check(职称 in('教授','副教授','讲师','助教')),
专业 char(10))
drop table 课程
create table 课程( 课程编号 char(8)Primary key,
课程名称 char(20)not null,
责任教师 char(8)foreign key references 教师(教师编号),
学时 smallint not null,
课程性质 char(10) check(课程性质 in('公共基础','专业基础','专业选修','任意选修')))
drop table 选课
create table 选课( 学号 char(8)foreign key references 学生(学号) on delete cascade,
课程编号 char(8) foreign key references 课程(课程编号),
成绩 smallint check(成绩>=0 and 成绩<=100)default null,
primary key(学号,课程编号))
--实验要求
alter table 学生 add 平均成绩 smallint default null
alter table 课程 add constraint chk_xueshi check(学时%8=0)
alter table 课程 alter column 学时 smallint not null
alter table 院系 drop constraint uniquea
alter table 院系 alter column 名称 varchar(30)
alter table 院系 add constraint uniquea unique(名称)
alter table 教师 add 工资 numeric(5,2)
0 0
- 数据库中定义表和建立完整性代码
- 创建表和定义数据完整性
- 01创建表和定义数据完整性
- 数据库完整性和约束
- 数据库完整性和安全性
- SQL SERVER数据库定义和建立
- 【DB】 数据库完整性和约束
- 数据库的完整性和安全性
- oracle索引和数据库完整性
- 完整性约束的定义和检验
- 跟我一起学extjs5(28--加入模块和菜单定义[1建立数据库和表])
- 数据库---表的完整性约束
- oracle数据库中建立表空间和删除表空间
- SQL Server Management Studio 中使用代码建立数据库和数据表
- 对数据库中完整性概述的认识
- 数据库完整性
- 数据库完整性
- 数据库完整性
- 第五次作业
- mysql 的load data infile的用法
- 猜年龄
- 数据库alter使用
- Word Break I,II, Triangle,Palindrome Partitioning 动态规划 DP
- 数据库中定义表和建立完整性代码
- python3 多线程的基本用法
- 有关真机调试中arm CPU的指令集
- 跨站脚本攻击详解
- mysql使用指南(上)
- 在vmware中启动虚拟机显示内存不足
- OC---知识点
- 解决Github访问超慢问题
- JAVA设计模式之 状态模式【State Pattern】