SQL Server 2008 Books Online (November 2009)
KEY_COLUMN_USAGE (Transact-SQL)

Returns one row for each column that is constrained as a key in the current database. This information schema view returns information about the objects to which the current user has permissions.

To retrieve information from these views, specify the fully qualified name of INFORMATION_SCHEMA.view_name.

Column name Data type Description

CONSTRAINT_CATALOG

nvarchar(128)

Constraint qualifier.

CONSTRAINT_SCHEMA

nvarchar(128)

Name of schema that contains the constraint.

ms189789.note(en-us,SQL.100).gifImportant:
Do not use INFORMATION_SCHEMA views to determine the schema of an object. The only reliable way to find the schema of an object is to query the sys.objects catalog view or the OBJECT_SCHEMA_NAME function.

CONSTRAINT_NAME

nvarchar(128)

Constraint name.

TABLE_CATALOG

nvarchar(128)

Table qualifier.

TABLE_SCHEMA

nvarchar(128)

Name of schema that contains the table.

ms189789.note(en-us,SQL.100).gifImportant:
Do not use INFORMATION_SCHEMA views to determine the schema of an object. The only reliable way to find the schema of an object is to query the sys.objects catalog view or the OBJECT_SCHEMA_NAME function.

TABLE_NAME

nvarchar(128)

Table name.

COLUMN_NAME

nvarchar(128)

Column name.

ORDINAL_POSITION

int

Column ordinal position.

Examples

The following example returns information about each column that is defined as a key column in a constraint.

USE AdventureWorks;
GO

SELECT CONSTRAINT_SCHEMA, CONSTRAINT_NAME, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME 
FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE
ORDER BY TABLE_SCHEMA, TABLE_NAME;
See Also

Reference

System Views (Transact-SQL)
Information Schema Views (Transact-SQL)
sys.columns (Transact-SQL)
sys.indexes (Transact-SQL)
sys.objects (Transact-SQL)
sys.foreign_keys (Transact-SQL)
sys.key_constraints (Transact-SQL)
OBJECT_SCHEMA_NAME (Transact-SQL)

Other Resources

Querying the SQL Server System Catalog

Help and Information

Getting SQL Server 2008 Assistance
Tags :


Page view tracker