SQL Basic
SQL Advanced
SQL Functions
| SQL Primary Key |
SQL PRIMARY KEY ConstraintThe PRIMARY KEY constraint uniquely identifies each record in a database table. Primary keys must contain unique values. A primary key column cannot contain NULL values. Each table should have a primary key, and each table can have only ONE primary key. SQL PRIMARY KEY Constraint on CREATE TABLEThe following SQL creates a PRIMARY KEY on the "P_Id" column when the "Persons" table is created: MySQL:
SQL Server / Oracle / MS Access:
To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following SQL syntax: MySQL / SQL Server / Oracle / MS Access:
SQL PRIMARY KEY Constraint on ALTER TABLETo create a PRIMARY KEY constraint on the "P_Id" column when the table is already created, use the following SQL: MySQL / SQL Server / Oracle / MS Access:
To allow naming of a PRIMARY KEY constraint, and for defining a PRIMARY KEY constraint on multiple columns, use the following SQL syntax: MySQL / SQL Server / Oracle / MS Access:
Note: If you use the ALTER TABLE statement to add a primary key, the primary key column(s) must already have been declared to not contain NULL values (when the table was first created). To DROP a PRIMARY KEY ConstraintTo drop a PRIMARY KEY constraint, use the following SQL: MySQL:
SQL Server / Oracle / MS Access: ALTER TABLE Persons |
SQL Primary Key