informix
Informix Guide to SQL: Syntax
SQL Statements

START VIOLATIONS TABLE

Use the START VIOLATIONS TABLE statement to create a violations table and a diagnostics table for a specified target table. The database server associates the violations and diagnostics tables with the target table by recording the relationship among the three tables in the sysviolations system catalog table.

In Enterprise Decision Server, the START VIOLATIONS TABLE statement creates a violations table but not a diagnostics table.

Syntax

Element Purpose Restrictions Syntax
diagnostics Name of the diagnostics table to be associated with the target table The name of the diagnostics table cannot match the name of any existing table in the database. Database Object Name, p. 4-50
num_rows Maximum number of rows that the database server can insert into the diagnostics table when a single statement is executed on the target table (IDS) Maximum number of rows that any single coserver can insert into the violations table when a single statement is executed on the target table (EDS) The value that you specify must be an integer in the range from 1 to the maximum value of the INTEGER data type. Literal Number, p. 4-237
table Name of the target table for which a violations table and diagnostics table are to be created If you do not include the USING clause in the statement, the name of the target table must be 124 characters or less (IDS). If you do not include the USING clause in the statement, the name of the target table must be 14 characters or less (EDS). The target table cannot have a violations and diagnostics table associated with it before you execute the statement. The target table cannot be a system catalog table. The target table must be a local table. Database Object Name, p. 4-50
violations Name of the violations table to be associated with the target table The name of the violations table cannot match the name of any existing table in the database. Database Object Name, p. 4-50

Usage

The START VIOLATIONS TABLE statement creates the special violations table that holds rows that fail to satisfy constraints and unique indexes during insert, update, and delete operations on target tables. This statement also creates the special diagnostics table that contains information about the integrity violations caused by each row in the violations table.

In Enterprise Decision Server, the START VIOLATIONS TABLE statement creates a violations table but not a diagnostics table.

Relationship of START VIOLATIONS TABLE and SET Database Object Mode Statements

The START VIOLATIONS TABLE statement is closely related to the SET Database Object Mode statement. If you use the SET Database Object Mode statement to set the constraints or unique indexes defined on a table to the filtering database object mode, but you do not use the START VIOLATIONS TABLE statement to start the violations and diagnostics tables for this target table, any rows that violate a constraint or unique-index requirement during an insert, update, or delete operation are not filtered out to a violations table. Instead you receive an error message indicating that you must start a violations table for the target table.

Similarly, if you use the SET Database Object Mode statement to set a disabled constraint or disabled unique index to the enabled or filtering database object mode, but you do not use the START VIOLATIONS TABLE statement to start the violations and diagnostics tables for the table on which the database objects are defined, any existing rows in the table that do not satisfy the constraint or unique-index requirement are not filtered out to a violations table. If, in these cases, you want the ability to identify existing rows that do not satisfy the constraint or unique-index requirement, you must issue the START VIOLATIONS TABLE statement to start the violations and diagnostics tables before you issue the SET Database Object Mode statement to set the database objects to the enabled or filtering database object mode.

In Enterprise Decision Server, the SET Database Object Mode statement is not supported, and the concept of database object modes does not exist. Instead, once you use the START VIOLATIONS TABLE statement to create a violations table and associate it with a target table, the existence of this violations table causes all violations of constraints and unique-index requirements by insert, delete, and update operations to be recorded in the violations table.

In other words, once you issue a START VIOLATIONS TABLE statement, all constraints and unique indexes in a database on Enterprise Decision Server behave like filtering-mode constraints and filtering-mode unique indexes in a database on Dynamic Server. For an explanation of the behavior of filtering-mode constraints and filtering-mode unique indexes, see Filtering Mode.

Effect of Violations Table on Concurrent Transactions

A transaction must issue the START VIOLATIONS TABLE statement in isolation. That is, no other transaction can be in progress on a target table when a transaction issues a START VIOLATIONS TABLE statement on that table. However, any transactions that start on the target table after the first transaction has issued the START VIOLATIONS TABLE statement will behave the same way as the first transaction with respect to the violations and diagnostics tables. That is, any constraint and unique-index violations by these subsequent transactions will be recorded in the violations and diagnostics tables.

For example, if transaction A operates on table tab1 and issues a START VIOLATIONS TABLE statement on table tab1, the database server starts a violations table named tab1_vio and filters any constraint or unique-index violations on table tab1 by transaction A to table tab1_vio. If transactions B and C start on table tab1 after transaction A has issued the START VIOLATiONS TABLE statement, the database server also filters any constraint and unique-index violations by transactions B and C to table tab1_vio.

