1.创建表单
格式:create table + 表单名称
mysql> create table sc;
Query OK, 0 rows affected
2.设置主键/主码
关键词:primary key
mysql> create table teacher
-> (tno char(3) primary key);
Query OK, 0 rows affected
3.定义主键约束
格式:constraint + 约束名 + primary key(字段名1,字段名2,…,字段名n)
mysql> create table teaching
-> (cno char(5) NOT NULL,
-> tno char(3) NOT NULL,
-> constraint A1 primary key(cno,tno));
4.设置外键/外码
关键词:foreign key
mysql> create table teaching
-> (cno char(5) foreign key);
Query OK, 0 rows affected