How to know if a key in sql server is Identity

Asked

Viewed 419 times

3

How do I know if a key in sql server is Identity? How do I find out? The version is 2014.

3 answers

4


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

Will return 1 if column is Identity

2

Complementing @Artur’s reply, if you want a relation (table/column) of all identitys 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

1

You can use the COLUMNPROPERTY for that reason.

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

This way will return one of the options:

  • 1 = TRUE

  • 0 = FALSE

  • NULL = The input is not valid.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.