Help - Search - Members - Calendar
Full Version: Assigning nothing to "not null" field should generate error
HTMLHelp Forums > Programming > Databases
tleave2000
I thought that if you didn't bother to assign a value to a field that was defined as "NOT NULL" and didn't have a default, that the query would fail. But the following queries on a fresh database work fine in phpmyadmin. When I browse the table contents, the state field is just blank. Any light you might be able to shed on this would be greatly appreciated.

CREATE TABLE Customer
(
CustID BIGINT(20) NOT NULL AUTO_INCREMENT,
Name VARCHAR(50) NOT NULL,
Address VARCHAR(50) NOT NULL,
City VARCHAR(30) NOT NULL,
State CHAR(3) NOT NULL,
Zipcode CHAR(10) NOT NULL,
Phone CHAR(20),
PRIMARY KEY(CustID)
)

INSERT INTO Customer
(Name, Address, City, Zipcode)
VALUES
("John Smith", "123 Oak St.", "Portland", "99999")

Thanks for looking.



tleave2000
Ok so now I think that if a field is set "not null", has no default value specified and you don't bother to enter a value for it when you create a new record, then if it's a string field, mySQL enters the empty string into it. So that's what's happening.


But isn't there some situation where not entering a value for a field does generate an error? Does someone know how this situation can arise? Then I could make it so that you must enter a value for that field. Or is that only possible at the stage of validating a form?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.