首页 | 新闻 | 交流 | 问吧 | 文档 | 手册 | 下载 | 博客

mysql 建数据库 建表

作者:  时间: 2011-05-22

创建数据库:
create database td;
use database td;//在数据库td中创建表
创建表:
create table tb_student (
Student_ID
int auto_increment primary key, //自增id,指定主键
Student_Name
varchar(20),
Sex
char(1),
Birthday
varchar(10)
) 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;
create table tb_subject (
Subject_ID
int auto_increment primary key,
Subject_Name
varchar(50)
) engine
=innodb default character set =utf8;