Home  »  CodeProgrammingSnippetsTechnologyTools   »   Add Primary Key to Existing Table SQL

Add Primary Key to Existing Table SQL

Posted: March 15, 2022 | by Michael Bright

Code to add a primary key to existing table SQL.

ALTER TABLE table_name ADD PRIMARY KEY ( the_id, the_name, PMID );

Syntax.

ALTER TABLE <Table_Name> DROP CONSTRAINT <constraint_name>;

ALTER TABLE <Table_Name> ADD CONSTRAINT <constraint_name> PRIMARY KEY ( <Column1>, <Column2> )

Live example.

ALTER TABLE table_name ADD PRIMARY KEY ( id );

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.