sql - When to write NOT NULL when creating a MySQL table column -


what's difference or benefit of writing "not null" in mysql field creation...

for example if i'm creating table this...

create table if not exists game( id int(11) not null auto_increment, name varchar(128) not null, description varchar(200) not null, primary key(id) ) 

here, id , name has value not null fine. that. but, description optional field so, can blank.

so, in situation, should put not null or not ?

null , blank field not same thing (unless, under circumstances, you're brain-dead dbms coughoraclecough).

null means unknown or not applicable whereas blank field means, well, known , blank.

it depends entirely on how want handle field itself. example, let's consider middle initial of name. if not wish distinguish between 'unknown' , 'does not have one', set column not null , use blank value represent both - ease queries somewhat.

however, if want mail clients without middle names (for whatever bizarre reason) without bothering don't know if have one, need able distinguish between 2 classes.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -