CREATE TABLE teb_test(
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(20)
);
CREATE TABLE `teb_test` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(20) DEFAULT NULL,
PRIMARY KEY (`id`)
)
CREATE TABLE tab_test(
id INT AUTO_INCREMENT PRIMARY KEY,
job_id INT,
CONSTRAINT fg_job_id
FOREIGN KEY(job_id) REFERENCES employees(employee_id)
);
ALTER TABLE tab_test MODIFY COLUMN id INT AUTO_INCREMENT UNIQUE ;
# 主键只有一个
ALTER TABLE tab_test DROP PRIMARY KEY;
# 外键约束需要指定索引名称
ALTER TABLE tab_test DROP FOREIGN KEY fg_job_id;
# 也可手动为unique设置约束名
ALTER TABLE goodstest ADD CONSTRAINT GNAME_UNI UNIQUE KEY(GNAME)
ALTER TABLE tab_test ADD PRIMARY KEY(id);