<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Altering table definitions</title>
    <link>/en/admin/working-with-native-tables/altering-table-definitions/</link>
    <description>Recent content in Altering table definitions on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/admin/working-with-native-tables/altering-table-definitions/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Admin: Adding table columns</title>
      <link>/en/admin/working-with-native-tables/altering-table-definitions/adding-table-columns/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/working-with-native-tables/altering-table-definitions/adding-table-columns/</guid>
      <description>
        
        
        &lt;p&gt;You add a column to a persistent table with &lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-table/#AddColumn&#34;&gt;ALTER TABLE...ADD COLUMN&lt;/a&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ALTER TABLE ...
ADD COLUMN [IF NOT EXISTS] &lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt; &lt;span class=&#34;code-variable&#34;&gt;datatype&lt;/span&gt;
  [&lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/create-statements/create-table/column-constraint/#&#34;&gt;column-constraint&lt;/a&gt;&lt;/span&gt;]
  [ENCODING &lt;span class=&#34;code-variable&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/create-statements/create-projection/encoding-types/#&#34;&gt;encoding-type&lt;/a&gt;&lt;/span&gt;]
  [PROJECTIONS (&lt;span class=&#34;code-variable&#34;&gt;projections-list&lt;/span&gt;) | ALL PROJECTIONS ]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;An ALTER TABLE statement can include more than one ADD COLUMN clause, separated by commas:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ALTER TABLE...
  ADD COLUMN pid INT NOT NULL,
  ADD COLUMN desc VARCHAR(200),
  ADD COLUMN region INT DEFAULT 1
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Columns that use DEFAULT with static values, as shown in the previous example, can be added in a single ALTER TABLE statement.  Columns that use non-static DEFAULT values must be added in separate ALTER TABLE statements.&lt;/p&gt;
&lt;p&gt;Before you add columns to a table, verify that all its superprojections are up to date.&lt;/p&gt;
&lt;h2 id=&#34;table-locking&#34;&gt;Table locking&lt;/h2&gt;
&lt;p&gt;When you use ADD COLUMN to alter a table, the database takes an O lock on the table until the operation completes. The lock prevents DELETE, UPDATE, INSERT, and COPY statements from accessing the table. The lock also blocks SELECT statements issued at SERIALIZABLE isolation level, until the operation completes.&lt;/p&gt;
&lt;p&gt;Adding a column to a table does not affect &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/k-safety/&#34; title=&#34;For more information, see Designing for K-Safety.&#34;&gt;K-safety&lt;/a&gt; of the &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/physical-schema/&#34; title=&#34;Consists of a set of projections used to store data on disk.&#34;&gt;physical schema&lt;/a&gt; design.&lt;/p&gt;
&lt;p&gt;You can add columns when nodes are down.&lt;/p&gt;
&lt;h2 id=&#34;adding-new-columns-to-projections&#34;&gt;Adding new columns to projections&lt;/h2&gt;
&lt;p&gt;When you add a column to a table, the database automatically adds the column to &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/superprojection/&#34; title=&#34;A projection that includes all columns in an anchor table.&#34;&gt;superprojections&lt;/a&gt; of that table. The ADD COLUMN clause can also specify to add the column to one or more non-superprojections, with one of these options:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;PROJECTIONS (&lt;/code&gt;&lt;em&gt;&lt;code&gt;projections-list&lt;/code&gt;&lt;/em&gt;): Adds the new column to one or more projections of this table, specified as a comma-delimted list of projection &lt;a href=&#34;../../../../en/admin/projections/projection-naming/&#34;&gt;base names&lt;/a&gt;. The database adds the column to all buddies of each projection. The projection list cannot include projections with &lt;a href=&#34;../../../../en/data-analysis/data-aggregation/pre-aggregating-data-projections/&#34;&gt;pre-aggregated data&lt;/a&gt; such as live aggregate projections; otherwise, the database rolls back the ALTER TABLE statement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ALL PROJECTIONS&lt;/code&gt; adds the column to all projections of this table, excluding projections with pre-aggregated data.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, the &lt;code&gt;store_orders&lt;/code&gt; table has two projections, a superprojection (&lt;code&gt;store_orders_super&lt;/code&gt;) and a user-created projection (&lt;code&gt;store_orders_p&lt;/code&gt;). The following ALTER TABLE...ADD COLUMN statement adds a column to the &lt;code&gt;store_orders&lt;/code&gt; table. Because the statement omits the PROJECTIONS option, the database adds the column only to the table&#39;s superprojection:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE public.store_orders &lt;span class=&#34;code-input&#34;&gt;ADD COLUMN expected_ship_date date&lt;/span&gt;;
ALTER TABLE
=&amp;gt; SELECT projection_column_name, projection_name FROM projection_columns WHERE table_name ILIKE &amp;#39;store_orders&amp;#39;
     ORDER BY projection_name , projection_column_name;
 projection_column_name |  projection_name
------------------------+--------------------
 order_date             | store_orders_p_b0
 order_no               | store_orders_p_b0
 ship_date              | store_orders_p_b0
 order_date             | store_orders_p_b1
 order_no               | store_orders_p_b1
 ship_date              | store_orders_p_b1
&lt;span class=&#34;code-input&#34;&gt; expected_ship_date     | store_orders_super&lt;/span&gt;
 order_date             | store_orders_super
 order_no               | store_orders_super
 ship_date              | store_orders_super
 shipper                | store_orders_super
(11 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following ALTER TABLE...ADD COLUMN statement includes the PROJECTIONS option. This specifies to include projection &lt;code&gt;store_orders_p&lt;/code&gt; in the add operation. The database adds the new column to this projection and the table&#39;s superprojection:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE public.store_orders &lt;span class=&#34;code-input&#34;&gt;ADD COLUMN delivery_date date PROJECTIONS (store_orders_p)&lt;/span&gt;;
=&amp;gt; SELECT projection_column_name, projection_name FROM projection_columns WHERE table_name ILIKE &amp;#39;store_orders&amp;#39;
     ORDER BY projection_name, projection_column_name;
 projection_column_name |  projection_name
------------------------+--------------------
 &lt;span class=&#34;code-input&#34;&gt;delivery_date          | store_orders_p_b0&lt;/span&gt;
 order_date             | store_orders_p_b0
 order_no               | store_orders_p_b0
 ship_date              | store_orders_p_b0
 &lt;span class=&#34;code-input&#34;&gt;delivery_date          | store_orders_p_b1&lt;/span&gt;
 order_date             | store_orders_p_b1
 order_no               | store_orders_p_b1
 ship_date              | store_orders_p_b1
 &lt;span class=&#34;code-input&#34;&gt;delivery_date          | store_orders_super&lt;/span&gt;
 expected_ship_date     | store_orders_super
 order_date             | store_orders_super
 order_no               | store_orders_super
 ship_date              | store_orders_super
 shipper                | store_orders_super
(14 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;updating-associated-table-views&#34;&gt;Updating associated table views&lt;/h2&gt;
&lt;p&gt;Adding new columns to a table that has an associated view does not update the view&#39;s result set, even if the view uses a wildcard (*) to represent all table columns. To incorporate new columns, you must &lt;a href=&#34;../../../../en/sql-reference/statements/create-statements/create-view/&#34;&gt;recreate the view&lt;/a&gt;.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Dropping table columns</title>
      <link>/en/admin/working-with-native-tables/altering-table-definitions/dropping-table-columns/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/working-with-native-tables/altering-table-definitions/dropping-table-columns/</guid>
      <description>
        
        
        &lt;p&gt;&lt;span class=&#34;sql&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-table/&#34;&gt;ALTER TABLE...DROP COLUMN&lt;/a&gt;&lt;/span&gt; drops the specified table column and the ROS containers that correspond to the dropped column:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ALTER TABLE [&lt;span class=&#34;code-variable&#34;&gt;schema&lt;/span&gt;.]&lt;span class=&#34;code-variable&#34;&gt;table&lt;/span&gt; DROP [ COLUMN ] [IF EXISTS] &lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt; [CASCADE | RESTRICT]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;After the drop operation completes, data backed up from the current epoch onward recovers without the column. Data recovered from a backup that precedes the current epoch re-add the table column. Because drop operations physically purge object storage and catalog definitions (table history) from the table, &lt;span class=&#34;sql&#34;&gt;AT EPOCH&lt;/span&gt; (historical) queries return nothing for the dropped column.&lt;/p&gt;
&lt;p&gt;The altered table retains its object ID.

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

Drop column operations can be fast because these catalog-level changes do not require data reorganization, so the database can quickly reclaim disk storage.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;restrictions&#34;&gt;Restrictions&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;You cannot drop or alter a primary key column or a column that participates in the table partitioning clause.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You cannot drop the first column of any projection sort order, or columns that participate in a projection segmentation expression.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;In Enterprise Mode, all nodes must be up. This restriction does not apply to Eon mode.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;You cannot drop a column associated with an access policy. Attempts to do so produce the following error:&lt;br /&gt;&lt;code&gt;ERROR 6482: Failed to parse Access Policies for table &amp;quot;t1&amp;quot;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;using-cascade-to-force-a-drop&#34;&gt;Using CASCADE to force a drop&lt;/h2&gt;
&lt;p&gt;If the table column to drop has dependencies, you must qualify the &lt;span class=&#34;sql&#34;&gt;DROP COLUMN&lt;/span&gt; clause with the &lt;span class=&#34;sql&#34;&gt;CASCADE&lt;/span&gt; option. For example, the target column might be specified in a projection sort order. In this and other cases, &lt;span class=&#34;sql&#34;&gt;DROP COLUMN...CASCADE&lt;/span&gt; handles the dependency by reorganizing catalog definitions or dropping a projection. In all cases, &lt;span class=&#34;sql&#34;&gt;CASCADE&lt;/span&gt; performs the minimal reorganization required to drop the column.&lt;/p&gt;
&lt;p&gt;Use &lt;span class=&#34;sql&#34;&gt;CASCADE&lt;/span&gt; to drop a column with the following dependencies:

&lt;table class=&#34;table table-bordered&#34; &gt;



&lt;tr&gt; 

&lt;th &gt;
Dropped column dependency&lt;/th&gt; 

&lt;th &gt;
CASCADE behavior&lt;/th&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;


Any constraint&lt;/td&gt; 

&lt;td &gt;


The database drops the column when a &lt;span class=&#34;sql&#34;&gt;FOREIGN KEY&lt;/span&gt; constraint depends on a &lt;span class=&#34;sql&#34;&gt;UNIQUE&lt;/span&gt; or &lt;span class=&#34;sql&#34;&gt;PRIMARY KEY&lt;/span&gt; constraint on the referenced columns.&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;


Specified in projection sort order&lt;/td&gt; 

&lt;td &gt;


The database truncates projection sort order up to and including the projection that is dropped without impact on physical storage for other columns and then drops the specified column. For example if a projection&#39;s columns are in sort order (a,b,c), dropping column b causes the projection&#39;s sort order to be just (a), omitting column (c).&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;


Specified in a projection segmentation expression&lt;/td&gt; 

&lt;td &gt;


The column to drop is integral to the projection definition. If possible, the database drops the projection as long as doing so does not compromise K-safety; otherwise, the transaction rolls back.&lt;/td&gt;&lt;/tr&gt;

&lt;tr&gt; 

&lt;td &gt;
Referenced as default value of another column&lt;/td&gt; 

&lt;td &gt;


See &lt;a href=&#34;#Dropping&#34;&gt;Dropping a Column Referenced as Default&lt;/a&gt;, below.&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;
&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;Dropping&#34;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&#34;a-namedroppingreferencedcolumnadropping-a-column-referenced-as-default&#34;&gt;&lt;a name=&#34;DroppingReferencedColumn&#34;&gt;&lt;/a&gt;Dropping a column referenced as default&lt;/h2&gt;
&lt;p&gt;You might want to drop a table column that is referenced by another column as its default value. For example, the following table is defined with two columns, &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;:, where &lt;code&gt;b&lt;/code&gt; gets its default value from column &lt;code&gt;a&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE x (a int) UNSEGMENTED ALL NODES;
CREATE TABLE
=&amp;gt; ALTER TABLE x ADD COLUMN b int DEFAULT a;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In this case, dropping column &lt;code&gt;a&lt;/code&gt; requires the following procedure:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Remove the default dependency through &lt;span class=&#34;sql&#34;&gt;ALTER COLUMN..DROP DEFAULT&lt;/span&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE x ALTER COLUMN b DROP DEFAULT;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Create a replacement superprojection for the target table if one or both of the following conditions is true:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The target column is the table&#39;s first sort order column. If the table has no explicit sort order, the default table sort order specifies the first table column as the first sort order column. In this case, the new superprojection must specify a sort order that excludes the target column.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If the table is segmented, the target column is specified in the segmentation expression. In this case, the new superprojection must specify a segmentation expression that excludes the target column.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Given the previous example, table &lt;code&gt;x&lt;/code&gt; has a default sort order of (a,b). Because column &lt;code&gt;a&lt;/code&gt; is the table&#39;s first sort order column, you must create a replacement superprojection that is sorted on column &lt;code&gt;b&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE PROJECTION x_p1 as select * FROM x ORDER BY b UNSEGMENTED ALL NODES;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/management-functions/projection-functions/start-refresh/#&#34;&gt;START_REFRESH&lt;/a&gt;&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT START_REFRESH();
              START_REFRESH
----------------------------------------
 Starting refresh background process.

(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run &lt;span class=&#34;sql&#34;&gt;&lt;a href=&#34;../../../../en/sql-reference/functions/management-functions/epoch-functions/make-ahm-now/#&#34;&gt;MAKE_AHM_NOW&lt;/a&gt;&lt;/span&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT MAKE_AHM_NOW();
         MAKE_AHM_NOW
-------------------------------
 AHM set (New AHM Epoch: 1231)
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Drop the column:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE x DROP COLUMN a CASCADE;
&lt;/code&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;The database implements the &lt;span class=&#34;sql&#34;&gt;CASCADE&lt;/span&gt; directive as follows:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Drops the original superprojection for table &lt;code&gt;x&lt;/code&gt; (&lt;code&gt;x_super&lt;/code&gt;).&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Updates the replacement superprojection &lt;code&gt;x_p1&lt;/code&gt; by dropping column &lt;code&gt;a&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following series of commands successfully drops a &lt;span class=&#34;sql&#34;&gt;BYTEA&lt;/span&gt; data type column:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE t (x BYTEA(65000), y BYTEA, z BYTEA(1));
CREATE TABLE
=&amp;gt; ALTER TABLE t DROP COLUMN y;
ALTER TABLE
=&amp;gt; SELECT y FROM t;
ERROR 2624:  Column &amp;#34;y&amp;#34; does not exist
=&amp;gt; ALTER TABLE t DROP COLUMN x RESTRICT;
ALTER TABLE
=&amp;gt; SELECT x FROM t;
ERROR 2624:  Column &amp;#34;x&amp;#34; does not exist
=&amp;gt; SELECT * FROM t;
 z
---
(0 rows)
=&amp;gt; DROP TABLE t CASCADE;
DROP TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following series of commands tries to drop a &lt;span class=&#34;sql&#34;&gt;FLOAT(8)&lt;/span&gt; column and fails because there are not enough projections to maintain K-safety.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE t (x FLOAT(8),y FLOAT(08));
CREATE TABLE
=&amp;gt; ALTER TABLE t DROP COLUMN y RESTRICT;
ALTER TABLE
=&amp;gt; SELECT y FROM t;
ERROR 2624:  Column &amp;#34;y&amp;#34; does not exist
=&amp;gt; ALTER TABLE t DROP x CASCADE;
ROLLBACK 2409:  Cannot drop any more columns in t
=&amp;gt; DROP TABLE t CASCADE;
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Altering constraint enforcement</title>
      <link>/en/admin/working-with-native-tables/altering-table-definitions/altering-constraint-enforcement/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/working-with-native-tables/altering-table-definitions/altering-constraint-enforcement/</guid>
      <description>
        
        
        &lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-table/#&#34;&gt;ALTER TABLE...ALTER CONSTRAINT&lt;/a&gt;&lt;/code&gt; can enable or disable enforcement of &lt;a href=&#34;../../../../en/admin/constraints/supported-constraints/primary-key-constraints/&#34;&gt;primary key&lt;/a&gt;, &lt;a href=&#34;../../../../en/admin/constraints/supported-constraints/unique-constraints/&#34;&gt;unique&lt;/a&gt;, and &lt;a href=&#34;../../../../en/admin/constraints/supported-constraints/check-constraints/&#34;&gt;check&lt;/a&gt; constraints. You must qualify this clause with the keyword &lt;code&gt;ENABLED&lt;/code&gt; or &lt;code&gt;DISABLED&lt;/code&gt;:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;ENABLED&lt;/code&gt; enforces the specified constraint.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;DISABLED&lt;/code&gt; disables enforcement of the specified constraint.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ALTER TABLE public.new_sales ALTER CONSTRAINT C_PRIMARY ENABLED;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For details, see &lt;a href=&#34;../../../../en/admin/constraints/constraint-enforcement/#&#34;&gt;Constraint enforcement&lt;/a&gt;.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Renaming tables</title>
      <link>/en/admin/working-with-native-tables/altering-table-definitions/renaming-tables/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/working-with-native-tables/altering-table-definitions/renaming-tables/</guid>
      <description>
        
        
        &lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-table/#&#34;&gt;ALTER TABLE...RENAME TO&lt;/a&gt;&lt;/code&gt; renames one or more tables. Renamed tables retain their original OIDs.&lt;/p&gt;
&lt;p&gt;You can rename multiple tables by supplying two comma-delimited lists. The database maps the names according to their order in the two lists. Only the first list can qualify table names with a schema. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE S1.T1, S1.T2 RENAME TO U1, U2;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The &lt;code&gt;RENAME TO&lt;/code&gt; parameter is applied atomically: all tables are renamed, or none of them. For example, if the number of tables to rename does not match the number of new names, none of the tables is renamed.

&lt;div class=&#34;admonition caution&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Caution&lt;/h4&gt;

If a table is referenced by a view, renaming it causes the view to fail, unless you create another table with the previous name to replace the renamed table.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;using-rename-to-swap-tables-within-a-schema&#34;&gt;Using rename to swap tables within a schema&lt;/h2&gt;
&lt;p&gt;You can use &lt;code&gt;ALTER TABLE...RENAME TO&lt;/code&gt; to swap tables within the same schema, without actually moving data. You cannot swap tables across schemas.&lt;/p&gt;
&lt;p&gt;The following example swaps the data in tables &lt;code&gt;T1&lt;/code&gt; and &lt;code&gt;T2&lt;/code&gt; through intermediary table &lt;code&gt;temp&lt;/code&gt;:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;t1&lt;/code&gt; to &lt;code&gt;temp&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;t2&lt;/code&gt; to &lt;code&gt;t1&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;temp&lt;/code&gt; to &lt;code&gt;t2&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; DROP TABLE IF EXISTS temp, t1, t2;
DROP TABLE
=&amp;gt; CREATE TABLE t1 (original_name varchar(24));
CREATE TABLE
=&amp;gt; CREATE TABLE t2 (original_name varchar(24));
CREATE TABLE
=&amp;gt; INSERT INTO t1 VALUES (&amp;#39;original name t1&amp;#39;);
 OUTPUT
--------
      1
(1 row)

=&amp;gt; INSERT INTO t2 VALUES (&amp;#39;original name t2&amp;#39;);
 OUTPUT
--------
      1
(1 row)

=&amp;gt; COMMIT;
COMMIT
=&amp;gt; ALTER TABLE t1, t2, temp RENAME TO temp, t1, t2;
ALTER TABLE
=&amp;gt; SELECT * FROM t1, t2;
  original_name   |  original_name
------------------+------------------
 original name t2 | original name t1
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Moving tables to another schema</title>
      <link>/en/admin/working-with-native-tables/altering-table-definitions/moving-tables-to-another-schema/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/working-with-native-tables/altering-table-definitions/moving-tables-to-another-schema/</guid>
      <description>
        
        
        &lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-table/#&#34;&gt;ALTER TABLE...SET SCHEMA&lt;/a&gt;&lt;/code&gt; moves a table from one schema to another. The database automatically moves all projections that are anchored to the source table to the destination schema. It also moves all &lt;a href=&#34;../../../../en/admin/working-with-native-tables/sequences/identity-sequences/&#34;&gt;IDENTITY&lt;/a&gt; columns to the destination schema.&lt;/p&gt;
&lt;p&gt;Moving a table across schemas requires that you have &lt;code&gt;USAGE&lt;/code&gt; privileges on the current schema and &lt;code&gt;CREATE&lt;/code&gt; privileges on destination schema. You can move only one table between schemas at a time. You cannot move temporary tables across schemas.&lt;/p&gt;
&lt;h2 id=&#34;name-conflicts&#34;&gt;Name conflicts&lt;/h2&gt;
&lt;p&gt;If a table of the same name or any of the projections that you want to move already exist in the new schema, the statement rolls back and does not move either the table or any projections. To work around name conflicts:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Rename any conflicting table or projections that you want to move.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run 
&lt;code&gt;&lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-table/#&#34;&gt;ALTER TABLE...SET SCHEMA&lt;/a&gt;&lt;/code&gt; again.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class=&#34;alert admonition note&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Note&lt;/h4&gt;

The database lets you move system tables to system schemas. Moving system tables could be necessary to support designs created through the &lt;a class=&#34;glosslink&#34; href=&#34;../../../../en/glossary/db-designer/&#34; title=&#34;A tool that analyzes a logical schema definition, sample queries, and sample data, and creates a physical schema () in the form of a SQL script that you deploy automatically or manually.&#34;&gt;Database Designer&lt;/a&gt;.

&lt;/div&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;The following example moves table &lt;code&gt;T1&lt;/code&gt; from schema &lt;code&gt;S1&lt;/code&gt; to schema &lt;code&gt;S2&lt;/code&gt;. All projections that are anchored on table &lt;code&gt;T1&lt;/code&gt; automatically move to schema &lt;code&gt;S2&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE S1.T1 SET SCHEMA S2;
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Changing table ownership</title>
      <link>/en/admin/working-with-native-tables/altering-table-definitions/changing-table-ownership/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/working-with-native-tables/altering-table-definitions/changing-table-ownership/</guid>
      <description>
        
        
        &lt;p&gt;As a superuser or table owner, you can reassign table ownership with &lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-table/&#34;&gt;ALTER TABLE...OWNER TO&lt;/a&gt;, as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ALTER TABLE [&lt;span class=&#34;code-variable&#34;&gt;schema.&lt;/span&gt;]&lt;span class=&#34;code-variable&#34;&gt;table-name&lt;/span&gt; OWNER TO &lt;span class=&#34;code-variable&#34;&gt;owner-name&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Changing table ownership is useful when moving a table from one schema to another. Ownership reassignment is also useful when a table owner leaves the company or changes job responsibilities. Because you can change the table owner, the tables won&#39;t have to be completely rewritten, you can avoid loss in productivity.&lt;/p&gt;
&lt;p&gt;Changing table ownership automatically causes the following changes:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Grants on the table that were made by the original owner are dropped and all existing privileges on the table are revoked from the previous owner. Changes in table ownership has no effect on schema privileges.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Ownership of dependent &lt;a href=&#34;../../../../en/admin/working-with-native-tables/sequences/identity-sequences/&#34;&gt;IDENTITY&lt;/a&gt; sequences are transferred with the table. However, ownership does not change for named sequences created with &lt;a href=&#34;../../../../en/sql-reference/statements/create-statements/create-sequence/#&#34;&gt;CREATE SEQUENCE&lt;/a&gt;. To transfer ownership of these sequences, use &lt;a href=&#34;../../../../en/sql-reference/statements/alter-statements/alter-sequence/#&#34;&gt;ALTER SEQUENCE&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;New table ownership is propagated to its projections.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;example&#34;&gt;Example&lt;/h2&gt;
&lt;p&gt;In this example, user Bob connects to the database, looks up the tables, and transfers ownership of table &lt;code&gt;t33&lt;/code&gt; from himself to user Alice.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c - Bob
You are now connected as user &amp;#34;Bob&amp;#34;.
=&amp;gt; \d
 Schema |  Name  | Kind  |  Owner  | Comment
--------+--------+-------+---------+---------
 public | applog | table | dbadmin |
 public | t33    | table | Bob     |
(2 rows)
=&amp;gt; ALTER TABLE t33 OWNER TO Alice;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When Bob looks up database tables again, he no longer sees table &lt;code&gt;t33&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \d                List of tables
               List of tables
 Schema |  Name  | Kind  |  Owner  | Comment
--------+--------+-------+---------+---------
 public | applog | table | dbadmin |
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When user Alice connects to the database and looks up tables, she sees she is the owner of table &lt;code&gt;t33&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c - Alice
You are now connected as user &amp;#34;Alice&amp;#34;.
=&amp;gt; \d
             List of tables
 Schema | Name | Kind  | Owner | Comment
--------+------+-------+-------+---------
 public | t33  | table | Alice |
(2 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Alice or a superuser can transfer table ownership back to Bob. In the following case a superuser performs the transfer.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; \c - dbadmin
You are now connected as user &amp;#34;dbadmin&amp;#34;.
=&amp;gt; ALTER TABLE t33 OWNER TO Bob;
ALTER TABLE
=&amp;gt; \d
                List of tables
 Schema |   Name   | Kind  |  Owner  | Comment
--------+----------+-------+---------+---------
 public | applog   | table | dbadmin |
 public | comments | table | dbadmin |
 public | t33      | table | Bob     |
 s1     | t1       | table | User1   |
(4 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can also query system table &lt;a href=&#34;../../../../en/sql-reference/system-tables/v-catalog-schema/tables/#&#34;&gt;TABLES&lt;/a&gt; to view table and owner information. Note that a change in ownership does not change the table ID.&lt;/p&gt;
&lt;p&gt;In the below series of commands, the superuser changes table ownership back to Alice and queries the &lt;code&gt;TABLES&lt;/code&gt; system table.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; ALTER TABLE t33 OWNER TO Alice;
ALTER TABLE
=&amp;gt; SELECT table_schema_id, table_schema, table_id, table_name, owner_id, owner_name FROM tables;
  table_schema_id  | table_schema |     table_id      | table_name |     owner_id      | owner_name
-------------------+--------------+-------------------+------------+-------------------+------------
 45035996273704968 | public       | 45035996273713634 | applog     | 45035996273704962 | dbadmin
 45035996273704968 | public       | 45035996273724496 | comments   | 45035996273704962 | dbadmin
 45035996273730528 | s1           | 45035996273730548 | t1         | 45035996273730516 | User1
 45035996273704968 | public       | 45035996273795846 | t33        | 45035996273724576 | Alice
(5 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Now the superuser changes table ownership back to Bob and queries the &lt;code&gt;TABLES&lt;/code&gt; table again. Nothing changes but the &lt;code&gt;owner_name&lt;/code&gt; row, from Alice to Bob.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE t33 OWNER TO Bob;
ALTER TABLE
=&amp;gt; SELECT table_schema_id, table_schema, table_id, table_name, owner_id, owner_name FROM tables;
  table_schema_id  | table_schema |     table_id      | table_name |     owner_id      | owner_name
-------------------+--------------+-------------------+------------+-------------------+------------
 45035996273704968 | public       | 45035996273713634 | applog     | 45035996273704962 | dbadmin
 45035996273704968 | public       | 45035996273724496 | comments   | 45035996273704962 | dbadmin
 45035996273730528 | s1           | 45035996273730548 | t1         | 45035996273730516 | User1
 45035996273704968 | public       | 45035996273793876 | foo        | 45035996273724576 | Alice
 45035996273704968 | public       | 45035996273795846 | t33        | 45035996273714428 | Bob
(5 rows)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
  </channel>
</rss>
