Constraints: not null + default = useless?
Posted in 2000
Topics: General Discussion
Hi: I have a field that I need a "not null" constraint on. I am inserting fields from an old db that didn't have this constraint. So I thinks 'Put a default value, that'll fix it', like so: request_date date default today not null, So inserting a null should cause the default to be put in the field, right? How come I get sql error 391: cannot insert null into a column? How can I do this? Drop the "not null" and then add it after the conversion prog runs? Roger Pilkey rpilkey@hotmail.com Sent via Deja.com http://www.deja.com/ Before you buy.
On Fri, 01 Dec 2000 03:31:50 GMT, roger_pilkey@my-deja.com wrote:
>Hi:
> I have a field that I need a "not null"
>constraint on. I am inserting fields from an old
>db that didn't have this constraint. So I
>thinks 'Put a default value, that'll fix it',
>like so:
>
> request_date date default today not null,
>
>So inserting a null should cause the default to
>be put in the field, right?
Wrong
> How come I get sql error 391: cannot insert null into a column?
Because column is not null
> How can I do this?
DEFAULT means that default value will be inserted in column when the column is
not mentioned in INSERT statement. Example:
create table requests (request_id serial,
request_num integer not null,
request_date date default today not null);
insert into requests(request_id,request_num) values (0,123);
Today's date will be inserted in request_date field.
> Drop the "not null" and then add it after the conversion prog runs?
No
>
>Roger Pilkey
>rpilkey@hotmail.com
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.