PRIMARY KEY

SQL PRIMARY KEY Keyword

The PRIMARY KEY constraint uniquely identifies each record in a table. A table can have only one primary key, which may consist of one or multiple columns.

SQL PRIMARY KEY on CREATE TABLE Syntax

SQL

Tutorials dojo strip

SQL PRIMARY KEY on CREATE TABLE Example

This query creates a new table Rooms with room_id as the primary key.

SQL

SQL PRIMARY KEY with Column-Level Declaration Syntax

SQL

SQL PRIMARY KEY with Column-Level Declaration Example

This query creates a Buildings table with building_id set as the primary key.

SQL

SQL PRIMARY KEY on Multiple Columns Syntax

SQL

SQL PRIMARY KEY on Multiple Columns Example

This query creates a LabRooms table with a composite primary key of room_id and floor_no.

SQL

SQL PRIMARY KEY on ALTER TABLE Syntax

SQL

SQL PRIMARY KEY on ALTER TABLE Example

This query adds a primary key to the Rooms table on the room_id column.

SQL

Note: This will not work in TechKubo (SQLite), as SQLite does not support adding a primary key after table creation.

SQL PRIMARY KEY on ALTER TABLE with Constraint Name Syntax

SQL

SQL PRIMARY KEY on ALTER TABLE with Constraint Name Example

SQL

Note: Not supported in TechKubo (SQLite). In SQLite, you cannot add primary keys to an existing table using ALTER TABLE.

SQL DROP PRIMARY KEY Constraint Syntax

SQL

SQL DROP PRIMARY KEY Constraint Example

SQL

Note: This command is not supported in TechKubo (SQLite). You must recreate the table if you want to remove a primary key in SQLite.

SQL PRIMARY KEY Labs

Tutorials dojo strip