Showing posts with label PrimaryKey. Show all posts
Showing posts with label PrimaryKey. Show all posts

Tuesday, June 15, 2010

Get name of non-primarykey columns of a table in SQL server

Get all column names of a table that are not primary key.

Select COLUMN_NAME

FROM INFORMATION_SCHEMA.columns

WHERE TABLE_NAME = 'tbl_Name'

AND COLUMN_NAME NOT in

(select c.COLUMN_NAME

from INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk ,

INFORMATION_SCHEMA.KEY_COLUMN_USAGE c

where pk.TABLE_NAME = 'tbl_Name'

and CONSTRAINT_TYPE = 'PRIMARY KEY'

and c.TABLE_NAME = pk.TABLE_NAME

and c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME)

Monday, June 14, 2010

Get name of primarykey columns of a table in SQL server

Get names of all primarykey columns of a table in SQL server.

select c.COLUMN_NAME

from INFORMATION_SCHEMA.TABLE_CONSTRAINTS pk ,

INFORMATION_SCHEMA.KEY_COLUMN_USAGE c

where pk.TABLE_NAME = 'TBL_NAME'

and CONSTRAINT_TYPE = 'PRIMARY KEY'

and c.TABLE_NAME = pk.TABLE_NAME

and c.CONSTRAINT_NAME = pk.CONSTRAINT_NAME