However, the result is that all three transactions do not receive error messages about constraint and unique-index violations even though transactions B and C do not expect this behavior. For example, if transaction B issues an INSERT or UPDATE statement that violates a check constraint on table tab1, the database server does not issue a constraint violation error to transaction B. Instead, the database server filters the bad row to the violations table without notifying transaction B that a data-integrity violation occurred.

You can prevent this situation from arising in Dynamic Server by specifying the WITH ERRORS option when you set database objects to the FILTERING mode in a SET Database Object Mode, CREATE TABLE, ALTER TABLE, or CREATE INDEX statement. When multiple transactions operate on a table and the WITH ERRORS option is in effect, any transaction that violates a constraint or unique-index requirement on a target table receives a data-integrity error message.

In Enterprise Decision Server, once a transaction issues a START VIOLATIONS TABLE statement, you have no way to make the database server issue data-integrity violation messages to that transaction or to any other transactions that start subsequently on the same target table.

Stopping the Violations and Diagnostics Tables

After you use a START VIOLATIONS TABLE statement to create an association between a target table and the violations and diagnostics tables, the only way to drop the association between the target table and the violations and diagnostics tables is to issue a STOP VIOLATIONS TABLE statement for the target table. For more information, see STOP VIOLATIONS TABLE.

USING Clause

You can use the USING clause to assign explicit names to the violations and diagnostics tables.

If you omit the USING clause, the database server assigns names to the violations and diagnostics tables. The system-assigned name of the violations table consists of the name of the target table followed by the string vio. The system-assigned name of the diagnostics table consists of the name of the target table followed by the string dia.

If you omit the USING clause, the maximum length of the target table is 124 characters.

You can use the USING clause to assign an explicit name to the violations table.

If you omit the USING clause, the database server assigns a name to the violations table. The system-assigned name of the violations table consists of the name of the target table followed by the string vio.

If you omit the USING clause, the maximum length of the target table is 14 characters.

Use of the MAX ROWS Clause

You can use the MAX ROWS clause to specify the maximum number of rows that the database server can insert into the diagnostics table when a single statement is executed on the target table.

If you do not include the MAX ROWS clause in the START VIOLATIONS TABLE statement, no upper limit exists on the number of rows that can be inserted into the diagnostics table when a single statement is executed on the target table.

Use of the MAX VIOLATIONS Clause

You can use the MAX VIOLATIONS clause to specify the maximum number of rows that any single coserver can insert into the violations table when a single statement is executed on the target table. Each coserver where the violations table resides has this limit. The first coserver to reach this limit raises an error and causes the statement to fail.

If you do not include the MAX VIOLATIONS clause in a START VIOLATIONS TABLE statement, no upper limit exists on the number of rows that can be inserted into the violations table when a single statement is executed on the target table.

Examples of START VIOLATIONS TABLE Statements

The following examples show different ways to execute the START VIOLATIONS TABLE statement.

Starting Violations and Diagnostics Tables Without Specifying Their Names

The following statement starts violations and diagnostics tables for the target table named cust_subset. The violations table is named cust_subset_vio by default, and the diagnostics table is named cust_subset_dia by default.

Starting Violations and Diagnostics Tables and Specifying Their Names

The following statement starts a violations and diagnostics table for the target table named items. The USING clause assigns explicit names to the violations and diagnostics tables. The violations table is to be named exceptions, and the diagnostics table is to be named reasons.

Specifying the Maximum Number of Rows in the Diagnostics Table

The following statement starts violations and diagnostics tables for the target table named orders. The MAX ROWS clause specifies the maximum number of rows that can be inserted into the diagnostics table when a single statement, such as an INSERT statement, is executed on the target table.

Specifying the Maximum Number of Rows in the Violations Table

The following statement starts a violations table for the target table named orders. The MAX VIOLATIONS clause specifies the maximum number of rows that any single coserver can insert into the violations table when a single statement, such as an INSERT statement, is executed on the target table.

Privileges Required for Starting Violations Tables

To start a violations and diagnostics table for a target table, you must meet one of the following requirements:

Structure of the Violations Table

When you issue a START VIOLATIONS TABLE statement for a target table, the violations table that the statement creates has a predefined structure. This structure consists of the columns of the target table and three additional columns.

