SitePoint Sponsor |
|
User Tag List
Results 1 to 2 of 2
Thread: Null or Default value?
-
Nov 17, 2004, 11:51 #1
- Join Date
- Aug 2001
- Location
- Hattiesburg, MS
- Posts
- 1,085
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Null or Default value?
What's the most optimized way to handle fields that aren't required to be filled in at record creation? NULL or give it a default value
-
Nov 17, 2004, 13:08 #2
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
NULL is better
unless, of course, you know, a default is more appropriate
example of NULL appropriate --Code:create table employees ( id integer not null primary key auto_increment , name varchar(99) not null , hiredate datetime not null , termdate datetime null );
termination date would be NULL until the employee terminates, then it gets a value
a "default" value in termination date makes no sense whatsoever
example of default appropriate --Code:create table users ( id integer not null primary key auto_increment , username varchar(16) not null , password datetime not null , status char(1) default 'U' );
insert into users (username,password) values ('curly','woobwoob')
insert into users (username,password) values ('larry','heyfellas')
insert into users (username,password) values ('moe','whyioughta')
insert into users (username,password,status) values ('superuser','iamgod','S')
Bookmarks