You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Databases often store sensitive and valuable data — personal information, financial records, medical data. Protecting this data from unauthorised access, corruption, and loss is a critical responsibility. This lesson covers the key concepts of database security and data integrity.
Data integrity means that the data stored in the database is accurate, consistent, and reliable. There are several types:
Every table must have a primary key, and no primary key value can be NULL. This ensures every record is uniquely identifiable.
Every foreign key value must either match an existing primary key in the referenced table or be NULL (if the field allows NULLs). This ensures that relationships between tables remain valid.
Example: If you try to insert an order with a CustomerID that does not exist in the Customers table, the database will reject the insert.
Every value in a field must conform to the defined data type, format, and constraints for that field.
Examples:
| Concept | Definition | Example |
|---|---|---|
| Validation | Checking that data is reasonable, sensible, and within acceptable bounds | Range check: age must be 0–150; type check: age must be an integer |
| Verification | Checking that data has been entered correctly (matches the original source) | Double entry: typing the same data twice to confirm it matches |
Databases use user accounts with different levels of access:
-- Grant SELECT permission on Students to user 'teacher1'
GRANT SELECT ON Students TO teacher1;
-- Grant full access on Grades to user 'admin1'
GRANT ALL PRIVILEGES ON Grades TO admin1;
-- Remove INSERT permission on Students from user 'student1'
REVOKE INSERT ON Students FROM student1;
A view is a virtual table defined by a query. Views can restrict which rows and columns a user can see, providing a security layer.
-- Create a view that shows student names but not their emails
CREATE VIEW PublicStudentInfo AS
SELECT StudentID, FirstName, Surname, FormGroup
FROM Students;
-- Grant access to the view instead of the base table
GRANT SELECT ON PublicStudentInfo TO teacher1;
Encryption converts data into an unreadable format using an algorithm and a key. Only someone with the correct decryption key can read the original data.
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.