Need a complete analysis on this 6 mysql tables

Discussion in 'MySQL' started by digitalpointnet, Mar 23, 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
     
    Last edited: Mar 23, 2011
    digitalpointnet, Mar 23, 2011 IP
  2. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Answer 1) What was the error message

    Answer 2) Because you are required to define a maximum length for the varchar datatype

    Obviously don't know what the site is to do so commenting on its optimisation is difficult, is 255 going to be big enough for the number of restaurants you will ever have? given you have an unsigned smallint as the ID
     
    AstarothSolutions, Mar 24, 2011 IP
  3. digitalpointnet

    digitalpointnet Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Question 1

    This is the error message

    -----

    Error

    SQL query:

    -------------------------------------------------------- --
    --
    -- 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 ,
    X 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;



    MySQL said:
    #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '----------------------------------------------------------

    --
    -- Table struc' at line 1



    Question 2

    Answer accepted

    -------------------
    If i am not mistaken smallint supports up to 65535

    please refer this link
    http://dev.mysql.com/doc/refman/5.0/en/numeric-types.html
     
    Last edited: Mar 24, 2011
    digitalpointnet, Mar 24, 2011 IP
  4. AstarothSolutions

    AstarothSolutions Peon

    Messages:
    2,680
    Likes Received:
    77
    Best Answers:
    0
    Trophy Points:
    0
    #4
    My bad .
     
    AstarothSolutions, Mar 25, 2011 IP
  5. shield

    shield Active Member

    Messages:
    39
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    61
    #5
    -- Database: db_restaurants
    CREATE DATABASE db_restaurants;


    Could this be the reason for the error?
    I mean, if you already have created the database...
     
    shield, Apr 13, 2011 IP