Glenn Slaven
Glenn Slaven

Reputation: 34183

How can I find if a column is auto_increment in mysql?

I'm trying to inspect my mysql database information_schema to find out the attributes of the columns. I can't find where the details as to which columns are auto_increment. Does anyone know where I can find this info in the information_schema DB?

Upvotes: 9

Views: 5098

Answers (2)

Jan Święcki
Jan Święcki

Reputation: 1683

You could use

mysql> DESCRIBE yourtable;

Example:

mysql> use my_database;
mysql> describe users;
+----------+--------------+------+-----+---------+----------------+
| Field    | Type         | Null | Key | Default | Extra          |
+----------+--------------+------+-----+---------+----------------+
| user_id  | int(11)      | NO   | PRI | NULL    | auto_increment |
| password | varchar(128) | NO   |     | NULL    |                |
| email    | varchar(128) | NO   |     | NULL    |                |
+----------+--------------+------+-----+---------+----------------+

Upvotes: 7

jscoot
jscoot

Reputation: 2109

see the EXTRA column in the COLUMNS table:

select * from COLUMNS where  TABLE_SCHEMA='yourschema' and TABLE_NAME='yourtable' and EXTRA like '%auto_increment%'

Upvotes: 15

Related Questions