ALTER TABLE...ALTER COLUMN Restrictions¶
ALTER TABLE...ALTER COLUMN is supported for Actian Data Platform tables only for changing the default value or changing the masking.
Rules and Restrictions on Renaming Tables¶
Be aware of the following guidelines and restrictions when renaming tables:
- You must own any table you rename.
-
The name of the new table must conform to the naming rules for tables (see Object Naming Rules).
-
There must be no table already existing in the database having the same name and owned by the same user as the new table name. (The new table name will get the same internal relation ID (reltid) as the old table name.)
-
Indexes, grants, comments, synonyms, sequences are automatically transferred to the newly renamed table or column.
-
The ALTER TABLE or RENAME operation can be rolled back.
-
If any views refer to the table being renamed, the rename operation will fail with errors. Names of dependent objects are included in the error log for each dependent object.
-
Primary key constraints, foreign key constraints, and unique constraints on the table will be transferred to the new table name.
- Any forms, join definitions, or reports that refer to the old table name will be invalidated.
Rules and Restrictions on Renaming Columns¶
Be aware of the following guidelines and restrictions when renaming columns:
- You must own any table containing columns you rename.
-
The name of the new column must conform to the naming rules for columns (see Object Naming Rules).
-
There must be no column already existing in the table having the same name.
-
If any views refer to the table column being renamed, the rename operation will fail with errors.
-
The ALTER TABLE RENAME COLUMN operation can be rolled back.
- Any forms, join definitions, or reports that refer to the old table column name will be invalidated.
Constraint Specifications¶
When a constraint is added to a table, the table is checked to ensure that its contents do not violate the constraint. If the contents of the table do violate the constraint, the Actian Data Platform returns an error and does not add the constraint.
The following table summarizes the elements of the constraint_clause:
| Type | Keyword | Example |
|---|---|---|
| Referential | REFERENCES | ALTER TABLE dept_constADD CONSTRAINT chkmgrFOREIGN KEY(mgr) REFERENCES emp(ename); |
| Unique | UNIQUE | ALTER TABLE emp_constADD UNIQUE (eno, ename); |
| Primary key | PRIMARY KEY | ALTER TABLE emp_constADD CONSTRAINT ekeyPRIMARY KEY(eno); |
For more information, see Constraints.
Named Constraints¶
If the constraint name is omitted, the Actian Data Platform assigns a name.
To assign a name to a constraint on the ALTER TABLE statement, use the following syntax:
The keyword CONSTRAINT must be used only when specifying a name.
For example, the following statement adds a named constraint to the dept table:
The following statement adds an internally named constraint to the dept table:
To drop a constraint, using the following syntax:
For example, the following ALTER TABLE statement drops the constraint named dept_unique:
To find a system-defined constraint name (valid in interactive SQL but not in the Query Editor):
You can also use the following:
If a system-defined constraint name is being dropped, specify the constraint name using a delimited identifier (that is, in double quotes), because system-defined constraint names include special characters.
ALTER TABLE Examples¶
- Add a column to an existing table:
- Drop a column from an existing table:
- Add a table-level constraint
- Drop a table-level constraint:
- Given the following two tables:
The following statement returns an error because there is a referential constraint that depends on dept_unique.
Dropping the empref constraint from table emp_const will work:
- Add a column to an existing table. :
Note
If NOT NULL is specified the WITH DEFAULT is mandatory but no value can be specified.
- Rename a table:
- Rename a table column:
- Add the MASKED attribute to the salary column of the employee table:
- Add a sampled min-max index on one column: