创建表时添加主键约束
create table author (author_id int(11) primary key, name varchar(45),email varchar(45));
创建表时添加外键约束
create table book (
book_id int primary key,
title nvarchar(128),
description nvarchar(512),
published DATE ,
author_id int,
price float,
rating int,
constraint book_author_fk foreign key(author_id) references author(author_id));
删除外键约束
-- 修改表删除外键约束
alter table book drop foreign key book_author_fk;
修改表的时候添加外键约束
alter table book
add constraint author_book_FK foreign key (author_id) references author(author_id);
修改表添加自增列约束
alter table book change book_id book_id int not null auto_increment;