主键 唯一 并 不允许为空.
建表
mysql> create table if not exists students(id int primary key, name varchar(128) not null,age int,male enum('男','女'));
Query OK, 1 rows affected, 0 warning (0.00 sec)
查询 表结构
show create table students;
+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table |
+----------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| students | CREATE TABLE students
(
id
int(11) NOT NULL,
name
varchar(128) NOT NULL,
age
int(11) DEFAULT NULL,
male
enum('男','女') DEFAULT NULL,
PRIMARY KEY (id
)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
修改字段属性 需要重新 申请 类型,是否允许为空,是否自增长,是否唯一,主键不用 重复 定义.
mysql> alter table students modify id int auto_increment;
Query OK, 0 rows affected (0.25 sec)
Records: 0 Duplicates: 0 Warnings: 0
网友评论