<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>OpenText Analytics Database 26.2.x – Constraints</title>
    <link>/en/admin/constraints/</link>
    <description>Recent content in Constraints on OpenText Analytics Database 26.2.x</description>
    <generator>Hugo -- gohugo.io</generator>
    
	  <atom:link href="/en/admin/constraints/index.xml" rel="self" type="application/rss+xml" />
    
    
      
        
      
    
    
    <item>
      <title>Admin: Supported constraints</title>
      <link>/en/admin/constraints/supported-constraints/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/constraints/supported-constraints/</guid>
      <description>
        
        
        &lt;p&gt;OpenText™ Analytics Database supports standard SQL constraints, as described in this section.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Setting constraints</title>
      <link>/en/admin/constraints/setting-constraints/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/constraints/setting-constraints/</guid>
      <description>
        
        
        &lt;p&gt;You can set constraints on a new table and an existing one with 
&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; and 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#AddConstraint&#34;&gt;ALTER TABLE...ADD CONSTRAINT&lt;/a&gt;&lt;/code&gt;, respectively.&lt;/p&gt;
&lt;h2 id=&#34;setting-constraints-on-a-new-table&#34;&gt;Setting constraints on a new table&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;CREATE TABLE&lt;/code&gt; can specify a constraint in two ways: as part of the column definition, or following all column definitions.&lt;/p&gt;
&lt;p&gt;For example, the following &lt;code&gt;CREATE TABLE&lt;/code&gt; statement sets two constraints on column &lt;code&gt;sku_number&lt;/code&gt;, &lt;code&gt;NOT NULL&lt;/code&gt; and &lt;code&gt;UNIQUE&lt;/code&gt;. After all columns are defined, the statement also sets a primary key that is composed of two columns, &lt;code&gt;product_key&lt;/code&gt; and &lt;code&gt;product_version&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE public.prod_dimension(
    product_key int,
    product_version int,
    product_description varchar(128),
    sku_number char(32) NOT NULL UNIQUE,
    category_description char(32),
    CONSTRAINT pk PRIMARY KEY (product_key, product_version) ENABLED
);
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;setting-constraints-on-an-existing-table&#34;&gt;Setting constraints on an existing table&lt;/h2&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#AddConstraint&#34;&gt;ALTER TABLE...ADD CONSTRAINT&lt;/a&gt;&lt;/code&gt; adds a constraint to an existing table. For example, the following statement specifies unique values for column &lt;code&gt;product_version&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE prod_dimension ADD CONSTRAINT u_product_versions UNIQUE (product_version) ENABLED;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;validating-existing-data&#34;&gt;Validating existing data&lt;/h2&gt;
&lt;p&gt;When you add a constraint on a column that already contains data, OpenText™ Analytics Database immediately validates column values if the following conditions are both true:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;The constraint is a &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;, or &lt;a href=&#34;../../../en/admin/constraints/supported-constraints/check-constraints/&#34;&gt;check&lt;/a&gt; constraint.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;The constraint is &lt;a href=&#34;../../../en/admin/constraints/constraint-enforcement/&#34;&gt;enforced&lt;/a&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;If either of these conditions is not true, the database does not validate the column values. In this case, you must call 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/table-functions/analyze-constraints/#&#34;&gt;ANALYZE_CONSTRAINTS&lt;/a&gt;&lt;/code&gt; to find constraint violations. Otherwise, queries are liable to return unexpected results. For details, see &lt;a href=&#34;../../../en/admin/constraints/detecting-constraint-violations/#&#34;&gt;Detecting constraint violations&lt;/a&gt;.&lt;/p&gt;
&lt;h2 id=&#34;exporting-table-constraints&#34;&gt;Exporting table constraints&lt;/h2&gt;
&lt;p&gt;Whether you specify constraints in the column definition or on the table, the database stores the table DDL as part of the &lt;code&gt;CREATE&lt;/code&gt; statement and exports them as such. One exception applies: foreign keys are stored and &lt;a href=&#34;../../../en/sql-reference/functions/management-functions/catalog-functions/export-tables/&#34;&gt;exported&lt;/a&gt; as &lt;code&gt;ALTER TABLE&lt;/code&gt; statements.&lt;/p&gt;
&lt;p&gt;For example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT EXPORT_TABLES(&amp;#39;&amp;#39;,&amp;#39;prod_dimension&amp;#39;);
...
CREATE TABLE public.prod_dimension
(
    product_key int NOT NULL,
    product_version int NOT NULL,
    product_description varchar(128),
    sku_number char(32) NOT NULL,
    category_description char(32),
    CONSTRAINT C_UNIQUE UNIQUE (sku_number) DISABLED,
    CONSTRAINT pk PRIMARY KEY (product_key, product_version) ENABLED,
    CONSTRAINT u_product_versions UNIQUE (product_version) ENABLED
);
(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Dropping constraints</title>
      <link>/en/admin/constraints/dropping-constraints/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/constraints/dropping-constraints/</guid>
      <description>
        
        
        &lt;p&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; drops constraints from tables in two ways:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#DropConstraint&#34;&gt;ALTER TABLE...DROP CONSTRAINT&lt;/a&gt;&lt;/code&gt; removes a named table constraint.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#AlterColumn&#34;&gt;ALTER TABLE...ALTER COLUMN&lt;/a&gt;&lt;/code&gt; removes a column&#39;s &lt;code&gt;NOT NULL&lt;/code&gt; constraint.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, table &lt;code&gt;store_orders_2018&lt;/code&gt; specifies the following constraints:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Named constraint &lt;code&gt;pk&lt;/code&gt; identifies column &lt;code&gt;order_no&lt;/code&gt; as a primary key.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Named constraint &lt;code&gt;IsYear2018&lt;/code&gt; specifies a check constraint that allows only 2018 dates in column &lt;code&gt;order_date&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Named constraint &lt;code&gt;Ship5dAfterOrder&lt;/code&gt; specifies a check constraint that disallows any &lt;code&gt;ship_date&lt;/code&gt; value that is more than 5 days after &lt;code&gt;order_date&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Columns &lt;code&gt;order_no&lt;/code&gt; and &lt;code&gt;order_date&lt;/code&gt; are set to &lt;code&gt;NOT NULL&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;CREATE TABLE public.store_orders_2018 (
    order_no int NOT NULL CONSTRAINT pk PRIMARY KEY,
    product_key int,
    product_version int,
    order_date timestamp NOT NULL,
    shipper varchar(20),
    ship_date date,
    CONSTRAINT IsYear2018 CHECK (DATE_PART(&amp;#39;year&amp;#39;, order_date)::int = 2018),
    CONSTRAINT Ship5dAfterOrder CHECK (DAYOFYEAR(ship_date) - DAYOFYEAR(order_date) &amp;lt;=5)
);
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;dropping-named-constraints&#34;&gt;Dropping named constraints&lt;/h2&gt;
&lt;p&gt;You remove primary, foreign key, check, and unique constraints with 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#DropConstraint&#34;&gt;ALTER TABLE...DROP CONSTRAINT&lt;/a&gt;&lt;/code&gt;, which requires you to supply their names. For example, you remove the primary key constraint in table &lt;code&gt;store_orders_2018&lt;/code&gt; as follows:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE store_orders_2018 DROP CONSTRAINT pk;
ALTER TABLE
=&amp;gt; SELECT export_tables(&amp;#39;&amp;#39;,&amp;#39;store_orders_2018&amp;#39;);
                                                             export_tables
---------------------------------------------------------------------------------------------------------------------------------------

CREATE TABLE public.store_orders_2018
(
    order_no int NOT NULL,
    product_key int,
    product_version int,
    order_date timestamp NOT NULL,
    shipper varchar(20),
    ship_date date,
    CONSTRAINT IsYear2018 CHECK (((date_part(&amp;#39;year&amp;#39;, store_orders_2018.order_date))::int = 2018)) ENABLED,
    CONSTRAINT Ship5dAfterOrder CHECK (((dayofyear(store_orders_2018.ship_date) - dayofyear(store_orders_2018.order_date)) &amp;lt;= 5)) ENABLED
);
&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;
&lt;p&gt;If you do not explicitly name a constraint, OpenText™ Analytics Database &lt;a href=&#34;../../../en/admin/constraints/naming-constraints/#Automati&#34;&gt;assigns its own name&lt;/a&gt;. You can obtain all constraint names from the database catalog with
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/catalog-functions/export-tables/#&#34;&gt;EXPORT_TABLES&lt;/a&gt;&lt;/code&gt;, or by querying the following system tables:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/constraint-columns/#&#34;&gt;CONSTRAINT_COLUMNS&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/table-constraints/#&#34;&gt;TABLE_CONSTRAINTS&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/primary-keys/#&#34;&gt;PRIMARY_KEYS&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;/div&gt;
&lt;h2 id=&#34;dropping-not-null-constraints&#34;&gt;Dropping NOT NULL constraints&lt;/h2&gt;
&lt;p&gt;You drop a column&#39;s &lt;code&gt;NOT NULL&lt;/code&gt; constraint with 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#AlterColumn&#34;&gt;ALTER TABLE...ALTER COLUMN&lt;/a&gt;&lt;/code&gt;, as in the following example:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE store_orders_2018 ALTER COLUMN order_date DROP NOT NULL;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;dropping-primary-keys&#34;&gt;Dropping primary keys&lt;/h2&gt;
&lt;p&gt;You cannot drop a primary key constraint if another table has a foreign key constraint that references the primary key. To drop the primary key, you must first drop all foreign keys that reference it.&lt;/p&gt;
&lt;h2 id=&#34;dropping-constraint-referenced-columns&#34;&gt;Dropping constraint-referenced columns&lt;/h2&gt;
&lt;p&gt;If you try to drop a column that is referenced by a constraint in the same table, the drop operation returns with an error. For example, check constraint &lt;code&gt;Ship5dAfterOrder&lt;/code&gt; references two columns, &lt;code&gt;order_date&lt;/code&gt; and &lt;code&gt;ship_date&lt;/code&gt;. If you try to drop either column, the database returns the following error message:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE public.store_orders_2018 DROP COLUMN ship_date;
ROLLBACK 3128:  DROP failed due to dependencies
DETAIL:
Constraint Ship5dAfterOrder references column ship_date
HINT:  Use DROP .. CASCADE to drop or modify the dependent objects
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;In this case, you must qualify the &lt;code&gt;DROP COLUMN&lt;/code&gt; clause with the &lt;code&gt;CASCADE&lt;/code&gt; option, which specifies to drop the column and its dependent objects—in this case, constraint &lt;code&gt;Ship5dAfterOrder&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE public.store_orders_2018 DROP COLUMN ship_date CASCADE;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;A call to the database function &lt;code&gt;EXPORT_TABLES&lt;/code&gt; confirms that the column and the constraint were both removed:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE public.store_orders_2018 DROP COLUMN ship_date CASCADE;
ALTER TABLE
dbadmin=&amp;gt; SELECT export_tables(&amp;#39;&amp;#39;,&amp;#39;store_orders_2018&amp;#39;);
                                              export_tables
---------------------------------------------------------------------------------------------------------

CREATE TABLE public.store_orders_2018
(
    order_no int NOT NULL,
    product_key int,
    product_version int,
    order_date timestamp,
    shipper varchar(20),
    CONSTRAINT IsYear2018 CHECK (((date_part(&amp;#39;year&amp;#39;, store_orders_2018.order_date))::int = 2018)) ENABLED
);

(1 row)
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Naming constraints</title>
      <link>/en/admin/constraints/naming-constraints/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/constraints/naming-constraints/</guid>
      <description>
        
        
        &lt;p&gt;The following constraints must be named.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;PRIMARY KEY&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;REFERENCES&lt;/code&gt; (foreign key)&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;CHECK&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;UNIQUE&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;You name these constraints when you define them. If you omit assigning a name, OpenText™ Analytics Database automatically assigns one.&lt;/p&gt;
&lt;h2 id=&#34;user-assigned-constraint-names&#34;&gt;User-assigned constraint names&lt;/h2&gt;
&lt;p&gt;You assign names to constraints when you define them with 
&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; or 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#AddConstraint&#34;&gt;ALTER TABLE...ADD CONSTRAINT&lt;/a&gt;&lt;/code&gt;. For example, the following &lt;code&gt;CREATE TABLE&lt;/code&gt; statement names primary key and check constraints &lt;code&gt;pk&lt;/code&gt; and &lt;code&gt;date_c&lt;/code&gt;, respectively:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE public.store_orders_2016
(
    order_no int CONSTRAINT pk PRIMARY KEY,
    product_key int,
    product_version int,
    order_date timestamp NOT NULL,
    shipper varchar(20),
    ship_date date,
    CONSTRAINT date_c CHECK (date_part(&amp;#39;year&amp;#39;, order_date)::int = 2016)
)
PARTITION BY ((date_part(&amp;#39;year&amp;#39;, order_date))::int);
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following &lt;code&gt;ALTER TABLE&lt;/code&gt; statement adds foreign key constraint &lt;code&gt;fk&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE public.store_orders_2016 ADD CONSTRAINT fk
    FOREIGN KEY (product_key, product_version)
    REFERENCES public.product_dimension (product_key, product_version);
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;&lt;a name=&#34;Automati&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;auto-assigned-constraint-names&#34;&gt;Auto-assigned constraint names&lt;/h2&gt;
&lt;p&gt;Naming a constraint is optional. If you omit assigning a name to a constraint, the database assigns its own name using the following convention:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;C_&lt;span class=&#34;code-variable&#34;&gt;constraint-type&lt;/span&gt;[_&lt;span class=&#34;code-variable&#34;&gt;integer&lt;/span&gt;]
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;For example, the following table defines two columns &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt; and constrains them to contain unique values:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; CREATE TABLE t1 (a int UNIQUE, b int UNIQUE );
CREATE TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;When you export the table&#39;s DDL with 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/catalog-functions/export-tables/#&#34;&gt;EXPORT_TABLES&lt;/a&gt;&lt;/code&gt;, the function output shows that database assigned constraint names &lt;code&gt;C_UNIQUE&lt;/code&gt; and &lt;code&gt;C_UNIQUE_1&lt;/code&gt; to columns &lt;code&gt;a&lt;/code&gt; and &lt;code&gt;b&lt;/code&gt;, respectively:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; SELECT EXPORT_TABLES(&amp;#39;&amp;#39;,&amp;#39;t1&amp;#39;);
CREATE TABLE public.t1
(
    a int,
    b int,
    CONSTRAINT C_UNIQUE UNIQUE (a) DISABLED,
    CONSTRAINT C_UNIQUE_1 UNIQUE (b) DISABLED
);

(1 row)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;viewing-constraint-names&#34;&gt;Viewing constraint names&lt;/h2&gt;
&lt;p&gt;You can view the names of table constraints by exporting the table&#39;s DDL with 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/catalog-functions/export-tables/#&#34;&gt;EXPORT_TABLES&lt;/a&gt;&lt;/code&gt;, as shown earlier. You can also query the following system tables:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/constraint-columns/#&#34;&gt;CONSTRAINT_COLUMNS&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/table-constraints/#&#34;&gt;TABLE_CONSTRAINTS&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/system-tables/v-catalog-schema/primary-keys/#&#34;&gt;PRIMARY_KEYS&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, the following query gets the names of all primary and foreign key constraints in schema &lt;code&gt;online_sales&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; SELECT table_name, constraint_name, column_name, constraint_type FROM constraint_columns
     WHERE constraint_type in (&amp;#39;p&amp;#39;,&amp;#39;f&amp;#39;) AND table_schema=&amp;#39;online_sales&amp;#39;
     ORDER BY table_name, constraint_type, constraint_name;
      table_name       |      constraint_name      |   column_name   | constraint_type
-----------------------+---------------------------+-----------------+-----------------
 call_center_dimension | C_PRIMARY                 | call_center_key | p
 online_page_dimension | C_PRIMARY                 | online_page_key | p
 online_sales_fact     | fk_online_sales_cc        | call_center_key | f
 online_sales_fact     | fk_online_sales_customer  | customer_key    | f
 online_sales_fact     | fk_online_sales_op        | online_page_key | f
 online_sales_fact     | fk_online_sales_product   | product_version | f
 online_sales_fact     | fk_online_sales_product   | product_key     | f
 online_sales_fact     | fk_online_sales_promotion | promotion_key   | f
 online_sales_fact     | fk_online_sales_saledate  | sale_date_key   | f
 online_sales_fact     | fk_online_sales_shipdate  | ship_date_key   | f
 online_sales_fact     | fk_online_sales_shipping  | shipping_key    | f
 online_sales_fact     | fk_online_sales_warehouse | warehouse_key   | f
(12 rows)
&lt;/code&gt;&lt;/pre&gt;&lt;h2 id=&#34;using-constraint-names&#34;&gt;Using constraint names&lt;/h2&gt;
&lt;p&gt;You must reference a constraint name in order to perform the following tasks:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Enable or disable constraint enforcement.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Drop a constraint.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;For example, the following &lt;code&gt;ALTER TABLE&lt;/code&gt; statement enables enforcement of constraint &lt;code&gt;pk&lt;/code&gt; in table &lt;code&gt;store_orders_2016&lt;/code&gt;:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;
=&amp;gt; ALTER TABLE public.store_orders_2016 ALTER CONSTRAINT pk ENABLED;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;&lt;p&gt;The following statement drops another constraint in the same table:&lt;/p&gt;
&lt;pre tabindex=&#34;0&#34;&gt;&lt;code&gt;=&amp;gt; ALTER TABLE public.store_orders_2016 DROP CONSTRAINT date_c;
ALTER TABLE
&lt;/code&gt;&lt;/pre&gt;
      </description>
    </item>
    
    <item>
      <title>Admin: Detecting constraint violations</title>
      <link>/en/admin/constraints/detecting-constraint-violations/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/constraints/detecting-constraint-violations/</guid>
      <description>
        
        
        &lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/table-functions/analyze-constraints/#&#34;&gt;ANALYZE_CONSTRAINTS&lt;/a&gt;&lt;/code&gt; analyzes and reports on table constraint violations within a given schema. You can use &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; to analyze an individual table, specific columns within a table, or all tables within a schema. You typically use this function on tables where primary key, unique, or check constraints are not enforced. You can also use &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; to check the referential integrity of foreign keys.&lt;/p&gt;
&lt;p&gt;In the simplest use case, &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; is a two-step process:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Run &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; on the desired table. &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; reports all rows that violate constraints.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the report to fix violations.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;You can also use &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; in the following cases:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Analyze tables with enforced constraints.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Detect constraint violations introduced by a &lt;code&gt;COPY&lt;/code&gt; operation and address them before the copy transaction is committed.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;analyzing-tables-with-enforced-constraints&#34;&gt;Analyzing tables with enforced constraints&lt;/h2&gt;
&lt;p&gt;If constraints are enforced on a table and a DML operation returns constraint violations, OpenText™ Analytics Database reports on a limited number of constraint violations before it rolls back the operation. This can be problematic when you try to load a large amount of data that includes many constraint violations—for example, duplicate key values. In this case, use &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Temporarily disable enforcement of all constraints on the target table.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Run the DML operation.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;After the operation returns, run &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; on the table. &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; reports all rows that violate constraints.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the report to fix the violations.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Re-enable constraint enforcement on the table.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;h2 id=&#34;using-analyze_constraints-in-a-copy-transaction&#34;&gt;Using ANALYZE_CONSTRAINTS in a COPY transaction&lt;/h2&gt;
&lt;p&gt;Use &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; to detect and address constraint violations introduced by a 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/copy/#&#34;&gt;COPY&lt;/a&gt;&lt;/code&gt; operation as follows:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Copy the source data into the target table with &lt;code&gt;COPY...NO COMMIT&lt;/code&gt;.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Call &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; to check the target table with its uncommitted updates.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;If &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; reports constraint violations, roll back the copy transaction.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Use the report to fix the violations, and then re-execute the copy operation.&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;For details about using &lt;code&gt;COPY...NO COMMIT&lt;/code&gt;, see &lt;a href=&#34;../../../en/data-load/using-transactions-to-stage-load/#&#34;&gt;Using transactions to stage a load&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;Distribu&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;distributing-constraint-analysis&#34;&gt;Distributing constraint analysis&lt;/h2&gt;
&lt;p&gt;&lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; runs as an atomic operation—that is, it does not return until it evaluates all constraints within the specified scope. For example, if you run &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; against a table, the function returns only after it evaluates all column constraints against column data. If the table has a large number of columns with constraints, and contains a very large data set, &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; is liable to exhaust all available memory and return with an out-of-memory error. This risk is increased by running &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; against multiple tables simultaneously, or against the entire database.&lt;/p&gt;
&lt;p&gt;You can minimize the risk of out-of-memory errors by setting configuration parameter &lt;a href=&#34;../../../en/sql-reference/config-parameters/constraints-parameters/&#34;&gt;MaxConstraintChecksPerQuery&lt;/a&gt; (by default set to -1) to a positive integer. For example, if this parameter is set to 20, and you run &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; on a table that contains 38 column constraints, the function divides its work into two separate queries. &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; creates a temporary table for loading and compiling results from the two queries, and then returns the composite result set.&lt;/p&gt;
&lt;p&gt;MaxConstraintChecksPerQuery can only be set at the database level, and can incur a certain amount of overhead. When set, commits to the temporary table created by &lt;code&gt;ANALYZE_CONSTRAINTS&lt;/code&gt; cause all pending database transactions to auto-commit. Setting this parameter to a reasonable number such as 20 should minimize its performance impact.&lt;/p&gt;

      </description>
    </item>
    
    <item>
      <title>Admin: Constraint enforcement</title>
      <link>/en/admin/constraints/constraint-enforcement/</link>
      <pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
      
      <guid>/en/admin/constraints/constraint-enforcement/</guid>
      <description>
        
        
        &lt;p&gt;You can enforce the following constraints:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;PRIMARY KEY&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;UNIQUE&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;code&gt;CHECK&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;When you enable constraint enforcement on a table, OpenText™ Analytics Database applies that constraint immediately to the table&#39;s current content, and to all content that is added or updated later.&lt;/p&gt;
&lt;p&gt;&lt;a name=&#34;OperationsInvokeEnforcement&#34;&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2 id=&#34;operations-that-invoke-constraint-enforcement&#34;&gt;Operations that invoke constraint enforcement&lt;/h2&gt;
&lt;p&gt;The following DDL and DML operations invoke constraint enforcement:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#AddConstraint&#34;&gt;ALTER TABLE...ADD CONSTRAINT&lt;/a&gt;&lt;/code&gt; and 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/alter-statements/alter-table/#AlterConstraint&#34;&gt;ALTER TABLE...ALTER CONSTRAINT&lt;/a&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/insert/#&#34;&gt;INSERT&lt;/a&gt;&lt;/code&gt; and 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/insert/#InsertSelect&#34;&gt;INSERT...SELECT&lt;/a&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/copy/#&#34;&gt;COPY&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/update/#&#34;&gt;UPDATE&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;

&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/statements/merge/#&#34;&gt;MERGE&lt;/a&gt;&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Partitioning functions: &lt;br /&gt;- 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/partition-functions/copy-partitions-to-table/#&#34;&gt;COPY_PARTITIONS_TO_TABLE&lt;/a&gt;&lt;/code&gt;&lt;br /&gt;- 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/partition-functions/move-partitions-to-table/#&#34;&gt;MOVE_PARTITIONS_TO_TABLE&lt;/a&gt;&lt;/code&gt;&lt;br /&gt;- 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/partition-functions/swap-partitions-between-tables/#&#34;&gt;SWAP_PARTITIONS_BETWEEN_TABLES&lt;/a&gt;&lt;/code&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id=&#34;benefits-and-costs&#34;&gt;Benefits and costs&lt;/h2&gt;
&lt;p&gt;Enabling constraint enforcement can help minimize post-load maintenance tasks, such as validating data separately with 
&lt;code&gt;&lt;a href=&#34;../../../en/sql-reference/functions/management-functions/table-functions/analyze-constraints/#&#34;&gt;ANALYZE_CONSTRAINTS&lt;/a&gt;&lt;/code&gt;, and then dealing with the constraint violations that it returns.&lt;/p&gt;
&lt;p&gt;Enforcing key constraints, particularly on primary keys, can help the optimizer produce faster query plans, particularly for joins. When a primary key constraint is enforced on a table, the optimizer assumes that no rows in that table contain duplicate key values.&lt;/p&gt;
&lt;p&gt;Under certain circumstances, widespread constraint enforcement, especially in large fact tables, can incur significant system overhead. For details, see &lt;a href=&#34;../../../en/admin/constraints/constraint-enforcement/constraint-enforcement-and-performance/#&#34;&gt;Constraint enforcement and performance&lt;/a&gt;.&lt;/p&gt;

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