This statement is an extension to the ANSI/ISO standard for SQL.
>>-RENAME TABLE--+--------+--old_table--TO----------------------> '-owner.-' >--+-------------------+--new_table---------------------------->< | (1) | '--------new_owner.-'
Element | Description | Restrictions | Syntax |
---|---|---|---|
new_table | New name for old_table | Must be unique among the names of sequences, tables, views, and synonyms in the database | Identifier, p. Identifier |
old_table | Name that new_table replaces | Must be the name (not the synonym) of a table that exists in the current database | Identifier, p. Identifier |
owner | Current owner of the table | Must be the owner of the table. | Owner Name,
p. Owner Name |
new_owner | New owner of the table (XPS only) | Must have DBA privilege on the database | Owner Name,
p. Owner Name |
To rename a table, you must be the owner of the table, or have the ALTER privilege on the table, or have the DBA privilege on the database.
An error occurs if old_table is a synonym, rather than the name of a table.
The renamed table remains in the current database. You cannot use the RENAME TABLE statement to move a table from the current database to another database, nor to rename a table that resides in another database.
In Dynamic Server, you cannot change the table owner by renaming the table. An error occurs if you try to specify an owner. qualifier for the new name of the table.
In Extended Parallel Server, a user with DBA privilege on the database can change the owner of a table, if the table is local. Both the table name and owner can be changed by a single statement. The following example uses the RENAME TABLE statement to change the owner of a table:
RENAME TABLE tro.customer TO mike.customer
When the table owner is changed, you must specify both the old owner and new owner.
In Extended Parallel Server, you cannot rename a table that contains a dependent GK index.
In an ANSI-compliant database, if you are not the owner of old_table, you must specify owner.old_table as the old name of the table.
If old_table is referenced by a view in the current database, the view definition is updated in the sysviews system catalog table to reflect the new table name. For further information on the sysviews system catalog table, see the IBM Informix Guide to SQL: Reference.
If old_table is a triggering table, the database server takes these actions:
When the trigger executes, the database server returns an error if it encounters a table name for which no table exists.
You can reorganize the items table to move the quantity column from the fifth position to the third position by following these steps:
The following example uses the RENAME TABLE statement as the last step:
CREATE TABLE new_table ( item_num SMALLINT, order_num INTEGER, quantity SMALLINT, stock_num SMALLINT, manu_code CHAR(3), total_price MONEY(8) ); INSERT INTO new_table SELECT item_num, order_num, quantity, stock_num, manu_code, total_price FROM items; DROP TABLE items; RENAME TABLE new_table TO items;
Related statements: ALTER TABLE, CREATE TABLE , DROP TABLE , and RENAME COLUMN