Unit2 General Notes
Unit2 General Notes
RELATION
Integrity constraints are used to ensure accuracy and
consistency of data in a relational database.
Domain Integrity-
CSE
EXAMPLE-
Consider 2 relations "stu" and "stu_1" Where "Stu_id " is the
primary key in the "stu" relation and foreign key in the "stu_1"
relation.
Relation "stu"
Examples
Rule 1. You can't delete any of the rows in the ”stu” relation that
are visible since all the ”stu” are in use in the “stu_1” relation.
Rule 2. You can't change any of the ”Stu_id” in the “stu”
relation since all the “Stu_id” are in use in the ”stu_1” relation.
* Rule 3.* The values that you can enter in the” Stu_id” field in
the “stu_1” relation must be in the” Stu_id” field in the “stu”
relation.
Rule 4 You can enter a null value in the "stu_1" relation if the
records are unrelated.
Key Constraints-
A Key Constraint is a statement that a certain minimal subset
of the fields of a relation is a unique identifier for a tuple. The
types of key constraints-
Unique Constraints
A unique column constraint in a table is similar to a primary
key in that the value in that column for every row of data in the
table must have a unique value. Although a primary key
constraint is placed on one column, you can place a unique
constraint on another column even though it is not actually for
use as the primary key.
. NOT NULL Constraints
SQL Views
A VIEW is a virtual table, through which a selective portion of the data from one or
more tables can be seen. Views do not contain data of their own. They are used to
restrict access to the database or to hide data complexity. A view is stored as a
SELECT statement in the database. DML operations on a view like INSERT,
UPDATE, DELETE affects the data in the original table upon which the view is
based.