Subject Re: [ib-support] NOT NULL constraints and the System Tables
Author ibrahim Bulut
I finished this problem.
This is my table
CREATE TABLE "T1"
(
"T1" INTEGER NOT NULL,
"T2" INTEGER NOT NULL,
PRIMARY KEY ("T1")
);

But T2 field can be null.
Before, you must learn the constraint name.
For that look at the RDB$RELATION_CONSTRAINTS table.
When I look at this table I saw that
RDB$CONSTRAINT_NAME=INTEG_7
RDB$CONSTRAINT_TYPE=NOT NULL
RDB$RELATION_NAME=T1

Drop the not null constraint:
UPDATE RDB$RELATION_FIELDS
SET
RDB$NULL_FLAG=NULL
WHERE
(RDB$FIELD_NAME = 'T2') AND
(RDB$RELATION_NAME='T1');

DELETE FROM RDB$RELATION_CONSTRAINTS
WHERE
(RDB$CONSTRAINT_TYPE = 'NOT NULL') AND
(RDB$RELATION_NAME = 'T1') AND
(RDB$CONSTRAINT_NAME = 'INTEG_7');

Add the contraint For T2 field
UPDATE RDB$RELATION_FIELDS
SET
RDB$NULL_FLAG=1
WHERE
(RDB$FIELD_NAME = 'FIELD_NAME') AND
(RDB$RELATION_NAME='TABLE_NAME')


Bye...






----- Original Message -----
From: "Martijn Tonies" <m.tonies@...>
To: <ib-support@yahoogroups.com>
Sent: Tuesday, November 13, 2001 9:32 PM
Subject: Re: [ib-support] NOT NULL constraints and the System Tables


> Hi,
>
> dropping the constraint touches the RDB$NULL_FLAG column alright. It sets
it to 0.
>
> Good. Now, when I try to insert a NULL, it fails - even after committing.
>
> However, when I re-connect, everything is fine. It seems that upon
connection (or so - can someone shed a light here?) this kind of meta-data
is cached?
>
> Next question: to do the reverse, is setting the RDB$NULL_FLAG to 1 enough
to disallow NULLs? Do I have to create records in the RDB$CHECK_CONSTRAINTS
and RDB$RELATION_CONSTRAINTS tables to be on the safe side? If so, how do I
generate the constraint name?
>
>
> Martijn Tonies
> InterBase Workbench - the developer tool for InterBase and Firebird
> http://www.interbaseworkbench.com
>
> Upscene Productions
> http://www.upscene.com
>
> "This is an object-oriented system.
> If we change anything, the users object."
>
>
>
> The null flag in rdb$relation_fields and rdb$fields predated
> sql and constraints. It can be used alone to disallow nulls.
> To allow nulls, you must remove both the constraint and the
> null flag.
>
>
>
> Regards,
>
> Ann
> www.ibphoenix.com
> We have answers.
>
>
> Yahoo! Groups Sponsor
>
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
>
>
>
> [Non-text portions of this message have been removed]
>
>
>
> To unsubscribe from this group, send an email to:
> ib-support-unsubscribe@egroups.com
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>