SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2002
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    problem with simple SQL command

    I am new at this.
    I am trying to execute this command:

    CREATE TABLE table_name (
    -> column_1_name column_1_type column_1_details,
    -> column_2_name column_2_type column_2_details,
    -> );

    from a mysql> prompt and am getting the following error:

    ERROR 1064: You have an error in your SQL syntax near 'column_1_type column_1_details,
    column_2_name column_2_type column_2_details' at line 2


    I'm copying the commands directly from a web page and I've looked over the consistancy of the text, but I can't figure it out, obviously.

    Any information would be much appreciated.

    Thanks.

    Rob

  2. #2
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is a real world example:
    Code:
    CREATE TABLE User (
       ID int(11) NOT NULL auto_increment,
       Name varchar(30) NOT NULL,
       Email varchar(200) NOT NULL,
       PRIMARY KEY (ID)
    );
    Here is a link to the mysql manual, with more info on creating tables.

    Hope this gets you going.




    Cheers.

  3. #3
    SitePoint Wizard Aes's Avatar
    Join Date
    Jun 2001
    Location
    Oklahoma
    Posts
    3,392
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That's because that is giving you a layout, not the exact commands. For example, column_1_type can be either varchar(), char(), text, int, blob, date, et cetera. column_1_details can be primary key, not null, unique, et cetera.

    So a general command would be something like:
    Code:
    -> CREATE TABLE table_name (
    -> column_1_name varchar(30) not null primary key,
    -> column_2_name text not null);
    Are you following? Go to the documentation at MySQL.com and you'll be able to easily find the syntax to be used when creating tables.

    -Colin
    Colin Anderson
    Ambition is a poor excuse for those without
    sense enough to be lazy.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •