Page 1 of 1

SQL Question regarding not null defaults.

Posted: Fri Dec 17, 2004 5:00 am
by mmc01ms
Hey gang, I was inserting a customer into my database from my form and the final two values nfor the validated and rank coloumn i entred as null, this caused problems stating that i couldn't do this. However in my script i have a default value for if a null is entered. my sql script is below.

Code: Select all

create table customers
(customer_id int(6) not null auto_increment primary key,
first_name varchar(20) not null default'',
surname varchar(20) not null default'',
initial varchar(4) not null default'',
address_line_one varchar(25) not null default'',
address_line_two varchar(25) not null default'',
city varchar(15) not null default'',
county varchar(15) default'',
postcode char(8) not null default'',
home_phone_number char(11) not null default'',
mobile_number char(11) not null default'',
email varchar(40) not null default'',
date_of_birth date not null default'0000-00-00',
username varchar(50) not null default '',
password varchar(20) not null default'',
validated int(1) not null default '0',
rank int(1) not null default '1');
any ideas guys?

Posted: Fri Dec 17, 2004 5:06 am
by kettle_drum
null is different to 0, the last two fields in your table are of type int - maybe want to change them to tinyint(1) since they will just be 1 or 0. Then make sure you use 1 or 0 instead of null.