SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Stevenwulf's Avatar
    Join Date
    May 2002
    Location
    Berkeley
    Posts
    76
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    MySQL / Null values

    Ok, so I'm having trouble creating a column that does not allow null values. Here is what I'm inserting to create the column:

    create table jokes (
    ID int not null auto_increment primary key,
    JokeText text,
    JokeDate date not null);

    So all of the colums get created fine excet ID. When I do:

    describe table:

    ID's default value is "not null" when it should be 0 because I assigned this colmun a not null value. Any ideas what is happening here?

    Thanks

  2. #2
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i assume you mean it says the default value is NULL, not NOT NULL as you said. this is normal for AUTO_INCREMENT columns. NULL is the value you insert to get it to "auto increment." so that's what MySQL shows as the default. you can create a column like this

    id INT UNSIGNED NOT NULL DEFAULT NULL AUTO_INCREMENT

    and it will work since it's AUTO_INCREMENT. however, if you have `DEFAULT NULL' on a normal NOT NULL column, it will cause an error.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  3. #3
    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)
    It is part of the ANSI standard (and Codd's Rules for Relational DBs) that the primary key is always NOT NULL.


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
  •