title: How to add new column in table as primary key?
body: <p>I wonder how to add new column ( set as primary key and set default value) in existing table ? I tried </p>
  
  <pre><code>ALTER TABLE table_name ADD ( column_name VARCHAR (10));
  ALTER TABLE table_name  ALTER COLUMN column_name SET DEFAULT 'value1';
  ALTER TABLE table_name ADD PRIMARY KEY(column_name);
  &gt;&gt; ERROR 1138 (22004): Invalid use of NULL value
  </code></pre>
  
  <p>I saw couple posts but it requires to delete all existing data in the table which I don't want to. Is there other way to add new column as primary key without delete data in table?</p>
  
  <p>My current table:</p>
  
  <p><a href="https://i.stack.imgur.com/93y9F.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/93y9F.png" alt="Current table"></a></p>
  
  <p>My new table that I want to create:</p>
  
  <p><a href="https://i.stack.imgur.com/P1GtJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P1GtJ.png" alt="new table"></a></p>
  
  <p>Thanks</p>