SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: MySQL / Null values
-
May 9, 2002, 14:14 #1
- 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
-
May 9, 2002, 15:08 #2
- 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
-
May 9, 2002, 16:48 #3
- 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.
Matt - Sybase DBA / PHP fanatic
Sybase/MySQL/Oracle | I don't like MySQL
Download Sybase | DBForums.com - for all your RDBMS talk
Bookmarks