Subject Re: Server defaults - what are they?
Author Adam
Barry,

I dont understand what you are asking?

Are you talking about default values for fields or default
configuration parameters such as the items in firebird.conf?

If you mean default field values, then they work something like this.

If you write an insert statement, but do not include that value in the
insert, then Firebird will subsitute in that value.

CREATE TABLE TEST
(
ID INTEGER,
SOMEOTHERFIELD INTEGER DEFAULT 0
);

COMMIT;

-----

INSERT INTO TEST (ID) VALUES (1);

SELECT * FROM TEST WHERE ID=1;

ID SOMEOTHERFIELD
==== ==============
1 0

------

INSERT INTO TEST (ID, SOMEOTHERFIELD) VALUES (2, NULL);

SELECT * FROM TEST WHERE ID=2;

ID SOMEOTHERFIELD
==== ==============
2 <null>

etc

So if you include SOMEOTHERFIELD in the first brackets, then the
default is ignored.

All pretty obvious so far.

The only gotcha I can think of is when adding a new field to the
table, and setting a default value for that field, the default value
is not automatically applied to the historical records.

So

ALTER TABLE TEST ADD YETANOTHERFIELD INTEGER DEFAULT 0;

COMMIT;

SELECT * FROM TEST;

ID SOMEOTHERFIELD YETANOTHERFIELD
==== ============== ===============
1 0 <null>
2 <null> <null>

You may have expected YETANOTHERFIELD to be set to 0.

UPDATE TEST SET YETANOTHERFIELD = 0 WHERE YETANOTHERFIELD IS NULL;

Will do the trick.

Some notes.

You MUST commit between adding the field and running the update.
If you declare YETANOTHERFIELD as NOT NULL, then you will get into the
awkward situation of having not null field full of nulls. (not good).
You will need to fill the field with data straight away or gbak etc
may give you problems.

Adam


--- In firebird-support@yahoogroups.com, "bmckenna6" <bmckenna@o...>
wrote:
>
> It seems that in order to understand various
> application/component/sql requirements and
> behaviors, I need to understand something
> about "server defaults."
>
> However, my references and my searches only
> turn up inferences, rather than explanations.
>
> I can begin to deduce that they refer to
> specific SQL statements when tables and
> fields are created, but I believe I need more.
>
> I also guess that the term "server defaults"
> or "server-side defaults" might mean different
> things in different contexts. Perhaps not.
>
> My context is Firebird.
>
> If anyone can direct me to some explanatory
> material or provide a brief explanation, I'd
> be grateful.
>
> I would have thought the IB6 docs had something
> on this, but I couldn't find anything.
>
> Barry
>