The following table shows the structure of the violations table.

Column Name Type Purpose
Same columns as the target table, in the same order that they appear in the target table These columns of the violations table match the data type of the corresponding columns in the target table, except that SERIAL columns in the target table are converted to INTEGER data types in the violations table. Table definition of the target table is reproduced in the violations table so that rows that violate constraints or unique-index requirements during insert, update, and delete operations can be filtered to the violations table. Users can examine these bad rows in the violations table, analyze the related rows that contain diagnostics information in the diagnostics table, and take corrective actions.
informix_tupleid SERIAL Contains the unique serial identifier that is assigned to the nonconforming row.
informix_optype CHAR(1) Indicates the type of operation that caused this bad row. This column can have the following values:
I = Insert

D = Delete

O = Update (with this row containing the original values)
N = Update (with this row containing the new values)
S = SET Database Object Mode statement (IDS)
informix_recowner CHAR(8) Identifies the user who issued the statement that created this bad row.

Relationship Between the Violations and Diagnostics Tables

Users can take advantage of the relationships among the target table, violations table, and diagnostics table to obtain complete diagnostic information about rows that have caused data-integrity violations during INSERT, DELETE, and UPDATE statements.

Each row of the violations table has at least one corresponding row in the diagnostics table. The row in the violations table contains a copy of the row in the target table for which a data-integrity violation was detected. The row in the diagnostics table contains information about the nature of the data-integrity violation caused by the bad row in the violations table. The row in the violations table has a unique serial identifier in the informix_tupleid column. The row in the diagnostics table has the same serial identifier in its informix_tupleid column.

A given row in the violations table can have more than one corresponding row in the diagnostics table. The multiple rows in the diagnostics table all have the same serial identifier in their informix_tupleid column so that they are all linked to the same row in the violations table. Multiple rows can exist in the diagnostics table for the same row in the violations table because a bad row in the violations table can cause more than one data-integrity violation.

For example, a bad row can violate a unique-index requirement for one column, a not-null constraint for another column, and a check constraint for yet another column. In this case, the diagnostics table contains three rows for the single bad row in the violations table. Each of these diagnostic rows identifies a different data-integrity violation that the nonconforming row in the violations table caused.

By joining the violations and diagnostics tables, the DBA or target-table owner can obtain complete diagnostic information about any or all bad rows in the violations table. You can use SELECT statements to perform these joins interactively, or you can write a program to perform them within transactions.

Initial Privileges on the Violations Table

When you issue the START VIOLATIONS TABLE statement to create the violations table, the database server uses the set of privileges granted on the target table as a basis for granting privileges on the violations table. However, the database server follows different rules when it grants each type of privilege.

The following table explains the circumstances under which the database server grants each privilege on the violations table. The first column lists each privilege. The second column explains the conditions under which the database server grants that privilege to a user.

Privilege Condition for Granting the Privilege
Insert User has the Insert privilege on the violations table if the user has any of the following privileges on the target table: the Insert privilege, the Delete privilege, or the Update privilege on any column.
Delete User has the Delete privilege on the violations table if the user has any of the following privileges on the target table: the Insert privilege, the Delete privilege, or the Update privilege on any column.
Select User has the Select privilege on the informix_tupleid, informix_optype, and informix_recowner columns of the violations table if the user has the Select privilege on any column of the target table.
User has the Select privilege on any other column of the violations table if the user has the Select privilege on the same column in the target table.
Update User has the Update privilege on the informix_tupleid, informix_optype, and informix_recowner columns of the violations table if the user has the Update privilege on any column of the target table.
However, even if the user has the Update privilege on the informix_tupleid column, the user cannot update this column because this column is a SERIAL column.
User has the Update privilege on any other column of the violations table if the user has the Update privilege on the same column in the target table.
Index User has the Index privilege on the violations table if the user has the Index privilege on the target table.
The user cannot create a globally detached index on the violations table even if the user has the Index privilege on the violations table (EDS).
Alter Alter privilege is not granted on the violations table. (Users cannot alter violations tables.)
References References privilege is not granted on the violations table. (Users cannot add referential constraints to violations tables.)

The following rules apply to ownership of the violations table and privileges on the violations table:

Example of Privileges on the Violations Table

The following example illustrates how the initial set of privileges on a violations table is derived from the current set of privileges on the target table.

