CREATE DATABASE myblog
posts
table:CREATE TABLE `myblog`.`posts` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `title` VARCHAR( 255 ) NOT NULL , `content` TEXT NOT NULL , `author_id` INT UNSIGNED NOT NULL , `publish_date` DATETIME NOT NULL ) ENGINE = MYISAM;
authors
table:CREATE TABLE `myblog`.`authors` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 50 ) NOT NULL ) ENGINE = MYISAM;
categories
table:CREATE TABLE `myblog`.`categories` ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `name` VARCHAR( 50 ) NOT NULL ) ENGINE = MYISAM;
posts_categories
table:CREATE TABLE `myblog`.`posts_categories` ( `post_id` INT UNSIGNED NOT NULL , `category_id` INT UNSIGNED NOT NULL , PRIMARY KEY ( `post_id` , `category_id` ) ) ENGINE = MYISAM;
We created a database to hold the tables needed for our blog application. We then created the following tables:
posts:
Table to store the actual post's content.authors:
Table to store the author's names. Each post belongs to one author and an author can have many posts.categories:
Table to store the category names. Each post can belong to multiple categories and each category can have multiple posts.posts_categories:
Table to store the relationship between posts
and categories
.