Subject | Re: [ib-support] Alter Table, add default value to an existing field (2nd post) |
---|---|
Author | Martijn Tonies |
Post date | 2003-03-20T13:42:41Z |
Hi Hugo,
The only "other" way to do this is directly updating DEFAULT_BLR
in RDB$RELATION_FIELDS. Good luck.
With regards,
Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com
"This is an object-oriented system.
If we change anything, the users object."
The only "other" way to do this is directly updating DEFAULT_BLR
in RDB$RELATION_FIELDS. Good luck.
With regards,
Martijn Tonies
Database Workbench - the developer tool for InterBase & Firebird
Upscene Productions
http://www.upscene.com
"This is an object-oriented system.
If we change anything, the users object."
> I've post this question some days ago, but I don't know if it arrives, soI
> re-post:make:
>
> I want to update the metadata of an existing table, but only adding a
> DEFAULT value for a field that already exists.
> For example, I have:
> CREATE TABLE MYTABLE (
> ID INTEGER NOT NULL PRIMARY KEY,
> DESCRIPTION VARCHAR(40),
> MYFLAG CHAR(1)
> );
> this table is in production, and now I want to convert it to:
>
> CREATE TABLE MYTABLE (
> ID INTEGER NOT NULL PRIMARY KEY,
> DESCRIPTION VARCHAR(40),
> MYFLAG CHAR(1) DEFAULT 'N'
> );
> After reading on SQL documentation about ALTER TABLE syntax, I cannot
> ALTER TABLE MYTABLE ALTER COLUMN MYFLAG DEFAULT 'N';and
> nor
> ALTER TABLE MYTABLE ALTER COLUMN MYFLAG TYPE CHAR(1) DEFAULT 'N';
>
> 1) The only possibility I see is:
> ALTER TABLE MYTABLE
> DROP MYFLAG,
> ADD MYFLAG CHAR(1) DEFAULT 'N';
> but this way I lost the data.
>
> 2) Another trick I have found, to avoid DROPing, is to define a DOMAIN:
> CREATE DOMAIN MYDOMAIN CHAR(1) DEFAULT 'N';
> and then
> ALTER TABLE MYTABLE ALTER COLUMN MYFLAG TYPE MYDOMAIN;
>
> But on both 1) and 2) solutions, I must DROP and recreate all PROCEDUREs
> TRIGGERs with dependencies on MYFLAG.
> And, finally, the question:
> Is there a way to add this default, directly via system tables
> (RDB$RELATION_FIELDS, I suppose)?