I am working on building a site for listing garage sales.
Below is the initial DB schema I have come up with and I'd
like a critique. If you see anything that could be improved
upon, I'd appreciate any comments.
#
# Table structure for table 'alerts'
#
# This table allows even people that are not members of the
# site to receive alerts of upcoming sales in their zip code
#
#
CREATE TABLE alerts (
alert_key bigint(3) unsigned NOT NULL auto_increment,
email varchar(45) NOT NULL DEFAULT '' ,
zip varchar(9) NOT NULL DEFAULT '' ,
PRIMARY KEY (alert_key),
INDEX alert_key (alert_key)
);
#
# Table structure for table 'category'
#
# This table holds the categories that sales can be listed under.
# Sample categories:
# Furniture, Garden/Outdoor, Hardware, Clothing/Accessories, Homewares,
# Computers/Software, Mechanical, Electrical, Miscellaneous, White Goods
#
# This allows users to search for particular things they want to buy.
#
# This is strictly a lookup table modified only by the administrator.
CREATE TABLE category (
category_key bigint(3) unsigned NOT NULL auto_increment,
category_description varchar(40) NOT NULL DEFAULT '' ,
category_date_created date NOT NULL DEFAULT '0000-00-00' ,
PRIMARY KEY (category_key),
INDEX category_key (category_key)
);
#
# Table structure for table 'comment'
#
# This table allows the user to enter comments about the
# particular sale, comments must be accompanied by a name.
# If user is logged in member, it will default to their name,
# and not be editable, if not logged i, will default to Guest.
#
CREATE TABLE comment (
comment_key bigint(3) unsigned NOT NULL auto_increment,
sale_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
comment text NOT NULL DEFAULT '' ,
name varchar(50) NOT NULL DEFAULT '' ,
comment_date date NOT NULL DEFAULT '0000-00-00' ,
PRIMARY KEY (comment_key),
INDEX comemnt_key (comment_key)
);
#
# Table structure for table 'sales'
#
# This table shows detail about a particular sale.
#
CREATE TABLE sales (
sale_key bigint(3) unsigned NOT NULL auto_increment,
user_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
status tinyint(3) unsigned ,
address varchar(65) NOT NULL DEFAULT '' ,
city varchar(40) NOT NULL DEFAULT '' ,
state char(2) NOT NULL DEFAULT '' ,
zip varchar(9) NOT NULL DEFAULT '' ,
phone varchar(10) ,
start datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
end datetime NOT NULL DEFAULT '0000-00-00 00:00:00' ,
description text NOT NULL DEFAULT '' ,
early_birds text ,
category_key bigint(3) NOT NULL DEFAULT '0' ,
date_created date NOT NULL DEFAULT '0000-00-00' ,
featured_items text ,
viewed bigint(3) unsigned ,
map_image varchar(255),
PRIMARY KEY (sale_key),
INDEX sale_key (sale_key)
);
#
# Table structure for table 'sales_images'
#
# This table stores paths for images to items contained
# in a sale.
#
CREATE TABLE sales_images (
sales_images_key bigint(3) unsigned NOT NULL DEFAULT auto_increment ,
sales_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
image_path varchar(255) NOT NULL DEFAULT '' ,
PRIMARY KEY (sales_images_key)
);
#
# Table structure for table 'sales_category'
#
# This table holds category keys that belong to a particular
# sale.
#
CREATE TABLE sales_category (
sales_category_key bigint(3) unsigned NOT NULL auto_increment,
sales_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
category_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
PRIMARY KEY (sales_category_key),
INDEX sales_category_key (sales_category_key,sales_key)
);
#
# Table structure for table 'user'
#
# This table holds detail about a particular registered user.
#
#
CREATE TABLE user (
user_key bigint(3) unsigned NOT NULL auto_increment,
user__lastname varchar(30) NOT NULL DEFAULT '' ,
user_firstname varchar(30) NOT NULL DEFAULT '' ,
user_email varchar(45) NOT NULL DEFAULT '' ,
user_alerts_key bigint(3) unsigned ,
date_created date NOT NULL DEFAULT '0000-00-00' ,
PRIMARY KEY (user_key),
INDEX user_key (user_key)
);
#
# Table structure for table 'user_alerts'
#
# This table stores the user's alerts.
#
CREATE TABLE user_alerts (
user_alerts_key bigint(3) unsigned NOT NULL auto_increment,
user_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
alert_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
PRIMARY KEY (user_alerts_key),
INDEX user_alerts_key (user_alerts_key)
);
#
# Table structure for table 'user_favorites'
#
# Users are allowed to select favorite sales to view in a favorites
# area.
#
CREATE TABLE user_favorites (
user_favorites_key bigint(3) unsigned NOT NULL auto_increment,
user_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
sale_key bigint(3) unsigned NOT NULL DEFAULT '0' ,
PRIMARY KEY (user_favorites_key),
INDEX favorites_key (user_favorites_key)
);