Connecting Tech Pros Worldwide Help | Site Map

NOT NULL problems

pradeepjain's Avatar
Needs Regular Fix
 
Join Date: Jul 2007
Location: India
Posts: 407
#1: Oct 15 '09
i ma creating a table like
Expand|Select|Wrap|Line Numbers
  1. create table mobile_master(id int AUTO_INCREMENT NOT NULL PRIMARY KEY,property1_name varchar(100) NOT NULL,property2_name varchar(100) NOT NULL,property3_name varchar(100) NOT NULL,property4_name varchar(100) NOT NULL,property5_name varchar(100) NULL,property6_name varchar(100) NULL,property7_name varchar(100) NULL,property8_name varchar(100) NULL,property9_name varchar(100) NULL,property10_name varchar(100) NULL,property11_name varchar(100) NULL,property12_name varchar(100) NULL,property13_name varchar(100) NULL,property14_name varchar(100) NULL,property15_name varchar(100) NULL)engine=INNODB;

but when i insert values with property2_name with no value something like this
Expand|Select|Wrap|Line Numbers
  1. insert into mobile_master  (property1_name,property2_name) values ('Brand','Model Number');

query gets accepted ...the NOT NULL factor is not coming into play...
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,078
#2: Oct 15 '09

re: NOT NULL problems


You are not inserting NULL, you are inserting an empty value.
MySql will insert the default value for a field that is NOT NULL,
0 for INT, empty for string
pradeepjain's Avatar
Needs Regular Fix
 
Join Date: Jul 2007
Location: India
Posts: 407
#3: Oct 15 '09

re: NOT NULL problems


is there a way so that i make sure that there is a value in a column ?
code green's Avatar
Expert
 
Join Date: Mar 2007
Location: England
Posts: 1,078
#4: Oct 15 '09

re: NOT NULL problems


Do you mean reject the query if there are missing values?
This is better handled on the front end.

But you could try something weird like, setting the dafault value to NULL yet have the field set to NOT NULL. No idea what would happen then.

Or write a sql function to process the incoming data that so missing data is set to NULL

Can NULLIF() be used with INSERT INTO?
Reply