[TOC=1,5]
>[success] # **語法**
* * * * *
>[info] ##### **基本語法**
```
create table 表名(
列名 類型 是否可以為空,
列名 類型 是否可以為空
)ENGINE=InnoDB DEFAULT CHARSET=utf8
```

<br>
* * * * *
>[info] ##### **設置字段是否為空-null**
```
默認值,創建列時可以指定默認值,當插入數據時如果未主動設置,則自動添加默認值
create table tb1(
nid int null -可空 ,
num int not null -不可為空
)
```
<br>
* * * * *
>[info] ##### **設置默認值-defalut**
```
默認值,創建列時可以指定默認值,當插入數據時如果未主動設置,則自動添加默認值
create table tb1(
nid int not null defalut 2,
num int not null
)
```
* * * * *
<br>
>[info] ##### **設置自增-auto_increment**
```
自增,如果為某列設置自增列,插入數據時無需設置此列
默認將自增(表中只能有一個自增列)
create table tb1(
nid int not null auto_increment primary key,
num int null
)
或
create table tb1(
nid int not null auto_increment,
num int null,
index(nid)
)
```
**注意**:
```
1、對于自增列,必須是索引(含主鍵)。
2、對于自增可以設置步長和起始值
3、自增時要用int 類型
```
圖片對應第二條`CREATE TABLE 表名 ( ...) AUTO_INCREMENT=10000`

<br>
* * * * *
>[info] ##### **主鍵 -primary key**
```
主鍵,一種特殊的唯一索引,不允許有空值,如果主鍵使用單個列,則它的值必須唯一,如果是多列,則其組合必須唯一。
create table tb1(
nid int not null auto_increment primary key,
num int null
)
或
create table tb1(
nid int not null,
num int not null,
primary key(nid,num)
)
```