I am iterating through a list of database columns using this code:
adapter = New SqlDataAdapter("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" & i & "'", connection)
Dim ds_cols As New DataSet
adapter.Fill(ds_cols)
For Each c As DataRow In ds_cols.Tables(0).Rows
'doing lots of things in here
Next
Now, i would need to query the database (or even better edit the existing one) to know if the current column i am analizing is an identity column.
Thank you
You can check the sys.columns
view:
SELECT
name, is_identity
FROM sys.columns
WHERE name = 'YourColumnName' AND object_id = OBJECT_ID('dbo.YourTableName')
If you need the type of the column, you need to join to sys.types
:
SELECT
ColumnName = c.name ,
c.is_identity,
TypeName = ty.name
FROM sys.columns c
INNER JOIN sys.types ty ON ty.system_type_id = c.system_type_id
WHERE name = 'YourColumnName' AND object_id = OBJECT_ID('dbo.YourTableName')
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments