Add a joint primary key constraint to the table when modifying the table
The add syntax is as follows:
"Alter table table_name
Add constraint pk_nameprimary key (Column name1, Column name2);"
[Example]1] Assume that the reservation information table (Orderinfo), No primary key is created.OrderinfoTableCustomeridAndOrderidSet the two columns to the primary key. The syntax is as follows:
"Alter table orderinfo
Add constraint pk_orderinfoprimary key (customerid,Orderid);"
*In general, when you want to set a primary key constraint for a column in the table when modifying the table, make sure that the values in the columns set to the primary key constraint cannot have duplicates, and ensure that they are non-empty. Otherwise, the primary key constraint is set.
Delete primary key constraints
The statement for deleting a primary key constraint is as follows:
"Alter table table_name
Drop primary key"
[Example]2] Delete the customer information table (Customerinfo. The Code is as follows:
"Alter table customerinfo
Drop primary key"
*Because only one primary key constraint can exist in a table, you can delete the primary key constraint in a table without specifying a primary key name.