Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

not null default value set automatically

Status
Not open for further replies.

fwonny

Programmer
Jul 9, 2003
6
US
Here's my problem:

Create table my_table ( ... locationid int not null);

When I execute the above, mysql automatically assigns a default value of 0. therefore, locationid can never be null!

What is going on?
 
Take this example:

CREATE TABLE information (
id int(11) NOT NULL,
info text NULL
);

That's an overly basic table structure, but should give you the idea. The above tells the field id that it can never be null, and therefore mysql assigns the default to 0. In your example, you told the field to never be null, so if you want to allow null, you have to tell the field that it can be null. I hope that made sense. :/

----------------------------
"Security is like an onion" - Unknown
 
I thought the whole point of "not null" is to prevent records from being inserted w/o missing key information. The default is to allow nulls to be inserted into the record. I'm looking for the opposite effect.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top