#创建年级表(包含ID和姓名)
CREATE TABLE IF NOT EXISTS grade(
gradeId INT(4) NOT NULL PRIMARY KEY AUTO_INCREMENT,
gradeName VARCHAR(50) NOT NULL
)
#创建学生表(包含学号、姓名、年龄、年级、电话、性别、家庭地址)
CREATE TABLE IF NOT EXISTS student(
studentNo INT(4) NOT NULL PRIMARY KEY AUTO_INCREMENT,
studentName VARCHAR(20) NOT NULL DEFAULT '匿名',
age INT(4),
gradeId INT(4),
phoneNum VARCHAR(11),
sex VARCHAR(10),
address VARCHAR(50),
CONSTRAINT FK_gradeId FOREIGN KEY(gradeId) REFERENCES grade(gradeId)
)
创建主表和子表并建立约束
最新推荐文章于 2023-07-09 13:45:51 发布