学生信息数据库

create database 学生信息数据库
go
use 学生信息数据库
go
create table 课程信息表
(
课程号 int not null,
课程名称 char(20) not null,
学分 int not null
)
create table 学生信息表
(
学号 int not null,
姓名 char(10) not null,
性别 char(2) not null
)
create table 学生成绩表
(
考号 int not null,
学号 int null,
课程号 int null,
分数 int not null
)
alter table 课程信息表
add constraint PK_CourseInfo primary key (课程号)
alter table 课程信息表
add constraint DF_Marks default (1) for 学分
alter table 课程信息表
add constraint CH_Marks check (学分>1 and 学分<5)
alter table 学生信息表
add constraint PK_StuID primary key (学号)
alter table 学生信息表
add constraint DF_StuID default (0) for 学号
alter table 学生信息表
add constraint CH_StuID check (学号 >0 and 学号 < =100)
alter table 学生成绩表
add constraint PK_ExamNO primary key (考号)
alter table 学生成绩表
add constraint FK_StuID foreign key (学号) references 学生信息表(学号)
alter table 学生成绩表
add constraint FK_CourseNO foreign key (课程号) references 课程信息表(课程号)
alter table 学生成绩表
add constraint DF_Score default (0) for 分数
alter table 学生成绩表
add constraint CH_Score check (分数 >0 and 分数 <=100)


插入数据:
use 学生信息数据库
go
insert into 学生信息表 (姓名,性别,学号,联系电话) values ('胡火云','男',001,'15172046802')
insert into 学生信息表 (学号,姓名,性别,联系电话) values(002,'康年香','女','07137660970')
insert into 学生信息表 (学号,姓名,性别,联系电话) values(003,'胡学明','男','13939774584')
insert into 学生信息表 (学号,姓名,性别,联系电话) values(004,'胡松楠','女',NULL)
insert into 学生信息表 (学号,姓名,性别,联系电话) values(005,'胡松强','女',NULL)
insert into 学生信息表 (学号,姓名,性别,联系电话) values(006,'胡国鹏','男',NULL)
insert into 学生信息表 (学号,姓名,性别,联系电话) values(007,'胡伟红','女',NULL)
insert into 学生信息表 (学号,姓名,性别,联系电话) values(008,'吴秋贵','女',NULL)
update 学生信息表 set 联系电话='88888' where 性别='女'
select 姓名,性别 from 学生信息表 where 学号 <> 004
delete from 学生信息表
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值