I am trying to run a query to check if a column auto increments. I can check type, default value, if it\'s nullable or not, etc. but I can\'t figure out how to test if it au
For MySql, Check in the EXTRA column:
SELECT *
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'my_table'
AND COLUMN_NAME = 'my_column'
AND DATA_TYPE = 'int'
AND COLUMN_DEFAULT IS NULL
AND IS_NULLABLE = 'NO'
AND EXTRA like '%auto_increment%'
For Sql Server, use sys.columns and the is_identity column:
SELECT
is_identity
FROM sys.columns
WHERE
object_id = object_id('my_table')
AND name = 'my_column'