How to know if a column of type int is Identity using ADO.NET GetSchema()?
-
I can't figure it using the data GetSchema() returns. Is there something I don't see? Is there any other way? Thanks! Edit: I'm using SQL Server 2008 and SQLConnection
try linking the sysobjects table to the syscolumns table and find the datatype in the syscolumns table. I'll try to come up with the query later.
-
try linking the sysobjects table to the syscolumns table and find the datatype in the syscolumns table. I'll try to come up with the query later.
Here is some code I found ... Set the @tblName variable to the name of the table you are trying to find the Identity column and you will get the result. Happy Coding :cool:
declare @TblName sysname set @tblName = 'Your table name' -- show identity col name select syscolumns.name from sysobjects inner join syscolumns on sysobjects.id = syscolumns.id where sysobjects.name = @tblName and syscolumns.status = 0x80 -- show identity constraint name select sysobjconstraint.name from sysobjects inner join sysconstraints on sysobjects.id = sysconstraints.id left outer join sysobjects sysobjconstraint on sysconstraints.constid = sysobjconstraint.id where sysobjects.name = @tblName and sysobjconstraint.xtype = 'PK'
-
Here is some code I found ... Set the @tblName variable to the name of the table you are trying to find the Identity column and you will get the result. Happy Coding :cool:
declare @TblName sysname set @tblName = 'Your table name' -- show identity col name select syscolumns.name from sysobjects inner join syscolumns on sysobjects.id = syscolumns.id where sysobjects.name = @tblName and syscolumns.status = 0x80 -- show identity constraint name select sysobjconstraint.name from sysobjects inner join sysconstraints on sysobjects.id = sysconstraints.id left outer join sysobjects sysobjconstraint on sysconstraints.constid = sysobjconstraint.id where sysobjects.name = @tblName and sysobjconstraint.xtype = 'PK'