Error when creating MySQL table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • neogazz
    New Member
    • Apr 2010
    • 55

    #1

    Error when creating MySQL table

    Please see the attached picture. When I try to create my MySQL table using the below commands I get the attached error, why?

    Code:
    mysql> CREATE TABLE grocery_inventory (
    -> id int not null primary key auto_increment,
    -> item_name varchar (50) not null,
    -> item_desc text,
    -> item_price float not null,
    -> curr_qty int not null
    -> );
    I am using Wampserver 2.0.
    Attached Files
    Last edited by Atli; Aug 2 '10, 07:54 AM. Reason: Please use [code] tags when posting code.
  • numberwhun
    Recognized Expert Moderator Specialist
    • May 2007
    • 3467

    #2
    That error is telling you that you have not first selected a database in which to create your new table. First do the following:

    Code:
    use <dbname>;
    where <dbname> is the name of your database. So, if you have a database called kitchen, you would issue the command:

    Code:
    use kitchen;
    Then issue your create table command and it should work. If not and you have a syntax issue, then be sure to check the documentation for the command on the specific version of Mysql that you are using.

    Regards,

    Jeff

    Comment

    • neogazz
      New Member
      • Apr 2010
      • 55

      #3
      Thanks I got it to work. First I created the database 'kitchen', via the phpMyAdmin consol. Then I inserted the below code and it worked:

      Code:
      use kitchen;
      mysql> CREATE TABLE grocery_inventory (
      id int not null primary key auto_increment,
      item_name varchar (50) not null,
      item_desc text,
      item_price float not null,
      curr_qty int not null
      );
      Last edited by Atli; Aug 2 '10, 07:55 AM. Reason: Please use [code] tags when posting code.

      Comment

      Working...