title: How to alter length of varchar in composite primary key?
body: <p>In MSSQL I have a table created like this:</p>
  
  <pre><code>CREATE TABLE [mytable] (fkid int NOT NULL, data varchar(255) CONSTRAINT DF_mytable_data DEFAULT '' NOT NULL);
  ALTER TABLE [mytable] ADD CONSTRAINT PK_mytable_data PRIMARY KEY (fkid, data);
  </code></pre>
  
  <p>Now I want to increase the length of the 'data' column from 255 to 4000. </p>
  
  <p>If I just try:</p>
  
  <pre><code>ALTER TABLE [mytable] ALTER COLUMN data varchar(4000);
  </code></pre>
  
  <p>Then I get this error:</p>
  
  <pre><code>The object 'PK_mytable_data' is dependent on the column 'data'
  </code></pre>
  
  <p>If I try this:</p>
  
  <pre><code>ALTER TABLE [mytable] DROP CONSTRAINT PK_mytable_data;
  ALTER TABLE [mytable] ALTER COLUMN data varchar(4000);
  ALTER TABLE [mytable] ADD CONSTRAINT PK_mytable_data PRIMARY KEY (fkid, data);
  </code></pre>
  
  <p>Then I get this error:</p>
  
  <pre><code>Cannot define PRIMARY KEY constraint on nullable column in table 'mytable'
  </code></pre>
  
  <p>What am I missing? Both columns were defined with NOT NULL, so why is MSSQL reporting that it can't recreate this constraint after I drop it?</p>
  
  <p>Thanks!
  Evan</p>