Data update
- SQL course
- Beginner
- Lesson 114/115
- 6 min
Write a calculated UPDATE based on existing data.
Challenge 3: Create a table
In this challenge you will create a table with PRIMARY KEY, NOT NULL and DEFAULT.
CREATE TABLE books (id INT PRIMARY KEY, title VARCHAR(100) NOT NULL, copies INT DEFAULT 1);This query books table; title required, copies default to 1.
The table books is created.
Practice Challenge 3: Create a table
Create books with id INT PRIMARY KEY, title VARCHAR(100) NOT NULL, copies INT DEFAULT 1.
Starter code
-- books table
CREATE TABLE booksSample solution
CREATE TABLE books (
id INT PRIMARY KEY,
title VARCHAR(100) NOT NULL,
copies INT DEFAULT 1
)Expected output
Tablo oluşturuldu
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which marks a column as required?
- NOT NULL Correct answer
- NULL
- EMPTY
- ZERO
Explanation: NOT NULL marks a column as required.
2 Table constraint
CREATE TABLE books (
id INT PRIMARY ____,
title VARCHAR(100) NOT NULL
);
CREATE TABLE books (
id INT PRIMARY KEY,
title VARCHAR(100) NOT NULL
);
Explanation: PRIMARY KEY uniquely identifies each book; leaving out KEY is a syntax error.