欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

mysql 建数据库 建表_MySQL

程序员文章站 2022-05-13 11:45:37
...
创建数据库:create database td character set =utf8;use database td;//在数据库td中创建表
create table tb_student (
Student_ID int auto_increment primary key,
Student_Name varchar(20),
Sex char(1),
Birthday varchar(10)
) engine=innodb default character set =utf8 auto_increment =100;//指定存储引擎和字符集 create table tb_subject (
Subject_ID int auto_increment primary key,
Subject_Name varchar(50)
) engine=innodb default character set =utf8;

create table tb_score (
ID int auto_increment primary key,
Student_ID int,
Subject_ID int,
Score decimal(10,2),
foreign key (Student_ID) references tb_student(Student_ID),//外键
foreign key (Subject_ID) references tb_subject(Subject_ID)
) engine=innodb default character set =utf8;
相关标签: 建数据库