Mysql
 sql >> Database >  >> RDS >> Mysql

SQL:controlla se una colonna viene incrementata automaticamente

Per MySql, controlla il EXTRA colonna:

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%'

Per SQL Server, usa sys.columns e is_identity colonna:

SELECT 
    is_identity
FROM sys.columns
WHERE 
    object_id = object_id('my_table')
    AND name = 'my_column'