I need the following tables for my blog application:
There after some thinking I have thought I needed only four tables.
Of course, the posts -> non explanatory. Posts should be categorized and are written by users. The exercise only asked for one user so the users table is almost unnecessary.
The Table Structures are as follows:
categories
CREATE TABLE IF NOT EXISTS `categories` (
`id` int(12) unsigned NOT NULL auto_increment,
`user_id` int(11) unsigned NOT NULL,
`name` varchar(100) NOT NULL,
`description` text,
`category_id` int(12) default ’0′,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 ;
posts
CREATE TABLE IF NOT EXISTS `posts` (
`id` int(12) unsigned NOT NULL auto_increment,
`name` varchar(250) NOT NULL,
`user_id` int(12) NOT NULL,
`intro` text NOT NULL,
`main` text,
`category_id` int(12) NOT NULL,
`status` tinyint(1) default ’0′,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
replies
CREATE TABLE IF NOT EXISTS `replies` (
`id` int(12) unsigned NOT NULL auto_increment,
`post_id` int(12) NOT NULL,
`name` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`website` varchar(100) NOT NULL,
`reply` text,
`status` tinyint(1) default ’0′,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
tags
CREATE TABLE IF NOT EXISTS `tags` (
`id` int(12) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`post_id` int(12) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
users
CREATE TABLE IF NOT EXISTS `users` (
`id` int(12) unsigned NOT NULL auto_increment,
`name` varchar(100) NOT NULL,
`username` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`password` varchar(100) NOT NULL,
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1
So that’s it. Next >> Baking the Models
