|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
PKey association w/tableHi:
Given that the name of a PKey has been identified, how can one tell which table that PKey is associated to? Any ideas. Thanks. DECLARE @pkeyname SYSNAME
SET @pkeyname = 'your_primary_key_name' SELECT T.TABLE_NAME, T.CONSTRAINT_NAME, K.COLUMN_NAME, K.ORDINAL_POSITION FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS T INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE K ON T.CONSTRAINT_NAME = K.CONSTRAINT_NAME WHERE T.CONSTRAINT_TYPE = 'PRIMARY KEY' AND K.CONSTRAINT_NAME = @pkeyname ORDER BY T.TABLE_NAME, K.ORDINAL_POSITION Show quote "Rob" <R**@discussions.microsoft.com> wrote in message news:00E17BBC-52FB-40D1-94C3-03F0E9183FCC@microsoft.com... > Hi: > > Given that the name of a PKey has been identified, how can one tell which > table that PKey is associated to? Any ideas. Thanks. Rob, try:
select table_schema, table_name from information_schema.table_constraints where constraint_schema = 'dbo' and constraint_name = 'pk_t1' Show quote "Rob" <R**@discussions.microsoft.com> wrote in message news:00E17BBC-52FB-40D1-94C3-03F0E9183FCC@microsoft.com... > Hi: > > Given that the name of a PKey has been identified, how can one tell which > table that PKey is associated to? Any ideas. Thanks. The other answers are valid and good, but, pray tell, where did you identify
this PKey? A column without the context of a table is just the definition of a scalar (or vector) value? One rarely stumbles upon such things :) -- Show quote---------------------------------------------------------------------------- Louis Davidson - http://spaces.msn.com/members/drsql/ SQL Server MVP "Rob" <R**@discussions.microsoft.com> wrote in message news:00E17BBC-52FB-40D1-94C3-03F0E9183FCC@microsoft.com... > Hi: > > Given that the name of a PKey has been identified, how can one tell which > table that PKey is associated to? Any ideas. Thanks. |
|||||||||||||||||||||||