> For the complete documentation index, see [llms.txt](https://learnsql.gitbook.io/lernmysql/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://learnsql.gitbook.io/lernmysql/welcome-to-the-mysql-tutorial/tao-auto_increment.md).

# Tạo AUTO\_INCREMENT

Để tạo `AUTO_INCREMENT` thì ta thêm từ khóa `AUTO_INCREMENT` đằng sau field muốn tạo trong lệnh tạo bảng ([Create Table](https://freetuts.net/lenh-tao-bang-create-table-trong-mysql-314.html)). Thông thường chúng ta dùng cho khóa chính nên trong các ví dụ dưới đây tôi sử dụng cho field `ID`.

```
CREATE TABLE Users(
    id INT(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
    username VARCHAR(50) NOT NULL UNIQUE,
    email VARCHAR (50) NOT NULL UNIQUE
)
```
