SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: create table...

  1. #1
    SitePoint Enthusiast ErikN's Avatar
    Join Date
    Jul 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    create table...

    I'm trying to create a script that will make a table with an id that auto increments, here's what i've got, but it seems to be broke...

    PHP Code:
    $sql2 "CREATE TABLE ns_names PRIMARY KEY(id)(
       name VARCHAR (50),
       email VARCHAR (50),
       timestamp TIMESTAMP,
       id INTEGER NOT NULL AUTO_INCREMENT
    );"

    I'm trying to make 'id' primary, not null, and auto_incrementing, but it won't work...any idea on how to fix this?

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PRIMARY KEY needs to be inside the create statement. preferrably on the same lin as the id definition.

    PHP Code:
    $sql2 "CREATE TABLE ns_names (
             name VARCHAR(50),
             email VARCHAR(50),
             timestamp TIMESTAMP,
             id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY
    )"

    Although I think this will work also.

    PHP Code:
    $sql2 "CREATE TABLE ns_names (
             name VARCHAR(50),
             email VARCHAR(50),
             timestamp TIMESTAMP,
             id INT(11) UNSIGNED NOT NULL AUTO_INCREMENT,
             PRIMARY KEY(id)
    )"

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Enthusiast ErikN's Avatar
    Join Date
    Jul 2001
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works, thanks!


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
  •