SQL SMO Fast way to get primary key column from a table
-
Does anyone know a fast way of getting the primary key column of a table using SQL SMO? My aproach so far has been to run through all of the columns checking to see if they are primary key columns...
Apparently it's not OK to start a bonfire of Microsoft products in the aisles of CompUSA even though the Linuxrulz web site says so
-
Does anyone know a fast way of getting the primary key column of a table using SQL SMO? My aproach so far has been to run through all of the columns checking to see if they are primary key columns...
Apparently it's not OK to start a bonfire of Microsoft products in the aisles of CompUSA even though the Linuxrulz web site says so
-
tbl.Indexes(0).Name seems to give me the constraint name...but i need to column name, sorry if i missed it, but i didnt see it in your code. Thanks for the quick response :)
Apparently it's not OK to start a bonfire of Microsoft products in the aisles of CompUSA even though the Linuxrulz web site says so
-
Does anyone know a fast way of getting the primary key column of a table using SQL SMO? My aproach so far has been to run through all of the columns checking to see if they are primary key columns...
Apparently it's not OK to start a bonfire of Microsoft products in the aisles of CompUSA even though the Linuxrulz web site says so
-
As far as I can remember you'd have to loop and check. Is the problem that doign the loop and check is very slow? If so check out the 'SetDefaultInitFields' method.
The fastest way i have found so far is by extending your idea slightly:
If tbl.Indexes.Count > 0 Then If tbl.Indexes(0).IndexedColumns.Count > 0 Then Return tbl.Indexes(0).IndexedColumns(0).Name End If End If
Apparently it's not OK to start a bonfire of Microsoft products in the aisles of CompUSA even though the Linuxrulz web site says so