Note: This site is currently "Under construction". I'm migrating to a new version of my site building software. Lots of things are in a state of disrepair as a result (for example, footnote links aren't working). It's all part of the process of building in public. Most things should still be readable though.

Add A Primary Key To An Existing Database Table With SQL

Do this to add a primary key to an existing database table:

Code

ALTER TABLE table_name ADD PRIMARY KEY (column_name)

You can make the primary key with multiple columns as well

Code

ALTER TABLE table_name ADD PRIMARY KEY (column_name_1, column_name_2)