数据库MySQL编写_数据库MySQL的创建

#如果存在数据库School,则删除。否则创建数据库

drop database if exists `School`;

#创建数据库

create database `School`;

use `School`;

#创建一个学校系表:系号(主键,自增),系办公地点,人数

drop table if exists `tb_dept`;

create table `tb_dept`

(

`id` int(11) not null AUTO_INCREMENT PRIMARY key,

`Local` varchar(32) not null,

`Dnum` int(4) not null

);

#创建一个学生班级表:班级id(主键,自增),专业名,系名(外键),人数

drop table if exists `tb_class`;

create table `tb_class`

(

`id` int(11) not null AUTO_INCREMENT primary key ,

`CName` varchar(32) not null,

`CdeptId` int(11) not null ,

`CNum` int(4) not null,

constraint `FK_Stuid` foreign key(`CdeptId`) references `tb_dept`(`id`)

);

#创建一个学生信息表:学生id(自增,主键),姓名,年龄,性别,所属班级id(外键),宿舍区。

drop table if exists `tb_student`;

create table `tb_student`

(

`id` int(11) not null auto_increment primary key,

`SName` varchar(32) not null,

`Age` int default 0,check(`Age`>0 and `Age`<=100),

`gender` boolean default 0,check(`gender`=0 or `gender`=1),

`classId` int(11) not null ,

constraint `FK_Stuid1` foreign key(`classId`) references `tb_class`(`id`)

);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值