title: SQL Server 2008: Find out primary/foreign key in Table?
body: <p>Does anyone know how I can see which are the primary &amp; foreign keys in a table?</p>
  
  <p>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.</p>
  
  <p>This is how I read out the Table Catalog:  </p>
  
  <pre><code>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";
  </code></pre>
  
  <p>And this is how I get the Infos about a Column:</p>
  
  <pre><code>const string sqlSelectTable =
              "SELECT     COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH " +
              "FROM         INFORMATION_SCHEMA.COLUMNS " +
              "WHERE     (TABLE_NAME = @TABLE_NAME) " +
              "ORDER BY ORDINAL_POSITION";
  </code></pre>
  
  <p>Would I have to create a Inner-Join so see which of the Columns are Primary Key?</p>
  
  <p>Cheers</p>