Column definitions
- SQL course
- Beginner
- Lesson 90/115
- 4 min
Learn to give a column name and type.
PRIMARY KEY
With PRIMARY KEY you make a column the primary key. Its value is unique and cannot be null.
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100)
);Id is the primary key; unique and not null.
The table products is created.
PRIMARY KEY — details
Each table has at most one primary key. It creates an index automatically. It is usually given to the id column.
Practice PRIMARY KEY
Create customers with id INT PRIMARY KEY and name VARCHAR(100).
Starter code
-- create table
CREATE TABLE customersSample solution
CREATE TABLE customers (
id INT PRIMARY KEY,
name VARCHAR(100)
)Expected output
Tablo oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Primary key
CREATE TABLE products (
id INT ____,
name VARCHAR(100)
);
CREATE TABLE products (
id INT PRIMARY KEY,
name VARCHAR(100)
);
Explanation: PRIMARY KEY is the right answer.
2 Which two properties does a PRIMARY KEY have?
- Unique and not null Correct answer
- Empty and repeated
- Numbers only
- Text only
Explanation: PRIMARY KEY is unique and NOT NULL.
3 Column definitions: match the terms
| Term | Meaning |
|---|---|
PRIMARY KEY |
primary |
UNIQUE |
unique |
NOT NULL |
not null |
INT |
integer |