Collection Contents Index CHAPTER 14.  Ensuring Data Integrity Using column defaults pdf/chap14.pdf

User's Guide
   PART 2. Relational Database Concepts
     CHAPTER 14. Ensuring Data Integrity       

Data integrity overview


For data to have integrity means that the data is valid—correct and accurate—and that the relational structure of the database is intact. The relational structure of the database is enforced through referential integrity constraints. These are rules that maintain the consistency of data between tables.

Adaptive Server Anywhere supports stored procedures and JDBC, which allow you detailed control over how data gets entered into the database. You can also create triggers: custom procedures stored in the database that are invoked automatically when a certain action, such as an update of a particular column, is carried out.

For Info     Procedures and triggers are discussed in Using Procedures, Triggers, and Batches.

Top of page  How data can become invalid

Here are a few examples of how the data in a database may become invalid if proper checks are not made. Each of these examples can be prevented by facilities described in this chapter.

Incorrect information 

Duplicated data 

Foreign key relations invalidated 

Top of page  Integrity constraints belong in the database

In order to ensure that the data in a database are valid, you need to formulate checks that define valid and invalid data and design rules to which data must adhere. The rules to which data must conform are often called business rules. The collective name for checks and rules is constraints.

Build integrity constraints into database 

Constraints built into the database itself are inherently more reliable than those built into client applications, or spelled out as instructions to database users. Constraints built into the database are part of the definition of the database itself and enforced consistently across all applications.

Setting a constraint once, in the database, imposes it for all subsequent interactions with the database, no matter from what source. In contrast, constraints built into client applications are vulnerable every time the software is altered, and may need to be imposed in several applications, or several places in a single client application.

Top of page  How database contents get changed

Information in database tables is changed by submitting SQL statements from client applications. Only a few SQL statements actually modify the information in a database.

Top of page  Data integrity tools

To assist in maintaining data integrity, you can use defaults, data constraints, and constraints that maintain the referential structure of the database.

Defaults 

You can assign default values to columns, to make certain kinds of data entry more reliable. For example:

For Info     These and other column defaults are discussed in Using column defaults.

Constraints 

You can use several types of constraints on the data in individual columns or tables. For example:

These and other table and column constraints are discussed in Using table and column constraints. Column constraints can be inherited from user-defined data types.

Entity and referential integrity 

The information in relational database tables is tied together by the relations between tables. These relations are defined by the primary keys and foreign keys built in to the database design. The following integrity rules maintain the structure of the database:

For Info     For more information about enforcing referential integrity, see Enforcing entity and referential integrity. For more information about designing appropriate primary and foreign key relations, see Designing Your Database.

Triggers for advanced integrity rules 

You can also use triggers to maintain data integrity. A trigger is a procedure stored in the database that is executed automatically whenever the information in a specified table is altered. Triggers are a powerful mechanism for database administrators and developers to ensure that data is kept reliable.

For Info     For a full description of triggers, see Using Procedures, Triggers, and Batches.

Top of page  SQL statements for implementing integrity constraints

The following SQL statements are used to implement integrity constraints:

For Info     For full descriptions of the syntax of these statements, see SQL Statements.

Top of page  

Collection Contents Index CHAPTER 14.  Ensuring Data Integrity Using column defaults pdf/chap14.pdf