PRIMARY KEY is a table-level or column-level constraint that uniquely identifies each row in a table. Every table can have only one primary key, although it may be composite (multiple columns). When defined, the database automatically creates an associated unique index to enforce key integrity and speed lookups. All columns that participate must be declared NOT NULL implicitly or explicitly. Primary keys are referenced by foreign keys in other tables to maintain referential integrity. Attempting to insert duplicate or null values in a primary-key column results in an error. While you may drop and recreate a primary key, doing so can invalidate dependent foreign keys until the constraint is restored.
constraint_name
(string) - Optional name assigned to the primary key constraint.column_list
(identifier list) - One or more columns that form the key, separated by commas.UNIQUE, FOREIGN KEY, NOT NULL, INDEX, CONSTRAINT, AUTO INCREMENT
SQL-92
The database rejects the insert or update and raises a unique violation error.
Yes. Drop the existing primary key with ALTER TABLE ... DROP CONSTRAINT, then add a new one. Be sure to update any foreign keys.
In all major databases the primary key implicitly creates a unique index, improving query performance on the key columns.
Not explicitly. Creating a primary key implicitly sets each key column to NOT NULL, but you can also specify it yourself for clarity.