CodeBlanks Logo Icon CodeBlanks

Blog design

Set up author, post and tag tables and write skeleton queries.

Blog design

In this project you will build a blog database. First step: create the posts table.

CREATE TABLE posts (
  id INT PRIMARY KEY,
  title VARCHAR(200),
  body TEXT,
  author_id INT
);

Skeleton of the posts table.

The table posts is created.

Blog design — details

TEXT is for long text, VARCHAR for bounded text. author_id will be a foreign key.

The posts table has a VARCHAR for the title, TEXT for the body, author_id to link the author and a status column.

Practice Blog design

Create posts with id, title, body and author_id.

Starter code

query.sql
-- posts table
CREATE TABLE posts

Sample solution

query.sql
CREATE TABLE posts (
  id INT PRIMARY KEY,
  title VARCHAR(200),
  body TEXT,
  author_id INT
)

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 type for long text?

  • DATE
  • TEXT Correct answer
  • INT
  • BOOLEAN

Explanation: TEXT is for long text.

2 Add PRIMARY KEY

Question
CREATE TABLE posts (
  id INT ____,
  title VARCHAR(200)
);
Answer
CREATE TABLE posts (
  id INT PRIMARY KEY,
  title VARCHAR(200)
);

Explanation: PRIMARY KEY is the right answer.

3 Blog design: match the terms

Term Meaning
id primary key
title title
body body
TEXT long text

All lessons in Intermediate