In: Computer Science
1- How can database systems improve data quality and data integrity?
2- Discuss database constraints: Primary key, check, and referential integrity constraints? Give an example for each.
Answers
1.
To ensure data integrity we have to follow few measurements as
follows :
a. Input validation to preclude the entering of invalid data.
b. Data detection and validation to indicate errors in data
transmission.
c. Other methodology such as databse access control which
authorizes access permission to specified persons only,
data loss prevention to ensure data quality, data encryption to
fulfill integrity,etc.
2. Primary key is the minimal set of attributes from the candidate key,by which we can uniquely identify and access any tuple from the database.
ex : Suppose we have a student database consists of roll no,dob,standard,grades,phone no,email.
In between all the attributes a student can be uniquely identified by the attribute roll no because it is unqiue for all the students,there by it can be the minimal candidate key for the database.
CHECK constraint limits the values in
attributes based on values in other columns in the tuple and
ensures
the value range that can be placed in a column.
ex : CREATE TABLE Student (Roll_No int NOT NULL,Name varchar(30) NOT NULL,Subject varchar(30),Age int,CHECK (Age>=12));
In the above CREATE table command the CHECK constraint will cross check the ages are greater than or equal to 12 or not before inserting the values into the table.
Referential Integrity maintains the connection or relational objective in between two relational schemas,where the primary key of one table can be placed as the foreign key in another table and this foreign can be null.
ex: Let us having two tables Student and Subject. If we have sub_id as foreign key in Student table than by using referential integrity constraints we can avoid creating Student without Subject or non existing Subject.