The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

 
Reply to this topicStart new topic
> Assigning nothing to "not null" field should generate error
tleave2000
post Mar 4 2007, 05:28 PM
Post #1





Group: Members
Posts: 8
Joined: 23-February 07
Member No.: 2,007



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.



User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
tleave2000
post Mar 5 2007, 07:32 PM
Post #2





Group: Members
Posts: 8
Joined: 23-February 07
Member No.: 2,007



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?
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Reply to this topicStart new topic
2 User(s) are reading this topic (2 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 27th April 2024 - 01:47 PM