<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Vertica Documentation – ALTER TABLE</title>
    <link>/en/sql-reference/statements/alter-statements/alter-table/</link>
    <description>Recent content in ALTER TABLE on Vertica Documentation</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/sql-reference/statements/alter-statements/alter-table/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Sql-Reference: Projection column encoding</title>
      <link>/en/sql-reference/statements/alter-statements/alter-table/projection-column-encoding/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/alter-statements/alter-table/projection-column-encoding/</guid>
      <description>
        
        
        &lt;p&gt;After you create a table and its projections, you can call &lt;a href=&#34;../../../../../en/sql-reference/statements/alter-statements/alter-table/&#34;&gt;ALTER TABLE...ALTER COLUMN&lt;/a&gt; to set or change the &lt;a href=&#34;../../../../../en/sql-reference/statements/create-statements/create-projection/encoding-types/&#34;&gt;encoding type&lt;/a&gt; of an existing column in one or more projections. For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;ALTER TABLE store.store_dimension ALTER COLUMN store_region
  ENCODING rle PROJECTIONS (store.store_dimension_p1_b0, store.store_dimension_p2);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In this example, the ALTER TABLE statement specifies to set RLE encoding on column &lt;code&gt;store_region&lt;/code&gt; for two projections: &lt;code&gt;store_dimension_p1_b0&lt;/code&gt; and &lt;code&gt;store_dimension_p2&lt;/code&gt;. The &lt;code&gt;PROJECTIONS&lt;/code&gt; list references the two projections by their projection name and base name, respectively. You can reference a projection either way; in both cases, the change is propagated to all buddies of the projection and stored in its DDL accordingly:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; select export_objects(&amp;#39;&amp;#39;,&amp;#39;store.store_dimension&amp;#39;);

                          export_objects
------------------------------------------------------------------
CREATE TABLE store.store_dimension
(
    store_key int NOT NULL,
    store_name varchar(64),
    store_number int,
    store_address varchar(256),
    store_city varchar(64),
    store_state char(2),
    store_region varchar(64)
);

CREATE PROJECTION store.store_dimension_p1
(
 store_key,
 store_name,
 store_number,
 store_address,
 store_city,
 store_state,
 store_region ENCODING RLE
)
AS
 SELECT store_dimension.store_key,
        store_dimension.store_name,
        store_dimension.store_number,
        store_dimension.store_address,
        store_dimension.store_city,
        store_dimension.store_state,
        store_dimension.store_region
 FROM store.store_dimension
 ORDER BY store_dimension.store_key
SEGMENTED BY hash(store_dimension.store_key) ALL NODES KSAFE 1;

CREATE PROJECTION store.store_dimension_p2
(
 store_key,
 store_name,
 store_number,
 store_address,
 store_city,
 store_state,
 store_region ENCODING RLE
)
AS
 SELECT ...
&lt;/code&gt;&lt;/pre&gt;
&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
When you add or change a column&#39;s encoding type, it has no immediate effect on existing projection data. Vertica applies the encoding only to newly loaded data, and to existing data on &lt;a href=&#34;../../../../../en/admin/managing-db/tuple-mover/mergeout/&#34;&gt;mergeout&lt;/a&gt;.
&lt;/div&gt;

      </description>
    </item>
    
    <item>
      <title>Sql-Reference: Table-constraint</title>
      <link>/en/sql-reference/statements/alter-statements/alter-table/table-constraint/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/sql-reference/statements/alter-statements/alter-table/table-constraint/</guid>
      <description>
        
        
        &lt;h2 id=&#34;table-constraint&#34;&gt;Table-constraint&lt;/h2&gt;
&lt;p&gt;Adds a constraint to table metadata. You can specify table constraints with 
&lt;code&gt;
&lt;code&gt;&lt;a href=&#34;../../../../../en/sql-reference/statements/create-statements/create-table/&#34;&gt;CREATE TABLE&lt;/a&gt;&lt;/code&gt;&lt;/code&gt;, or add a constraint to an existing table with 
&lt;code&gt;
&lt;code&gt;&lt;a href=&#34;../../../../../en/sql-reference/statements/alter-statements/alter-table/&#34;&gt;ALTER TABLE&lt;/a&gt;&lt;/code&gt;&lt;/code&gt;. For details, see &lt;a href=&#34;../../../../../en/admin/constraints/setting-constraints/&#34;&gt;Setting constraints&lt;/a&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;

Adding a constraint to a table that is referenced in a view does not affect the view.

&lt;/div&gt;&lt;/p&gt;
&lt;h2 id=&#34;syntax&#34;&gt;Syntax&lt;/h2&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;[ CONSTRAINT &lt;span class=&#34;code-variable&#34;&gt;constraint-name&lt;/span&gt; ]
{
... PRIMARY KEY (&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;[,... ]) [ ENABLED | DISABLED ]
... | FOREIGN KEY (&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;[,... ] ) REFERENCES &lt;span class=&#34;code-variable&#34;&gt;table&lt;/span&gt; [ (&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;[,...]) ]
... | UNIQUE (&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;[,...]) [ ENABLED | DISABLED ]
... | CHECK (&lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;) [ ENABLED | DISABLED ]
}
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;parameters&#34;&gt;Parameters&lt;/h2&gt;
&lt;dl&gt;
&lt;dt&gt;&lt;code&gt;CONSTRAINT &lt;/code&gt;&lt;em&gt;&lt;code&gt;constraint‑name&lt;/code&gt;&lt;/em&gt;&lt;/dt&gt;
&lt;dd&gt;Assigns a name to the constraint. Vertica recommends that you name all constraints.&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;PRIMARY KEY&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Defines one or more &lt;code&gt;NOT NULL&lt;/code&gt; columns as the primary key as follows:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;PRIMARY KEY (&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;[,...]) [ ENABLED | DISABLED]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can qualify this constraint with the keyword &lt;code&gt;ENABLED&lt;/code&gt; or &lt;code&gt;DISABLED&lt;/code&gt;. See &lt;a href=&#34;#EnforcingTableConstraint&#34;&gt;Enforcing Constraints&lt;/a&gt; below.&lt;/p&gt;
&lt;p&gt;If you do not name a primary key constraint, Vertica assigns the name &lt;code&gt;C_PRIMARY&lt;/code&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;FOREIGN KEY&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Adds a referential integrity constraint defining one or more columns as foreign keys as follows:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;FOREIGN KEY (&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;[,... ]) REFERENCES &lt;span class=&#34;code-variable&#34;&gt;table&lt;/span&gt; [(&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;[,... ])]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;If you omit &lt;em&gt;&lt;code&gt;column&lt;/code&gt;&lt;/em&gt;, Vertica references the primary key in &lt;em&gt;&lt;code&gt;table&lt;/code&gt;&lt;/em&gt;.&lt;/p&gt;
&lt;p&gt;If you do not name a foreign key constraint, Vertica assigns the name &lt;code&gt;C_FOREIGN&lt;/code&gt;.

&lt;div class=&#34;admonition important&#34; role=&#34;alert&#34;&gt;
&lt;h4 class=&#34;admonition-head&#34;&gt;Important&lt;/h4&gt;
&lt;p&gt;Adding a foreign key constraint requires the following privileges (in addition to privileges also required by ALTER TABLE):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;REFERENCES on the referenced table&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;USAGE on the schema of the referenced table&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;UNIQUE&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies that the data in a column or group of columns is unique with respect to all table rows, as follows:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;UNIQUE (&lt;span class=&#34;code-variable&#34;&gt;column&lt;/span&gt;[,...]) [ENABLED | DISABLED]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can qualify this constraint with the keyword &lt;code&gt;ENABLED&lt;/code&gt; or &lt;code&gt;DISABLED&lt;/code&gt;. See &lt;a href=&#34;#EnforcingTableConstraint&#34;&gt;Enforcing Constraints&lt;/a&gt; below.&lt;/p&gt;
&lt;p&gt;If you do not name a unique constraint, Vertica assigns the name &lt;code&gt;C_UNIQUE&lt;/code&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;&lt;code&gt;CHECK&lt;/code&gt;&lt;/dt&gt;
&lt;dd&gt;Specifies a check condition as an expression that returns a Boolean value, as follows:
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CHECK (&lt;span class=&#34;code-variable&#34;&gt;expression&lt;/span&gt;) [ENABLED | DISABLED]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;You can qualify this constraint with the keyword &lt;code&gt;ENABLED&lt;/code&gt; or &lt;code&gt;DISABLED&lt;/code&gt;. See &lt;a href=&#34;#EnforcingTableConstraint&#34;&gt;Enforcing Constraints&lt;/a&gt; below.&lt;/p&gt;
&lt;p&gt;If you do not name a check constraint, Vertica assigns the name &lt;code&gt;C_CHECK&lt;/code&gt;.&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;h2 id=&#34;privileges&#34;&gt;Privileges&lt;/h2&gt;
&lt;p&gt;Non-superusers: table owner, or the following privileges:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;USAGE on schema&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;ALTER on table&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;SELECT on table to enable or disable &lt;a href=&#34;../../../../../en/admin/constraints/constraint-enforcement/&#34;&gt;constraint enforcement&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;a name=&#34;EnforcingTableConstraint&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;enforcing-constraints&#34;&gt;Enforcing constraints&lt;/h2&gt;
&lt;p&gt;A table can specify whether Vertica automatically enforces a primary key, unique key or check constraint with the keyword &lt;code&gt;ENABLED&lt;/code&gt; or &lt;code&gt;DISABLED&lt;/code&gt;. If you omit &lt;code&gt;ENABLED&lt;/code&gt; or &lt;code&gt;DISABLED&lt;/code&gt;, Vertica determines whether to enable the constraint automatically by checking the appropriate configuration parameter:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;EnableNewPrimaryKeysByDefault&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;EnableNewUniqueKeysByDefault&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;EnableNewCheckConstraintsByDefault&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&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;
&lt;h2 id=&#34;examples&#34;&gt;Examples&lt;/h2&gt;
&lt;p&gt;The following example creates a table (&lt;code&gt;t01&lt;/code&gt;) with a primary key constraint.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE t01 (id int CONSTRAINT sampleconstraint PRIMARY KEY);
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This example creates the same table without the constraint, and then adds the constraint with &lt;code&gt;ALTER TABLE ADD CONSTRAINT&lt;/code&gt;&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE t01 (id int);
CREATE TABLE

ALTER TABLE t01 ADD CONSTRAINT sampleconstraint PRIMARY KEY(id);
WARNING 2623:  Column &amp;#34;id&amp;#34; definition changed to NOT NULL
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following example creates a table (&lt;code&gt;addapk&lt;/code&gt;) with two columns, adds a third column to the table, and then adds a primary key constraint on the third column.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE addapk (col1 INT, col2 INT);
CREATE TABLE

=&amp;gt; ALTER TABLE addapk ADD COLUMN col3 INT;
ALTER TABLE

=&amp;gt; ALTER TABLE addapk ADD CONSTRAINT col3constraint PRIMARY KEY (col3) ENABLED;
WARNING 2623:  Column &amp;#34;col3&amp;#34; definition changed to NOT NULL
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Using the sample table &lt;code&gt;addapk&lt;/code&gt;, check that the primary key constraint is enabled (&lt;code&gt;is_enabled&lt;/code&gt; is &lt;code&gt;t&lt;/code&gt;).&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT constraint_name, column_name, constraint_type, is_enabled FROM PRIMARY_KEYS WHERE table_name IN (&amp;#39;addapk&amp;#39;);

 constraint_name | column_name | constraint_type | is_enabled
-----------------+-------------+-----------------+------------
 col3constraint  | col3        | p               | t
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;This example disables the constraint using &lt;code&gt;ALTER TABLE ALTER CONSTRAINT&lt;/code&gt;.&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE addapk ALTER CONSTRAINT col3constraint DISABLED;
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;Check that the primary key is now disabled (&lt;code&gt;is_enabled&lt;/code&gt; is &lt;code&gt;f&lt;/code&gt;).&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT constraint_name, column_name, constraint_type, is_enabled FROM PRIMARY_KEYS WHERE table_name IN (&amp;#39;addapk&amp;#39;);

 constraint_name | column_name | constraint_type | is_enabled
-----------------+-------------+-----------------+------------
 col3constraint  | col3        | p               | f
(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For a general discussion of constraints, see &lt;a href=&#34;../../../../../en/admin/constraints/&#34;&gt;Constraints&lt;/a&gt;. For additional examples of creating and naming constraints, see &lt;a href=&#34;../../../../../en/admin/constraints/naming-constraints/&#34;&gt;Naming constraints&lt;/a&gt;.&lt;/p&gt;


      </description>
    </item>
    
  </channel>
</rss>
