Need a complete analysis on this 6 mysql tables

Discussion in 'PHP' started by digitalpointnet, Mar 22, 2011.

  1. #1
    I am developing this restaurant site, and have come up with a table structure. I feel that there are mistakes in this table structure and the sql written for the mysql database.

    Question 1
    I find that when i run this code at as whole(by copy pasting the complete code to phpmyadmin) it shows an error.

    But when i create tables one by one , i can create all 6 tables.

    I couldn't find the reason for this

    Question 2

    Why can't i write

    restaurant_email VARCHAR - (Won't work for me)

    instead of

    restaurant_email VARCHAR( 80 ) -(Works for me)


    This is the sql i have written
    
    -- Database: db_restaurants
    CREATE DATABASE db_restaurants;
    
    ----------------------------------------------------------
    
    --
    -- Table structure for table `tbl_users`
    --
    
    CREATE TABLE tbl_users (
      user_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
      firstname VARCHAR(30) NOT NULL,
      lastname VARCHAR(30) NOT NULL,
      email VARCHAR(80) NOT NULL,
      pass VARCHAR(30) NOT NULL,
      gender ENUM('Male','Female') NOT NULL,
      PRIMARY KEY(user_id)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    
    
    --------------------------------------------------------
    --
    -- Table structure for table `tbl_restaurants`
    --
    CREATE TABLE tbl_restaurants (
      restaurant_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
      restaurant_name VARCHAR(50) NOT NULL,
      location VARCHAR(30) NOT NULL,
      cousin VARCHAR(30) NOT NULL,		
      price_range ENUM('very low','low','medium','high','very high') NOT NULL,
      address VARCHAR(150) NOT NULL,
      phone SMALLINT UNSIGNED,
      fax SMALLINT UNSIGNED,
      restaurant_email VARCHAR(80),
      open_hours VARCHAR(100),
      website VARCHAR(50),
      vision VARCHAR(300),
      mission VARCHAR(300),
      history VARCHAR(10000),
      faq VARCHAR(50000),
      PRIMARY KEY(restaurant_id)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    
    --------------------------------------------------------
    --
    -- Table structure for table `tbl_menuitems`
    --
    CREATE TABLE tbl_menuitems (
      menu_item_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
      menu_heading_id MEDIUMINT UNSIGNED NOT NULL,
      restaurant_id SMALLINT UNSIGNED NOT NULL,
      menu_item VARCHAR(100), 
      small_price SMALLINT UNSIGNED,
      medium_price SMALLINT UNSIGNED,
      large_price SMALLINT UNSIGNED,
      PRIMARY KEY(menu_item_id)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
     
    --------------------------------------------------------
    --
    -- Table structure for table `tbl_menuheading`
    -- 
    CREATE TABLE tbl_menuheadings (
      menu_heading_id MEDIUMINT UNSIGNED NOT NULL,
      menu_heading VARCHAR(100),
      menu_description VARCHAR(1000),
      PRIMARY KEY(menu_heading_id)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    --------------------------------------------------------
    --
    -- Table structure for table `tbl_reviews`
    --
    CREATE TABLE tbl_reviews(
      review_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
      restaurant_id SMALLINT UNSIGNED NOT NULL,
      user_id SMALLINT UNSIGNED NOT NULL,
      review_title VARCHAR(150) NOT NULL,
      review VARCHAR(1000),
      food FLOAT NOT NULL,
      service FLOAT NOT NULL,
      valu FLOAT NOT NULL,
      atmosphere FLOAT NOT NULL,
      overall_rating FLOAT NOT NULL,
      PRIMARY KEY(review_id)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    
    --------------------------------------------------------
    --
    -- Table structure for table `tbl_gallery`
    --
    CREATE TABLE tbl_gallery(
      gallery_id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT,
      restaurant_id SMALLINT UNSIGNED NOT NULL, 
      gallery_image VARCHAR(45),
      PRIMARY KEY(gallery_id)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    
    
    Code (markup):

    All suggestions to improve this code are welcome

    This should be posted on the mysql section. I am sorry for that.

    "Administrator or moderators" - Please delete this post, since i have included the same post in the mysql section
    Again sorry for the mistake.
     
    Last edited: Mar 23, 2011
    digitalpointnet, Mar 22, 2011 IP