# Database Constraints and Triggers

> Implementation and management of database constraints and triggers for maintaining data integrity and automating database operations

- **Canonical URL:** https://flashcards.world/flashcards/sets/4342d911-34e2-4bf1-94d9-fe7e461d82b2/
- **Markdown URL:** https://flashcards.world/flashcards/sets/4342d911-34e2-4bf1-94d9-fe7e461d82b2.md
- **Category:** Database Management
- **Level:** intermediate
- **Languages:** en → en
- **Total Cards:** 48

## Flashcards (48 Cards)

| # | Front (Term / Prompt) | Back (Definition / Answer) | Example | Multiple-Choice Options |
| :--- | :--- | :--- | :--- | :--- |
| 1 | What is a trigger in a database? | A trigger is a set of instructions that automatically executes in response to certain events on a table. |  |  |
| 2 | How do constraints help maintain data integrity? | Constraints enforce rules on data entry, preventing invalid data from being stored in the database. |  |  |
| 3 | What is a trigger body? | The trigger body is the section of the trigger that contains the SQL statements to be executed when the trigger is fired. |  |  |
| 4 | What is the purpose of the SET NULL action in foreign key constraints? | The SET NULL action sets the foreign key column to NULL when the referenced record is deleted. |  |  |
| 5 | What is a check constraint? | A check constraint is a rule that specifies a condition that must be met for values in a column. |  |  |
| 6 | What is the purpose of the SET DEFAULT action in foreign key constraints? | The SET DEFAULT action sets the foreign key column to its default value when the referenced record is deleted. |  |  |
| 7 | What is the purpose of the RAISE statement in a trigger? | The RAISE statement is used to generate an error or warning message within a trigger. |  |  |
| 8 | Explain the difference between a primary key and a unique key. | A primary key cannot contain NULL values and uniquely identifies a record, while a unique key can contain one NULL value and also ensures uniqueness. |  |  |
| 9 | How can you prevent infinite loops with triggers? | To prevent infinite loops, ensure that triggers do not cause actions that would re-invoke themselves. |  |  |
| 10 | Define PRIMARY KEY constraint. | A PRIMARY KEY constraint uniquely identifies each record in a table and cannot contain NULL values. |  |  |
| 11 | Give an example of a check constraint. | An example of a check constraint is ensuring that the age column must have values greater than 0. |  |  |
| 12 | What are the types of triggers? | The main types of triggers are BEFORE triggers, AFTER triggers, and INSTEAD OF triggers. |  |  |
| 13 | What is a performance consideration when using triggers? | Triggers can slow down data operations due to additional processing, so they should be used judiciously. |  |  |
| 14 | What is a trigger event? | A trigger event is the specific action that causes the trigger to execute, such as INSERT, UPDATE, or DELETE. |  |  |
| 15 | What is the impact of constraints on performance? | While constraints ensure data integrity, they can also impact performance due to additional checks during data operations. |  |  |
| 16 | How do you drop a constraint in SQL? | You can drop a constraint using the ALTER TABLE statement followed by DROP CONSTRAINT. |  |  |
| 17 | What is a trigger for auditing purposes? | A trigger for auditing purposes records changes made to a table, such as who made the change and when. |  |  |
| 18 | What is the purpose of the UNIQUE constraint? | The UNIQUE constraint ensures that all values in a column are different from each other. |  |  |
| 19 | What is a cascading update? | A cascading update automatically updates related records in child tables when a record in the parent table is updated. |  |  |
| 20 | What happens when a UNIQUE constraint is violated? | When a UNIQUE constraint is violated, the database rejects the insert or update operation that causes the duplication. |  |  |
| 21 | Name the four main types of database constraints. | The four main types are NOT NULL, UNIQUE, PRIMARY KEY, and FOREIGN KEY. |  |  |
| 22 | What is a FOREIGN KEY constraint? | A FOREIGN KEY constraint establishes a relationship between two tables by ensuring that a value in one table matches a value in another. |  |  |
| 23 | Can a trigger call another trigger? | Yes, a trigger can call another trigger, but this can lead to complex interactions and should be managed carefully. |  |  |
| 24 | What is the purpose of using triggers in data synchronization? | Triggers can be used to automatically synchronize data between tables or databases when changes occur. |  |  |
| 25 | What is a domain constraint? | A domain constraint specifies the allowable values for a column, such as data type and range. |  |  |
| 26 | What is a self-referencing foreign key? | A self-referencing foreign key is a foreign key that refers to the same table it is defined in. |  |  |
| 27 | When is a BEFORE trigger executed? | A BEFORE trigger is executed before an insert, update, or delete operation on a table. |  |  |
| 28 | What is a trigger timing? | Trigger timing refers to whether the trigger is executed before or after the triggering event. |  |  |
| 29 | What is the purpose of an AFTER trigger? | An AFTER trigger is executed after an insert, update, or delete operation, often used for auditing or logging changes. |  |  |
| 30 | How can triggers help with data validation? | Triggers can enforce complex validation rules that cannot be implemented with standard constraints. |  |  |
| 31 | What is a trigger condition? | A trigger condition is a specific criterion that must be met for the trigger to execute. |  |  |
| 32 | What is a composite key? | A composite key is a combination of two or more columns in a table that together uniquely identify a record. |  |  |
| 33 | What is the difference between a trigger and a stored procedure? | A trigger is automatically invoked by database events, while a stored procedure must be explicitly called by a user or application. |  |  |
| 34 | What is a cascading delete? | A cascading delete automatically removes related records in child tables when a record in the parent table is deleted. |  |  |
| 35 | What does an INSTEAD OF trigger do? | An INSTEAD OF trigger replaces the standard action of an insert, update, or delete operation. |  |  |
| 36 | How do you create a trigger in SQL? | You create a trigger using the CREATE TRIGGER statement followed by the trigger name and its specifications. |  |  |
| 37 | What is the difference between a trigger and a constraint? | A trigger automates actions based on events, while a constraint enforces rules on data integrity. |  |  |
| 38 | What is a trigger log? | A trigger log is a record of actions performed by triggers, often used for debugging or auditing. |  |  |
| 39 | What is a trigger variable? | Trigger variables are special variables that hold information about the triggering event, such as OLD and NEW values. |  |  |
| 40 | What is the purpose of the DEFAULT constraint? | The DEFAULT constraint provides a default value for a column when no value is specified during an insert. |  |  |
| 41 | What is the role of triggers in enforcing business rules? | Triggers can enforce complex business rules that go beyond simple constraints, ensuring compliance with business logic. |  |  |
| 42 | What is a row-level trigger? | A row-level trigger executes once for each row affected by the triggering event. |  |  |
| 43 | What is cascading in the context of foreign keys? | Cascading refers to automatically updating or deleting related records in child tables when a record in the parent table is updated or deleted. |  |  |
| 44 | What does the NOT NULL constraint do? | The NOT NULL constraint ensures that a column cannot have a NULL value. |  |  |
| 45 | What is a database constraint? | A database constraint is a rule that limits the types of data that can be inserted into a table to ensure data integrity. |  |  |
| 46 | What is a trigger action? | A trigger action is the specific operation that the trigger performs when it is fired. |  |  |
| 47 | What is a statement-level trigger? | A statement-level trigger executes once for the entire SQL statement, regardless of how many rows are affected. |  |  |
| 48 | What is the significance of the order of triggers? | The order of triggers can affect the outcome of operations, as they execute in the order they are defined. |  |  |

---
Study this deck interactively with FSRS-6 spaced repetition, audio review, and multiple-choice mode at [Flashcards World](https://flashcards.world/flashcards/sets/4342d911-34e2-4bf1-94d9-fe7e461d82b2/).
