Skip to content

Lecture 29 – Mini-Project: Populating the Blog

  • by
  • 3 min read
Lecture 29 Mini Project Populating the Blog

This lecture covers populating the blog database with sample data.Our blog database structure is built, but it’s an empty shell. To make things interesting, we need to fill it with some realistic sample data. We will use the INSERT INTO command for this.

Again, the order is important. We must insert data into the parent tables before we can insert data into the child tables that reference them.

Step 1: Insert Authors

Let’s add two authors to our `Authors` table. We will assume their auto-incremented `AuthorID`s will be 1 and 2.

INSERT INTO Authors (AuthorName, Email) VALUES ('Alice Wonder', 'alice@email.com');
INSERT INTO Authors (AuthorName, Email) VALUES ('Bob Builder', 'bob@email.com');
Lecture 29 Mini Project Populating the Blog
Lecture 29 Mini Project Populating the Blog

Step 2: Insert Posts

Now we can add some posts. We need to reference the `AuthorID` for each post. Let’s say Alice (ID 1) writes two posts, and Bob (ID 2) writes one.

-- Alice's Posts (Author_ID = 1)
INSERT INTO Posts (Title, Content, PublishDate, Author_ID) 
VALUES ('Learning SQL', 'SQL is a powerful language...', '2025-07-20', 1);

INSERT INTO Posts (Title, Content, PublishDate, Author_ID) 
VALUES ('Database Design Basics', 'Good design is crucial...', '2025-07-22', 1);

-- Bob's Post (Author_ID = 2)
INSERT INTO Posts (Title, Content, PublishDate, Author_ID) 
VALUES ('Fun with Joins', 'Joins are used to combine tables...', '2025-07-25', 2);
Lecture 29 Mini Project Populating the Blog
Lecture 29 Mini Project Populating the Blog

Step 3: Insert Comments

Finally, let’s add some comments on these posts. We’ll assume the `PostID`s are 1, 2, and 3 respectively.

-- Comments for the first post (Post_ID = 1)
INSERT INTO Comments (CommenterName, CommentContent, CommentDate, Post_ID) 
VALUES ('Charlie', 'Great article, thanks!', '2025-07-21', 1);

INSERT INTO Comments (CommenterName, CommentContent, CommentDate, Post_ID) 
VALUES ('David', 'Very helpful, I learned a lot.', '2025-07-21', 1);

-- Comment for the third post (Post_ID = 3)
INSERT INTO Comments (CommenterName, CommentContent, CommentDate, Post_ID) 
VALUES ('Alice', 'Nice explanation of joins!', '2025-07-26', 3);
Lecture 29 Mini Project Populating the Blog
Lecture 29 Mini Project Populating the Blog

Notice that the second post has no comments yet, and Alice, an author, can also be a commenter.

Our Data is Ready

We now have a small but complete set of data that realistically models a blog. We have authors, posts they’ve written, and comments on those posts.

In the Next Lecture…

This is where the fun begins. We will use our populated database to answer interesting questions by writing queries that join our three tables together. We will find out which author wrote which post, list all comments for a specific article, and more.

Lecture 28: Mini-Project – Creating the Blog Tables

Najeeb Alam

Najeeb Alam

Technical writer specializes in developer, Blogging and Online Journalism. I have been working in this field for the last 20 years.