drkbl

Firebird 1.5 alter column default value

Feb 23rd, 2021 (edited)
272
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.65 KB | None | 0 0
  1. -- ALTER TABLE ADD TMP_FIELDTOFIX SAMEDATATYPE NEWDEFAULTVALUE [NOT NULL, etc.];
  2.  
  3. UPDATE RDB$RELATION_FIELDS
  4.  SET RDB$DEFAULT_VALUE =
  5.   (
  6.      SELECT Q1.RDB$DEFAULT_VALUE
  7.      FROM RDB$RELATION_FIELDS Q1
  8.      WHERE (Q1.RDB$RELATION_NAME = 'TABLENAME') AND
  9.            (Q1.RDB$FIELD_NAME = 'TMP_FIELDTOFIX')
  10.    ),
  11.    RDB$DEFAULT_SOURCE =
  12.    (
  13.       SELECT Q2.RDB$DEFAULT_SOURCE
  14.       FROM RDB$RELATION_FIELDS Q2
  15.       WHERE (Q2.RDB$RELATION_NAME = 'TABLENAME') AND
  16.             (Q2.RDB$FIELD_NAME = 'TMP_FIELDTOFIX')
  17.    )
  18.  WHERE (RDB$RELATION_NAME = 'TABLENAME') AND
  19.        (RDB$FIELD_NAME = 'FIELDTOFIX')
  20. ;
  21.  
  22. -- ALTER TABLE DROP TMP_FIELDTOFIX;
Add Comment
Please, Sign In to add comment