SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    unable to add auto_icrement.

    when i type


    $sql = "CREATE TABLE $playerstable (player_id int(10) DEFAULT '0' NOT NULL primary key, name varchar(20) DEFAULT '' NOT NULL, passworddb varchar(10), approved varchar(10) DEFAULT 'no', mail varchar(50), icq varchar(15), aim varchar(40), msn varchar (100), country varchar(40), rating int(10) DEFAULT '1500', games int(10) DEFAULT '0', wins int(10) DEFAULT '0', losses int(10) DEFAULT '0', points int(10) DEFAULT '0', totalwins int(10) DEFAULT '0', totallosses int(10) DEFAULT '0', totalpoints int(10) DEFAULT '0', totalgames int(10) DEFAULT '0', rank int(10) DEFAULT '0', streakwins int(10) DEFAULT '0', streaklosses int(10) DEFAULT '0', ip varchar(100))";

    it works

    but when i add auto_increment near the primary key, it doesn't create the table.
    i am adding the "auto increment" manually, but it's very annoying.

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,246
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    try this --
    Code:
    CREATE TABLE $playerstable 
    ( player_id     integer not null primary key auto_increment
    , name          varchar(20) default '' not null
    , passworddb    varchar(10)
    , approved      varchar(10) default 'no'
    , mail          varchar(50)
    , icq           varchar(15)
    , aim           varchar(40)
    , msn           varchar(100)
    , country       varchar(40)
    , rating        integer default 1500
    , games         integer default 0
    , wins          integer default 0
    , losses        integer default 0
    , points        integer default 0
    , totalwins     integer default 0
    , totallosses   integer default 0
    , totalpoints   integer default 0
    , totalgames    integer default 0
    , rank          integer default 0
    , streakwins    integer default 0
    , streaklosses  integer default 0
    , ip            varchar(100)
    );
    note that a player with an empty string as the user name doesn't make sense -- well, to me, anyway -- and i think passworddb should probably be NOT NULL too
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i don't know will it work from sql console, but when i type the code and run it

    $sql = "CREATE TABLE $playerstable
    ( player_id integer not null primary key auto_increment
    , name varchar(20) default '' not null
    , passworddb varchar(10)
    , approved varchar(10) default 'no'
    , mail varchar(50)
    , icq varchar(15)
    , aim varchar(40)
    , msn varchar(100)
    , country varchar(40)
    , rating integer default 1500
    , games integer default 0
    , wins integer default 0
    , losses integer default 0
    , points integer default 0
    , totalwins integer default 0
    , totallosses integer default 0
    , totalpoints integer default 0
    , totalgames integer default 0
    , rank integer default 0
    , streakwins integer default 0
    , streaklosses integer default 0
    , ip varchar(100)
    )";

    it doesn't create a table.

  4. #4
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,246
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    substitute your desired table name for the php variable $playerstable before running it in mysql
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937
    substitute your desired table name for the php variable $playerstable before running it in mysql

    i did that ofcourse, everything works fine before i add
    auto_increment.
    when i add it, it doesn't create a table any more (after deleting the previous one obviously).

  6. #6
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,246
    Mentioned
    59 Post(s)
    Tagged
    3 Thread(s)
    well, i tested it and it works, so you must be doing something else wrong
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, for some reason it works now.
    just played with it a little, but doesn't seem like something is different.


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
  •