Subject | Re: why default value is failed? |
---|---|
Author | Adam |
Post date | 2005-10-12T01:32:14Z |
Yang,
Using a simple example
CREATE TABLE test (
id bigint,
somedata integer default 5
);
COMMIT;
Now,
INSERT INTO TEST (ID, SOMEDATA) VALUES (1,1);
Would put a 1 in the somedata field (obviously)
INSERT INTO TEST (ID, SOMEDATA) VALUES (1,null);
Would put a NULL in the somedata field (less obvious)
INSERT INTO TEST (ID) VALUES (1);
Would put the default value of somedata (what you are expecting).
The ONLY time the default value is used is when you run an insert
statement and you do not list the field in the insert statement. It
is not a value that is substituted for NULL.
If you want to do it that way, you could of course use a before
insert trigger, but above is how Firebird implements default.
Adam
--- In firebird-support@yahoogroups.com, Yang Jin <ojinyang@y...>
wrote:
record to the new table.
I insert a record that Field omit,Why the server don't set the
default to Field?
support Microsoft technical support
Using a simple example
CREATE TABLE test (
id bigint,
somedata integer default 5
);
COMMIT;
Now,
INSERT INTO TEST (ID, SOMEDATA) VALUES (1,1);
Would put a 1 in the somedata field (obviously)
INSERT INTO TEST (ID, SOMEDATA) VALUES (1,null);
Would put a NULL in the somedata field (less obvious)
INSERT INTO TEST (ID) VALUES (1);
Would put the default value of somedata (what you are expecting).
The ONLY time the default value is used is when you run an insert
statement and you do not list the field in the insert statement. It
is not a value that is substituted for NULL.
If you want to do it that way, you could of course use a before
insert trigger, but above is how Firebird implements default.
Adam
--- In firebird-support@yahoogroups.com, Yang Jin <ojinyang@y...>
wrote:
>statement to make
> First,thank your reply.
>
> Alan McDonald <alan@m...> дµÀ£º
> >>your application needs to omit the field >>from the insert
> >>the default take effect.which is also
>
> >>Your applicatoin is obviously setting the field >>value to NULL
> >>acceptable by your definition.add the Filed,So I think it is omit the Field.The old app can insert
>
>
> Re:The truth is my app is suit for the old table struct that don't
record to the new table.
>when you tried
>
> >>If you set the field to NOT NULL, you would >>get an exception
> >>to post your data.Field value is null.constriant's error happened.So I think the key is
>
> Re:Ok,I see.But The error happen when I update the record that
I insert a record that Field omit,Why the server don't set the
default to Field?
>think it can been impacted by new server.It's just my personal judge.
>
> >>There is no bug here.
>
> Re:It happened after I update Firebird from 1.03 to 1.5.3.4854,so I
>technical support Compaq technical support Hewlett packard technical
>
> Alan
>
>
>
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> Visit http://firebird.sourceforge.net and click the Resources item
> on the main (top) menu. Try Knowledgebase and FAQ links !
>
> Also search the knowledgebases at http://www.ibphoenix.com
>
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
>
>
>
>
> SPONSORED LINKS
> Technical support Computer technical support Compaq computer
support Microsoft technical support
>Service.
> ---------------------------------
> YAHOO! GROUPS LINKS
>
>
> Visit your group "firebird-support" on the web.
>
> To unsubscribe from this group, send an email to:
> firebird-support-unsubscribe@yahoogroups.com
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of
>
>
> ---------------------------------
>
>
>
>
>
> ---------------------------------
> ÑÅ»¢Ãâ·ÑGÓÊÏä£No.1µÄ·À¶¾·ÀÀ¬»ø³¬´óÓÊÏä
> ÑÅ»¢ÖúÊÖ¡§DËÑË÷¡¢É±¶¾¡¢·ÀɧÈÅ
>
> [Non-text portions of this message have been removed]
>