chap 2.pdf
Document Details
Uploaded by EfficientMountRushmore
Tags
Full Transcript
Views, Semantics Constraints and Triggers Presented by: Marcelino, Elouisa Joy Tingas, Marie Colleen Content Definition of Views Example of Views Definition of Semantic Constraints Example of Semantic Constraints Definition of Triggers Example of Triggers...
Views, Semantics Constraints and Triggers Presented by: Marcelino, Elouisa Joy Tingas, Marie Colleen Content Definition of Views Example of Views Definition of Semantic Constraints Example of Semantic Constraints Definition of Triggers Example of Triggers 01. Virtual tables that provide a way to simplify complex queries. Views Purpose: Organize and 02. present data without affecting the underlying tables. What are Views? Views are stored queries that retrieve data. 03. They allow users to: Focus on relevant data. Restrict access to sensitive information. Simplify complex joins or queries. Data used: Example of VIEWS CREATE VIEW TopStudents AS SELECT StudentDetails.S_ID, StudentDetails.NAME, StudentDetails.ADDRESS, StudentMarks.MARKS FROM StudentDetails JOIN StudentMarks ON StudentDetails.S_ID = StudentMarks.ID WHERE StudentMarks.MARKS > 80; Example of VIEWS 01. Definition: Logical rules that ensure data integrity in a database. Semantics 02. Types of Constraints: Constraints >Domain Constraints: Limits on data types (e.g., age must be positive). >Referential Integrity: Ensures relationships between tables are consistent. > Assertions: Conditions that must be true for all rows of a table. Example of Semantics Constraints CREATE TABLE StudentMarks ( ID INT PRIMARY KEY, NAME VARCHAR(50), MARKS INT, AGE INT, CONSTRAINT chk_marks CHECK (MARKS BETWEEN 0 AND 100) ); Example of Semantics Constraints Definition: Procedures that 01. automatically execute when specific database events Triggers occur (like INSERT, UPDATE, or DELETE). 02. Purpose: Maintain data integrity, enforce business rules, or automate tasks. 03. How Triggers Work: Before vs. After Triggers: Triggers > Specify whether the trigger fires before or after the event. Types of Events: - Row-level (per row affected) - Statement-level (once per operation) They allow users to: Example of Triggers DELIMITER // CREATE TRIGGER InsertStudentMarks AFTER INSERT ON studentdetails FOR EACH ROW BEGIN INSERT INTO studentmarks (ID, NAME, MARKS, AGE) VALUES (NEW.S_ID, NEW.NAME, 0, 18); -- Default values for marks and age END; // DELIMITER ; Example of Triggers Thank you so much!