Re: Defaults in SE
Posted in 1995
>From: exg9537@cs.rit.edu (Edward X Garbowski)
>Date: Mon, 24 Apr 1995 15:25:35 GMT
>X-Informix-List-Id: <news.13310>
>
>Hey all, I'm trying to create/alter tables so that certain
>columns will have default values. It takes the changes and
>everything, and looks like it should work...but the defaults
>are never used!
>
>Ex: have a column of char(10) with a default of user
> of column of date with default today
>
> none of the defaults work. I've tried other constraints (ie - keys,
> or checks...) and they all work. But not defaults.
>
>For reference, I'm using Informix SE 7.10 and SQL 6.01. I've also
>tried SQL 4.00 (w/ comparible SE) and it still didn't work.
>
>I find it hard to believe that Informix has never had defaults
>working....what's wrong?!
I suspect that you are suffering because you are using SPERFORM rather than
raw SQL statements. The defaults only kick into effect when no value is
specified for the column in the INSERT statement. By default, SPERFORM
provides values for all columns, so the defaults wouldn't take effect.
Try:
CREATE TABLE X
(
Col01 SERIAL NOT NULL PRIMARY KEY,
Col02 INTEGER DEFAULT 10 NOT NULL,
Col03 CHAR(20) NOT NULL
);
INSERT INTO X(Col01, Col03) VALUES(0, "ABC");
SELECT * FROM X;
This certainly works with 6.00 OnLine. Next, generate and run a default
form, adding a row. No DEFAULT is used. Edit a copy of the form to remove
Col02, compile and run it, and add a row. With OnLine, this works and
gives the default in Col02. You can use the original form to verify this.
The defaults only apply to the columns you can't see on the form.
Yours,
Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>