Chapter 2 - Integrity Constraints Flashcards
What are integrity constraints?
Rules and conditions derived from real-world requirements and specified when defining or creating database schema
Why are integrity constraints necessary?
They help to ensure accuracy, consistency and validity of data in the DB.
They ensure that the stored data is faithful to the real-world meaning it represents
When are integrity constraints checked?
They are checked when modifications (insert, update, delete) are made to the relations in the DB.
This checking ensures that data modifications adhere to the specified constraints.
What happens when DBMS checks the database and sees that integrity constraints are violated?
DBMS may prevent modification or indicate an error
When do we consider a database legal?
When integrity constraints hold true for all data.
What are the 3 types of integrity constraints?
Domain constraints,
Key constraints,
Referential constraints
What are domain constraints? How is this done?
Domain constraints restrict the kind of attributes or values a column can hold in the DB table.
This is done by
1. Specifying data types
2. Specifying range of values: eg. age cannot be less than zero, telephone no cannot contain digit outside 0-9.
What are key constraints?
- We should only have ONE PRIMARY KEY.
- No two tuples should have the same value for primary key.
- Attribute in primary key cannot have NULL values.
What are relational integrity constraints? (REFERENTIAL CONSTRAINTS)
We must ensure that the reference from one table to another table must be valid.
- A foreign key must have a matching primary key.
- The reference key element (foreign key) must either either exist in the referenced table or be NULL
How do we preserve Integrity Constraints (ICs) in a relational database and how to ensure that these constraints are maintained.
- High-level database design: ICs should be modelled and defined at high-level database design stage, such as when creating an ER diagram. This involves specifying constraints like primary keys, foreign keys, unique constraints, and not null constraints using the design phase.
- Continuous evaluation: ICs should be evaluated continuously, especially during data modification operations like insert, update, delete or alteration of tables.
- SQL support for ICs: SQL provides various constructs and constraints for defining and enforcing ICs. Some examples include NOT NULL, CHECK, UNIQUE, PRIMARY KEY and FOREIGN KEY REFERENCES
Can we infer that an IC is true by looking at an instace?
NO. ICs are statements about all possible instances of a database, not just a single instance.
While you can use SQL constraints to enforce ICs, you cannot infer the truth of an IC solely by looking at a single instance of the DB. ICs are constraints that apply to the ENTIRE DATASET.
What do we communicate to DBMS?
- Defining the structure of the database. This includes creating, altering, dropping, truncating, commenting on, or renaming database objects such as tables, indexes, views, and more.
- Manipulating data.
You communicate with the DBMS to manipulate data within the database. Common data manipulation operations include SELECT (retrieving data), INSERT (adding new data), UPDATE (modifying existing data), DELETE (removing data), and more
How do we communicate with DBMS?
- Relational Algebra
- SQL