How to tell if a key in the sql server is identity

3

How to tell if a key in the sql server is identity? How do I find out? The version is 2014.

    
asked by anonymous 18.04.2017 / 18:56

3 answers

4
SELECT is_identity 
FROM sys.columns 
WHERE object_id = object_id('Nome_da_sua_tabela') 
AND name = 'Nome_da_sua_coluna'

It will return 1 if the column is identity

    
18.04.2017 / 18:59
2

Complementing the response of @Artur, if you want a relation (table / column) of all the identity keys of a given database:

select o.name, c.name
from sys.objects o inner join sys.columns c on o.object_id = c.object_id
where c.is_identity = 1
    
18.04.2017 / 19:23
1

You can use COLUMNPROPERTY for this.

select columnproperty(object_id('NomeTabela'),'NomeColuna','IsIdentity')

This will return one of the options:

  • 1 = TRUE

  • 0 = FALSE

  • NULL = The entry is not valid.

24.04.2017 / 18:35