Home > Database > Mysql Tutorial > How to find out whether a column is an auto-increment column in MySQL?

How to find out whether a column is an auto-increment column in MySQL?

WBOY
Release: 2023-08-24 08:21:02
forward
746 people have browsed it

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%';
Copy after login

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)
Copy after login

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%';
Copy after login

Below is the output showing the column i.e. auto_increment −

+-------------+
| COLUMN_NAME |
+-------------+
| ClientId    |
+-------------+
1 row in set (0.00 sec)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template