Does anyone know how I can see which are the primary & foreign keys in a table?
EDIT: Thanks for all the responses. I was looking for a SQL Query to do that. Right now I'm playing around with writing a tool which can list me all Tables of a DB and show the columns. I'd like to display also which of the keys are primary keys.
This is how I read out the Table Catalog:
const string sqlSelectTable = "SELECT TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, TABLE_TYPE " +
"FROM INFORMATION_SCHEMA.TABLES " +
"WHERE TABLE_TYPE = 'BASE TABLE' " +
"ORDER BY TABLE_TYPE,TABLE_NAME";
And this is how I get the Infos about a Column:
const string sqlSelectTable =
"SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH " +
"FROM INFORMATION_SCHEMA.COLUMNS " +
"WHERE (TABLE_NAME = @TABLE_NAME) " +
"ORDER BY ORDINAL_POSITION";
Would I have to create a Inner-Join so see which of the Columns are Primary Key?
Cheers