1 CHANGE_RELATION Changes the definition of the fields and relation-specific constraints that make up a relation. You can add, delete, or change fields and relation-specific constraints in an existing relation. When you execute this statement, Oracle Rdb modifies the named field and relation-specific constraint definition(s) within the relation definition. All the fields that you do not mention remain the same. Example: RDO> CHANGE RELATION EMPLOYEES. cont> DEFINE SALARY. cont> END EMPLOYEES RELATION. RDO> ! RDO> CHANGE RELATION DEPARTMENTS. cont> CHANGE DEPARTMENT_NAME cont> QUERY_NAME FOR DATATRIEVE IS "DEPT". cont> END DEPARTMENTS RELATION. 2 More To change a relation with the CHANGE RELATION statement, you need the Oracle Rdb CHANGE privilege for the relation. When you execute this statement, Oracle Rdb modifies the named field and relation-specific constraint definition(s) within the relation definition. All the fields and constraints that you do not mention remain the same. When you change a relation definition, other users see the revised definition only after they invoke the database the next time. By default, a database can be opened automatically (that is, by any user who invokes the database and executes a data manipulation language statement). If the database was modified so that it must be manually opened, the RMU/OPEN command must be used to open it. You must execute the CHANGE RELATION statement in a read/write transaction. If you issue this statement when there is no active transaction, Oracle Rdb starts a read/write transaction implicitly. Other users are allowed to be attached to the database when you issue the CHANGE RELATION statement. 2 Format (B)0CHANGE RELATION qq> name qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwqwqk x tq> DELETE CONSTRAINT w> constraint-name qwj x x x x x mqqqqqqqq , relation-constraint-def qqqqqqqqqqqqqqqqqj x x mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqq> . qqqk mq> DESCRIPTION IS /* text */ qqqqj x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqk mqqwqqwqq> DEFINE qq> define-clause qqqwq> . qwqj x x tqq> CHANGE qq> change-clause qqqu x x x mqq> DELETE qq> field-name qqqqqqj x x mqqqqqqqqqqqqqqqqqqqqq END qqwqqqqq>qqqqwqq> RELATION qqqqqqq> . mq> name qqj 3 name The name of the relation that you want to modify. 3 constraint-name The name of an existing relation-specific constraint. 3 relation-constraint-def Using the relation-constraint-def clause you can name or specify the type of relation-level constraints to be defined within a specific relation definition. (B)0relation-constraint-def = qwq> CONSTRAINT constraint-name IS qqwqk mqqqqqqqqqqqqqqqqqqqqq UNIQUE qqqqqqw>qqw> unique-field-name qqqwqqwqqqk xmq> PRIMARY KEY qj mqqqqqqqqq , qqqq FOREIGN KEY qw> referencing-field-name qwqk x x x mqqqqqqqqqqqqq , qqqq REFERENCES referenced-relation-nameqqqqqqqkx x x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqjx x x mqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqwqqqqqu x x mw> referenced-field-name wj x x x mqqqqqqqqqq , qqqq USING rse REQUIRE conditional-expr qqqqqqqqj x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq m> CHECK ON qwqq> COMMIT qu mqq> UPDATE qj 4 Arguments Constraint-name must be unique within the database. The constraint name can be referred to in other statements such as DEFINE RELATION, SHOW CONSTRAINT, and START_TRANSACTION. The phrase 'CONSTRAINT constraint-name is' is optional. If you specify the keyword CONSTRAINT, you must also provide a name for the constraint. 3 text A text string that adds a comment. You can apply the description to the entire relation definition using the DESCRIPTION keyword. You can also apply a separate description to each field using the text markers before the DEFINE or CHANGE clause. 3 DEFINE Using the DEFINE option of CHANGE RELATION, you can add a globally defined field to a relation. You can also use a local field name to refer to that global field. You can also define a relation-specific constraint at the field level. (B)0define-clause = qqwqqqqqqqqqqqqqqqwqqqk mq> /* text */ qj x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj mqqwq> global-field-name qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqk tq> local-field-name qq> BASED ON q> global-field-name qj x x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x mwqqqqqqqqqqqqqqqqqwqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk x mqw> dtr-clause qwj mqqw> field-constraint-def qwqqqu x mqqqqqq local-field-name qq> COMPUTED BY q> value-expr qk x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj x mqqqwqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqvq> mqw> dtr-clause qwqj mqqqqqq CONSTRAINT constraint-name IS qqj x lqqqqqqqqqqqqqqqqqq NOT MISSING qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqk tq> UNIQUE qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x tq> PRIMARY KEY qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqu x mw> REFERENCES referenced-relation-name qwqqqqqqqqqqqqqqqqqqqqqqqqwu x x m> referenced-field-name jx x x x x mq> USING rse REQUIRE conditional-expr qqqqqqqqqqqq>qqqqqqqqqqqqqqj x x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq mqq> CHECK ON qwqq> COMMIT qu mqq> UPDATE qj 5 Arguments Constraint-name must be unique within the database. The constraint name can be referred to in other statements such as DEFINE RELATION, SHOW CONSTRAINT, and START_TRANSACTION. The phrase 'CONSTRAINT constraint-name is' is optional. If you specify the keyword CONSTRAINT, you must also provide a name for the constraint. A field constraint definition differs from a relation constraint definition in that you cannot repeat referenced field names. See the "relation-constraint-def" help subtopic of CHANGE_RELATION for more information. 3 CHANGE The CHANGE RELATION statement with the CHANGE option modifies the local attributes of an existing field. Only the attributes you specify in the statement change; all others stay as they are. For more details, see the Arguments. You can change relation-specific constraints using the DELETE CONSTRAINT clause of the CHANGE option. Any constraint to be changed must be first specifically deleted by name and then re- declared. (B)0change-clause = qwqqqqqqqqq>qqqqqqqqwqqqqk mqq> /* text */ qqqj x lqqqqqqqqqq global-field-name qqqqqqqqqqqqqqqqqqq>qqqqqqqqqqqqqqqqqqwqk tqq> local-field-name qqqqqqqqqqqqqqqqqqqq>qqqqqqqqqqqqqqqqqqu x mqq> local-field-name qqqqq> BASED ON global-field-name qqqqqj x lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqwqwqwqqqqqqqqqqqqqqqqqqqq>qqqqqqqqqqqqqqqqqqqqqqwqwq> mw> dtr-clause qwj x tq> DELETE CONSTRAINT qw> constraint-name qwu x mqqqqq field-constraint-def qqqqqqqqqqqqqqqqqqqj x mqqqqqqqqqqqqqqqqqqqqqqqq field-name qqqqwqqq> . mqqqq 8000 MISSING_VALUE IS 0 EDIT_STRING FOR DATATRIEVE "$$$$$$9.99". DEFINE FIELD MONEY DATATYPE TEXT SIZE 8 VALID IF SALARY > 8000 MISSING_VALUE IS 0 EDIT_STRING FOR DATATRIEVE "$$$$$$9.99". CHANGE RELATION EMPLOYEES. DEFINE SALARY. END. CHANGE RELATION EMPLOYEES. CHANGE SALARY BASED ON MONEY. END. This example assumes two fields, SALARY and MONEY, defined globally. They have different data types. o The first CHANGE RELATION statement adds a field to EMPLOYEES using the global SALARY field definition o The second CHANGE RELATION statement uses the BASED ON clause to substitute the MONEY definition for the global SALARY. The local name remains the same, but that name now points to a different global definition. There are now two fields named SALARY in the database, one local and one global. Example 5 A COMPUTED BY field is calculated from another field in the relation: CHANGE RELATION SALARY_HISTORY. DEFINE SS_DEDUCTION COMPUTED BY (SALARY_AMOUNT * 0.0625). END SALARY_HISTORY RELATION. This statement adds a "virtual" field, whose value is computed from other fields. Example 6 The following example deletes a field: CHANGE RELATION COLLEGES. DELETE CONTACT_NAME. END COLLEGES RELATION. This example changes the COLLEGES relation by removing the CONTACT_NAME field from it. A global field is still defined for the database as a whole, and other relations can still refer to it. It may have some other name, if CONTACT_NAME were defined with the BASED ON qualifier. This statement also makes the data associated with that field invisible. Example 7 This example changes the field-level primary key constraint for the field DEPT_CODE to a field-level unique constraint. RDO> CHANGE RELATION JOB_HISTORY cont> DELETE CONSTRAINT JOB_HISTORY_FOREIGN3. cont> END. RDO> CHANGE RELATION DEPARTMENTS cont> DELETE CONSTRAINT DEPARTMENTS_PRIMARY1 cont> CONSTRAINT DEPARTMENTS_UNIQUE UNIQUE DEPARTMENT_CODE. cont> END. The example illustrates how constraints can refer to each other. Before the primary key constraint DEPARTMENTS_PRIMARY1 can be deleted, you must delete the foreign key constraint JOB_HISTORY_ FOREIGN3. Example 8 The following example shows that objects in the database with a dependency on the EMPLOYEES relation must be deleted before the EMPLOYEES relation can be deleted: RDO> START_TRANSACTION READ_WRITE RDO> CHANGE RELATION JOB_HISTORY cont> DELETE CONSTRAINT JOB_HISTORY_FOREIGN1. cont> END. RDO> CHANGE RELATION SALARY_HISTORY cont> DELETE CONSTRAINT SALARY_HISTORY_FOREIGN1. cont> END. RDO> CHANGE RELATION DEGREES cont> DELETE CONSTRAINT DEGREES_FOREIGN1. cont> END. RDO> CHANGE RELATION RESUMES cont> DELETE CONSTRAINT RESUMES_FOREIGN1. cont> END. RDO> CHANGE RELATION RESUMES cont> DELETE CONSTRAINT RESUMES_UNIQUE_EMPLOYEE_ID. cont> END. RDO> DELETE TRIGGER EMPLOYEE_ID_CASCADE_DELETE, STATUS_CODE_CASCADE_UPDATE. RDO> DELETE VIEW CURRENT_INFO, CURRENT_SALARY, CURRENT_JOB. RDO> RDO> DELETE RELATION EMPLOYEES. RDO> ROLLBACK