0 day streak
sql / beginner
Snippet

Ensuring Record Uniqueness with PRIMARY KEY Constraints

A PRIMARY KEY uniquely identifies each record in a database table. It ensures that duplicate identifiers cannot be inserted and that primary key values are never NULL.

snippet.sql
sql
1
2
3
4
5
CREATE TABLE employees (
employee_id INTEGER PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50)
);
Breakdown
1
CREATE TABLE employees (
Initiates the creation of a new table named 'employees'.
2
employee_id INTEGER PRIMARY KEY,
Defines 'employee_id' as an integer and sets it as the unique primary key for table rows.
3
first_name VARCHAR(50),
Creates a column named 'first_name' holding text up to 50 characters.
4
last_name VARCHAR(50)
Creates a column named 'last_name' holding text up to 50 characters.
5
);
Closes the table definition statement.