1. 建表时设置1个主键
CREATE TABLE `Student`( `s_id` VARCHAR(20) primary key, `s_name` VARCHAR(20) , `s_birth` VARCHAR(20) , `s_sex` VARCHAR(10) )engine = Innodb default charset = utf8mb4 ;
或者
CREATE TABLE `Teacher`( `t_id` VARCHAR(20), `t_name` VARCHAR(20), PRIMARY KEY(`t_id`) )engine = Innodb default charset = utf8mb4;
2. 建表时设置2个或多个主键
CREATE TABLE `Score`( `s_id` VARCHAR(20) , `c_id` VARCHAR(20) , `s_score` INT(3), PRIMARY KEY(`s_id`,`c_id`) )engine = Innodb default charset = utf8mb4;
注意 : 存在自增字段时, 自增列必须设置为主键.