title: SQL Server: drop table primary key, without knowing its name
body: <p>HI,</p>
  
  <p>Using: SQL Server
  Database: Northwind</p>
  
  <p>I'd like to drop a table primary key, without knowing the PK constraint name..</p>
  
  <p>eg, using the Categories table in the Northwind Sample database, the primary key column is 'CategoryId', and the primary key name is 'PK_Categories'</p>
  
  <p>I can drop the primary key while knowing the primary key name:</p>
  
  <pre><code>ALTER TABLE categories DROP CONSTRAINT PK_Categories;
  </code></pre>
  
  <p>And I can also get the primary key name for the table by table name:</p>
  
  <pre><code>select name from sysobjects where xtype = 'PK' and parent_obj = object_id('categories')
  </code></pre>
  
  <p>However, I cannot put them together to delete a table's primary key, without first knowing the primary key name.  </p>
  
  <p>I am trying:</p>
  
  <pre><code>ALTER TABLE categories DROP CONSTRAINT
  
  
  (select name from sysobjects where xtype = 'PK' and parent_obj = object_id('categories') ) 
  </code></pre>
  
  <p>Can anyone show me where I am going wrong?</p>
  
  <p>Many thanks,</p>
  
  <p>Bob</p>