title: Error 3728: is not a constraint
body: <p>I'm trying to alter <em>(not best practice?)</em> a SQL server database's table that was installed by a piece of software.</p>
  
  <p><strong>Goal:</strong>
  <br/>Set a constraint on a column to be a primary key then remove it.</p>
  
  <p><strong>Notes:</strong>
  <br/><code>APPT</code> - Table name
  <br/><code>ApptId</code> - Column that functions as a primary key (but was not set as the primary key by the software)</p>
  
  <p><strong>Question:</strong>
  <br> How to resolve <code>___ is not a constraint.</code> error message?</p>
  
  <p><br>
  The command I'm trying to run (test) is as follows and should enable and disable the <code>ApptId</code> row as the primary key:</p>
  
  <pre><code>-- Set an existing field as the primary key
  ALTER TABLE APPT
  ADD PRIMARY KEY (ApptID)
  
  -- Remove primary key constraint
  ALTER TABLE APPT
  DROP CONSTRAINT ApptID
  </code></pre>
  
  <p>The above command sets the <code>ApptID</code> as the primary key, however when it tries to <strong>drop</strong> it an <strong>error message</strong> is produced:</p>
  
  <pre><code>-- Error 3728: 'ApptID' is not a constraint.
  -- Could not drop constraint. See previous errors.
  </code></pre>
  
  <p>Why is this the case?
  <br /> when I try to view the constraints for that table using:</p>
  
  <pre><code>-- List all constraints for a specific table
  SELECT OBJECT_NAME(OBJECT_ID) AS NameofConstraint,
  OBJECT_NAME(parent_object_id) AS TableName,
  type_desc AS ConstraintType
  FROM sys.objects
  WHERE type_desc LIKE '%CONSTRAINT' AND parent_object_id = OBJECT_ID('APPT')
  </code></pre>
  
  <p>I get:</p>
  
  <pre><code>NameofConstraint           | TableName | ConstraintType
  PK__APPT__EDACF695230515B9 | APPT      | PRIMARY_KEY_CONSTRAINT 
  </code></pre>
  
  <hr>
  
  <p>When I set the <code>ApptId</code> column as the primary key via Sql Management Studio the result looks cleaner (i.e. without random string)</p>
  
  <pre><code>NameofConstraint           | TableName | ConstraintType
  PK_APPT                    | APPT      | PRIMARY_KEY_CONSTRAINT 
  </code></pre>
  
  <p>But this does not resolve my issue when trying to programmatically drop the primary key constraint on the <code>ApptId</code> field.</p>