For example, assume that you have a table named cust_subset that holds customer data. This table consists of the following columns: ssn (customer social security number), fname (customer first name), lname (customer last name), and city (city in which the customer lives).

The following set of privileges exists on the cust_subset table:

Now user alvin starts a violations table named cust_subset_viols and a diagnostics table named cust_subset_diags for the cust_subset table, as follows:

The database server grants the following set of initial privileges on the cust_subset_viols violations table:

Using the Violations Table

The following rules concern the structure and use of the violations table:

Example of a Violations Table

To start a violations and diagnostics table for the target table named customer in the demonstration database, enter the following statement:

Because your START VIOLATIONS statement does not include a USING clause, the violations table is named customer_vio by default. The customer_vio table includes the following columns:

The customer_vio table has the same table definition as the customer table except that the customer_vio table has three additional columns that contain information about the operation that caused the bad row.

Structure of the Diagnostics Table

When you issue a START VIOLATIONS TABLE statement for a target table, the diagnostics table that the statement creates has a predefined structure. This structure is independent of the structure of the target table.

The following table shows the structure of the diagnostics table.

Column Name Type Purpose
informix_tupleid INTEGER Implicitly refers to the values in the informix_tupleid column in the violations table However, this relationship is not declared as a foreign-key to primary-key relationship.
objtype CHAR(1) Identifies the type of the violation This column can have the following values.
C = Constraint violation
I = Unique-index violation
objowner CHAR(8) Identifies the owner of the constraint or index for which an integrity violation was detected.
objname CHAR(18) Contains the name of the constraint or index for which an integrity violation was detected.

Initial Privileges on the Diagnostics Table

When the START VIOLATIONS TABLE statement creates the diagnostics table, the database server uses the set of privileges granted on the target table as a basis for granting privileges on the diagnostics table. However, the database server follows different rules when it grants each type of privilege.

The following table explains the circumstances under which the database server grants each privilege on the diagnostics table. The first column lists each privilege. The second column explains the conditions under which the database server grants that privilege to a user.

Privilege Condition for Granting the Privilege
Insert User has the Insert privilege on the diagnostics table if the user has any of the following privileges on the target table: the Insert privilege, the Delete privilege, or the Update privilege on any column
Delete User has the Delete privilege on the diagnostics table if the user has any of the following privileges on the target table: the Insert privilege, the Delete privilege, or the Update privilege on any column
Select User has the Select privilege on the diagnostics table if the user has the Select privilege on any column in the target table
Update User has the Update privilege on the diagnostics table if the user has the Update privilege on any column in the target table
Index User has the Index privilege on the diagnostics table if the user has the Index privilege on the target table
Alter Alter privilege is not granted on the diagnostics table (Users cannot alter diagnostics tables.)
References References privilege is not granted on the diagnostics table (Users cannot add referential constraints to diagnostics tables.)

The following rules concern privileges on the diagnostics table:

Example of Privileges on the Diagnostics Table

The following example illustrates how the initial set of privileges on a diagnostics table is derived from the current set of privileges on the target table.

For example, assume that you have a table called cust_subset that holds customer data. This table consists of the following columns: ssn (social security number), fname (first name), lname (last name), and city (city in which the customer lives).

The following set of privileges exists on the cust_subset table:

Now user alvin starts a violations table named cust_subset_viols and a diagnostics table named cust_subset_diags for the cust_subset table, as follows:

The database server grants the following set of initial privileges on the cust_subset_diags diagnostics table:

Using the Diagnostics Table

For information on the relationship between the diagnostics table and the violations table, see Relationship Between the Violations and Diagnostics Tables.

The following issues concern the structure and use of the diagnostics table:

Example of a Diagnostics Table

To start a violations and diagnostics table for the target table named stock in the demonstration database, enter the following statement:

Because your START VIOLATIONS TABLE statement does not include a USING clause, the diagnostics table is named stock_dia by default. The stock_dia table includes the following columns:

This list of columns shows an important difference between the diagnostics table and violations table for a target table. Whereas the violations table has a matching column for every column in the target table, the columns of the diagnostics table do not match any columns in the target table. The diagnostics table created by any START VIOLATIONS TABLE statement always has the same columns with the same column names and data types.

Related Information

Related statements: SET Database Object Mode and STOP VIOLATIONS TABLE

For a discussion of object modes and violation detection, see the Informix Guide to SQL: Tutorial.


Informix Guide to SQL: Syntax, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved