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 auto increments. Here is how I am testing for those other things:
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 AUTO_INCREMENTS = 'YES'
Unfortunately there is no AUTO_INCREMENTS
column to compare against. So how can I test if a column auto increments?
5条答案
按热度按时间hyrbngr71#
For MySql, Check in the
EXTRA
column:For Sql Server, use
sys.columns
and theis_identity
column:qhhrdooz2#
Assuming MySQL, the
EXTRA
column will indicate whether it isAUTO_INCREMENT
.And for MSSQL, see here .
tct7dpnv3#
Run: describe 'table_name'; In column EXTRA is what you looking for
j2datikz4#
this works for sql server:
oknwwptz5#
In Postgres, try this:
And look for something like this (as opposed to
NULL
):nextval('my_schema.my_table_my_column_seq'::regclass)