- 自動編號,且必須與主鍵組合使用。
- 默認情況下,起始值為1,每次的增量為1。
例如:
CREATE TABLE tb3(
id SMALLINT UNSIGNED AUTO_INCREMENT,
username VARCHAR(20) NOT NULL
);
如果一個字段設置成自動編號,則該字段必須設置成主鍵。如果不設置,將會提示錯誤:ERROR 1075 (42000): Incorrect table definition; there can be only one auto column and it must be defined as a key
自動編號.png