Alter table

How do you alter the columns of the table? Think off NULL vs NOT NULL, or Char(1) –> Char(2)

Here are some think i used

 --Update the Default value
ALTER COLUMN tableName
    -- Set the type of the column to Char with a length of 1
    ALTER columnName TYPE Char(1),
    -- Give the column a default value, in this case 'F'
    ALTER columnName SET DEFAULT = 'F'

Before you change from NULL to NOT NULL remember to update the field like this

-- Update the NULL fields to the new DEFAULT value
UPDATE TBLPHONETYPES
     SET DELETED = 'F'
 WHERE DELETED is null;

To change the system-tables is not a good idea in general but for this i made a acception.

-- Change field from NULL to NOT NULL field
UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = 1
 WHERE RDB$FIELD_NAME = 'DELETED' 
           AND RDB$RELATION_NAME = 'TBLPHONETYPES';

-- Change field from NOT NULL to NULL field
UPDATE RDB$RELATION_FIELDS SET RDB$NULL_FLAG = NULL
 WHERE RDB$FIELD_NAME = 'DELETED' 
           AND RDB$RELATION_NAME = 'TBLPHONETYPES';

HTH

Leave a Reply