0

Using this query

SELECT C.COLUMN_NAME[name] 
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS T 
INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE C 
ON T.CONSTRAINT_NAME = C.CONSTRAINT_NAME 
WHERE T.CONSTRAINT_TYPE = 'PRIMARY KEY' 
AND T.TABLE_NAME = 'table1' 

it shows if the table has primarykey, but i want to modify this sql as if the table has no primarykey but it has an identity set as 1, return me a record so i can identify it

Seb
  • 49
  • 6

1 Answers1

0

This should do the trick:

SELECT COLUMN_NAME [name]
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_NAME = 'table1' 
    AND COLUMNPROPERTY(object_id(TABLE_SCHEMA + '.' + TABLE_NAME), COLUMN_NAME, 'IsIdentity') = 1

Adapted from this answer: https://stackoverflow.com/a/87993/3519440

Onkel-j
  • 1,139
  • 10
  • 7