Data Constraints
Constraints are used to implement standard
and business rules. Data integrity of the database must be maintained. In order to ensure
data has integrity we have to implement certain rules or constraints. As these constraints are
used to maintain integrity they are called as integrity constraints.
Standard rules
Standard constraints are the rules related to primary key and foreign key. Every table must
have a primary key. Primary key must be unique and not null. Foreign key must derive its
values from corresponding parent key. These rules are universal and are called as standard
rules.
Business rules
These rules are related to a single application. For example, in a payroll application we may
have to implement a rule that prevents any row of an employee if salary of the employee is
less than 2000. Another example is current balance of a bank account
Must be greater than or equal to 500.
Once the constraints are created, Oracle server makes sure that the constraints are not
violated whenever a row is inserted, deleted or updated. If constraint is not satisfied then the
operation will fail.
Constraints are normally defined at the time of creating table. But it is also possible to add
constraints after the table is created using ALTER TABLE command. Constraints are stored in the Data Dictionary (a set of tables which stores information regarding database).
Each constraint has a name; it is either given by user using CONSTRAINT option or assigned
by system. In the later case, the name is SYS_Cn; where n is a number.
Note: It is recommended that you use constraint name so that referring to constraint will be
easier later on.
No comments:
Post a Comment