该建表sql语句在日常学习,工作中用于参考使用
CREATE TABLE classes(
id int auto_increment primary key,
classname char(30) not null
)engine=innodb charset=utf8;
CREATE TABLE students(
id int auto_increment primary key,
name char(24) not null,
class_id int ,
unique uq1 (name,class_id),
constraint fk_students_classes foreign key (‘class_id‘) refernces classes(‘id‘)
)engine=innodb charset=utf8;
CREATE TABLE teacher (
id int auto_increment primary key,
name char(24) not null
)engine=innodb charset=utf8;
CREATE TABLE teacher2class(
id int auto_increment primary key,
t_id int not null,
c_id int not null,
constraint `fk_student` foreign key (`t_id`) peferences `teacher`(`id`),
constraint `fk_class` foreign key (`c_id`) peferences `classes`(`id`)
)engine=innodb charset=utf8;
CREATE TABLE students (
id int auto_increment primary key,
name varchar(32),
class_id int not null,
constraint fk_user_depar foreign key (`class_id`) refernces classes(`id`)
)engine=innodb default charset=utf8;
CREATE TABLE department (
id bigint auto_increment primary key,
title char(15)
)engine=innodb default charset=utf8;
CREATE TABLE user_info(
id int auto_increment primary key,
username varchar(30) not null ,
password varchar(30) not null
)engine=innodb default charset=utf8;
原文地址:https://blog.51cto.com/12643266/2417046
时间: 2024-10-23 19:21:10