---
title: "How to set column as AUTO_INCREMENT in MySQL"  
description: "How to set column as AUTO_INCREMENT in MySQL"  
author: "Sandra Emily"  
published: 2023-07-27  
updated: 2023-07-28  
canonical: https://www.mindstick.com/forum/159334/how-to-set-column-as-auto_increment-in-mysql  
category: "mysql"  
tags: ["database", "mysql"]  
reading_time: 2 minutes  

---

# How to set column as AUTO_INCREMENT in MySQL

How to set a [column](https://www.mindstick.com/forum/33860/how-to-calculate-column-summary-in-sql-server) as AUTO_INCREMENT in [MySQL](https://www.mindstick.com/articles/12156/what-is-mysql)

## Replies

### Reply by Aryan Kumar

To set a column as auto_increment in MySQL, you can use the `AUTO_INCREMENT` keyword when creating the table. The syntax is as follows:

SQL

```plaintext
CREATE TABLE table_name (
  column_name INT NOT NULL AUTO_INCREMENT,
  other_column_name VARCHAR(255) NOT NULL,
  ...
);
```

For example, the following SQL statement will create a table called `products` with a column called `id` that is auto_incremented:

SQL

```plaintext
CREATE TABLE products (
  id INT NOT NULL AUTO_INCREMENT,
  name VARCHAR(255) NOT NULL,
  price INT NOT NULL,
  PRIMARY KEY (id)
);
```

Once you have created the table, you can insert new rows into the table without specifying a value for the `id` column. MySQL will automatically increment the value of the `id` column for each new row that you insert.

Here are some additional things to keep in mind about auto_increment columns:

- The `AUTO_INCREMENT` keyword can only be used with integer columns.
- The starting value for the `AUTO_INCREMENT` column is 1.
- The `AUTO_INCREMENT` column will increment by 1 for each new row that you insert.
- You can change the starting value for the `AUTO_INCREMENT` column by using the `ALTER TABLE` statement.


---

Original Source: https://www.mindstick.com/forum/159334/how-to-set-column-as-auto_increment-in-mysql

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
