home ~ socials ~ projects ~ rss

Add A Primary Key To An Existing Database Table With SQL

August 2021

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

ALTER TABLE table_name ADD PRIMARY KEY (column_name)

You can make the primary key with multiple columns as well

ALTER TABLE table_name ADD PRIMARY KEY (column_name_1, column_name_2)
end of line
Share link:
https://www.alanwsmith.com/en/20/eo/ne/fz/?add-a-primary-key-to-an-existing-database-table-with-sql