Home >Database >Mysql Tutorial >How to find out whether a column is an auto-increment column in MySQL?
To find whether a column is auto_increment in MySQL, you can use the following syntax −
select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='yourDatabaseName' and TABLE_NAME='yourTableName' and EXTRA like '%auto_increment%';
Let us first create a table. Here, ClientId is set AUTO_INCREMENT −
mysql> create table autoIncrementTableDemo -> ( -> ClientId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ClientName varchar(20), -> ClientAge int, -> ClientAddress varchar(100), -> ClientCountryName varchar(100) -> ); Query OK, 0 rows affected (0.61 sec)
Now, let us find out if any column is auto_increment −
mysql> select COLUMN_NAME from information_schema.columns where TABLE_SCHEMA='test' and TABLE_NAME='autoIncrementTableDemo' and EXTRA like '%auto_increment%';
Below is the output showing the column i.e. auto_increment −
+-------------+ | COLUMN_NAME | +-------------+ | ClientId | +-------------+ 1 row in set (0.00 sec)
The above is the detailed content of How to find out whether a column is an auto-increment column in MySQL?. For more information, please follow other related articles on the PHP Chinese website!