SitePoint Sponsor

User Tag List

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

    Unhappy Help with creating database

    Hi,

    I need help to create my first database. Here is the code that i type in..

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

    So any error here? Everytime i click on enter i will get a error message. Can someone guide me..

  2. #2
    SitePoint Addict ThomasAesir's Avatar
    Join Date
    May 2002
    Location
    Sydney, Australia
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What kind of database are you using?
    Thomas Oeser - Blueprint Software
    Web Scripting Editor v 5.2 One cool Web editing tool.
    3dcomputergraphics.com Coming Soon!

  3. #3
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by ThomasAesir
    What kind of database are you using?
    I'm using mysql.

  4. #4
    Sports Publisher mjames's Avatar
    Join Date
    Jan 2000
    Location
    Charlotte, NC
    Posts
    5,891
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Moved to appropriate forum...

  5. #5
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Can we see the exact syntax you entered. What you posted looks like basic syntax, but it's not valid format as is.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  6. #6
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just this.
    This is the basic syntax that i follow the book that sitepoint is selling.

  7. #7
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Syntax like this will not work in MySQL:
    Code:
    CREATE TABLE table_name ( 
    column_1_name column_1_type column_1_details, 
    column_2_name column_2_type column_2_details, 
    ... 
    );
    You can't use syntax like that. All that is showing is basic syntax format for the create table. Create table syntax SHOULD look more like this:
    Code:
    CREATE TABLE MyTable(t_id INT (11) DEFAULT '' NOT NULL auto_increment, 
                         t_status SMALLINT(6) DEFAULT '1' NOT NULL, 
                         t_name VARCHAR(100) DEFAULT '', 
                         PRIMARY KEY (t_id));
    You would need to specify the column types (INT/SMALLINT/VARCHAR/etc), lengths, null/not null, default, etc....I think you might want to read a little further in the book to get what information you need.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  8. #8
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Dave,

    Don't include the (11), (6), etc. from numeric values if you are not using ZEROFILL. It is useless and a waste of typing.

    Also remember that SMALLINT/INT are NUMBERS and default values should match, e.g. DEFAULT 1, not DEFAULT '1'. For the AUTO_INCREMENT you do not specify a default value.

    DEFAULT '' is the same as no default value (e.g null) so it is extra typing.

    e.g.
    Code:
    CREATE TABLE MyTable(t_id INT NOT NULL AUTO_INCREMENT, 
                         t_status SMALLINT DEFAULT 1 NOT NULL, 
                         t_name VARCHAR(100), 
                         PRIMARY KEY (t_id));

  9. #9
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,265
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    Sorry, MattR. Didn't know since I don't use MySQL. Just used a table declaration segment of code from a piece of software I use. I'll pass on the correction to them.

    Thanks for the info.
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  10. #10
    SitePoint Member
    Join Date
    Jul 2002
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Hmmz...ok thanx for all the help

  11. #11
    Database Jedi MattR's Avatar
    Join Date
    Jan 2001
    Location
    buried in the database shell (Washington, DC)
    Posts
    1,107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by DaveMaxwell
    Sorry, MattR. Didn't know since I don't use MySQL. Just used a table declaration segment of code from a piece of software I use. I'll pass on the correction to them.

    Thanks for the info.
    No problem -- apologies if I came off a little harsh but there's a ton of bad MySQL code out there. Just doing my little bit to help clean up the streets!


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
  •