Not Null

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Not Null

Post by m2babaey »

Hi
I am not still clear where I should introduce tables feilds Not Null and where not. Can you help me?
thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Basically, you use it on fields you will normally not set initially to make an insertion query smaller and more simple. You have to specify all NOT NULL fields during insertion.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Not Null

Post by califdon »

m2babaey wrote:I am not still clear where I should introduce tables feilds Not Null and where not. Can you help me?
In most situations you should not use NOT NULL unless the field is one that you want to make absolutely certain contains data in every record. A primary key is an obvious example, but also for fields which, if blank, make the data useless, such as LastName in a directory of people. Using it anywhere else raises the potential that at some point you will want to enter a record that has no data in the field (perhaps expecting to fill it in later) and your database will refuse to allow you to enter the record. Believe me, it happens all the time.
Post Reply