mysql fk1_mysql命令

这段代码展示了如何创建数据库表,包括学院、部门、班级、学生和课程表。primary key 指定列作为表的唯一标识,not null 确保字段不允许为空。foreign key 定义了表之间的引用关系,如部门表引用学院表,学生表和课程表分别引用学院、部门表。numeric 类型用于存储数值,如学分。constraint 用于定义各种约束,如 dept_fk 指定外键约束。
摘要由CSDN通过智能技术生成

createtablecollege(coll_idchar(2)primarykey,coll_namevarchar(30)notnull);createtabledept(dept_idchar(4)primarykey,coll_idchar(2)notnull,dept_namevarchar(30),constraintdep...

create table college(

coll_id char(2) primary key,coll_name varchar(30) not null

);

create table dept(

dept_id char(4) primary key,coll_id char(2) not null,dept_name varchar(30),

constraint dept_fk foreign key(coll_id) references college(coll_id)

);

create table class(

class_id char(6) primary key,dept_id char(4) not null,coll_id char(2),

class_name varchar(6) not null,

constraint class_fk1 foreign key(dept_id) references dept(dept_id),

constraint class_fk2 foreign key(coll_id) references college(coll_id)

);

create table student(

stu_id char(12) primary key,stu_name varchar(20) not null,stu_gender char(2)

check(stu_gender='男' or stu_gender='女'),stu_birth datetime,

nativeplace varchar(60),coll_id char(2) not null,dept_id char(4) not null,

class_id char(6) not null,cometime datetime not null,

constraint stu_fk1 foreign key(class_id) references class(class_id),

constraint stu_fk2 foreign key(dept_id) references dept(dept_id),

constraint stu_fk3 foreign key(coll_id) references college(coll_id)

);

create table course(

cou_id char(6) primary key,cou_name varchar(30) not null,xuefen numeric(3,1) not null,

coll_id char(2) not null,dept_id char(4) not null,

constraint cou_fk1 foreign key(dept_id) references dept(dept_id),

constraint cou_fk2 foreign key(coll_id) references college(coll_id)

);

上述代码中,primary key是什么意思,not null 是什么意思 foreign key是什么意思 numeric是什么类型

constraint dept_fk foreign key(coll_id) references college(coll_id)这些语句是什么意思

展开

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值