273
CHAPTER 7
Ensuring Data Integrity
About this chapter
This chapter describes facilities for ensuring that the data in your database
is valid and reliable. These facilities include constraints on tables and
columns, and choosing appropriate data types.
The SQL statements in this chapter use the CREATE TABLE statement
and ALTER TABLE statement, basic forms of which were introduced in
Chapter 3, “Working with Database Objects”
Data integrity overview
For data to have integrity means that the data is valid—that is, correct and
accurate—and that the relational structure of the database is intact. The
relational structure of the database is described through referential
integrity constraints, business rules that maintain the consistency of data
between tables.
Adaptive Server IQ supports stored procedures and JDBC, which allow
you detailed control over how data gets entered into the database.
Procedures are discussed in Chapter 6, “Using Procedures and Batches”
See the Adaptive Server Anywhere User’s Guide for information on JDBC.
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.
Incorrectly formatted
information
• An operator enters text where numeric data is required.
• An operator enters numeric data that is too wide for the column.
Duplicated data
• A new department has been created, with dept_id 200, and needs to
be added to the department table of the organization's database—but
two people enter this information into the table.