Q.1 Which of the following constraints ensures that a column cannot have NULL values?
PRIMARY KEY
FOREIGN KEY
NOT NULL
UNIQUE
Explanation - The NOT NULL constraint ensures that a column must always have a value and cannot be left empty.
Correct answer is: NOT NULL
Q.2 What does a UNIQUE constraint enforce in a table?
No two rows can have the same value in the column(s)
Column cannot have NULL values
Column must be a primary key
Column can have duplicate values
Explanation - A UNIQUE constraint ensures that all values in a column or a combination of columns are distinct from each other.
Correct answer is: No two rows can have the same value in the column(s)
Q.3 Which constraint is automatically created when you define a PRIMARY KEY?
FOREIGN KEY
UNIQUE
CHECK
NOT NULL
Explanation - A PRIMARY KEY constraint automatically implies NOT NULL and UNIQUE for the column(s) involved.
Correct answer is: NOT NULL
Q.4 What is the purpose of a FOREIGN KEY constraint?
Enforce uniqueness in a column
Ensure referential integrity between tables
Prevent NULL values
Limit values in a column
Explanation - A FOREIGN KEY ensures that the value in one table matches a value in another table, maintaining relationships between tables.
Correct answer is: Ensure referential integrity between tables
Q.5 Which SQL statement is used to create a trigger?
CREATE TRIGGER
CREATE PROCEDURE
CREATE VIEW
CREATE FUNCTION
Explanation - Triggers are created using the CREATE TRIGGER statement to automatically execute a set of SQL statements on certain events.
Correct answer is: CREATE TRIGGER
Q.6 A trigger can be set to execute at which of the following times?
BEFORE
AFTER
INSTEAD OF
All of the above
Explanation - Triggers can be set to execute BEFORE or AFTER a data modification, or INSTEAD OF certain operations (like on views).
Correct answer is: All of the above
Q.7 Which type of trigger activates once for each row affected by a statement?
STATEMENT level
ROW level
BEFORE level
AFTER level
Explanation - ROW-level triggers execute once for each affected row, whereas statement-level triggers execute once per SQL statement.
Correct answer is: ROW level
Q.8 What is a view in SQL?
A physical table
A virtual table based on a query
A trigger
A stored procedure
Explanation - A view is a virtual table derived from a SELECT query, which does not store data physically but shows data from underlying tables.
Correct answer is: A virtual table based on a query
Q.9 Which SQL statement is used to create a view?
CREATE VIEW
CREATE TABLE
CREATE TRIGGER
CREATE DATABASE
Explanation - CREATE VIEW is used to define a virtual table using a SELECT query from one or more underlying tables.
Correct answer is: CREATE VIEW
Q.10 Which of the following can a CHECK constraint enforce?
Value range limits
Uniqueness
Referential integrity
Trigger execution
Explanation - CHECK constraints ensure that values in a column satisfy a specific condition, like a range or format.
Correct answer is: Value range limits
Q.11 If a DELETE operation violates a foreign key constraint, what happens?
The row is deleted anyway
The operation fails
The trigger runs automatically
A view is updated
Explanation - Foreign key constraints prevent deletion or update of referenced rows unless cascading rules are defined.
Correct answer is: The operation fails
Q.12 Which of the following is NOT a valid type of SQL trigger event?
INSERT
UPDATE
DELETE
SELECT
Explanation - Triggers can only be defined for data modification events (INSERT, UPDATE, DELETE), not for SELECT operations.
Correct answer is: SELECT
Q.13 What is an INSTEAD OF trigger commonly used for?
Preventing updates
Updating base tables through a view
Creating a virtual table
Enforcing constraints
Explanation - INSTEAD OF triggers are defined on views to perform actions on underlying tables when DML operations are executed on the view.
Correct answer is: Updating base tables through a view
Q.14 Which of the following constraints is used to prevent duplicate entries in a column?
PRIMARY KEY
FOREIGN KEY
CHECK
DEFAULT
Explanation - PRIMARY KEY ensures uniqueness and also disallows NULLs, effectively preventing duplicate entries in a column or set of columns.
Correct answer is: PRIMARY KEY
Q.15 Which of the following SQL statements modifies an existing view?
ALTER VIEW
UPDATE VIEW
MODIFY VIEW
CHANGE VIEW
Explanation - ALTER VIEW is used to redefine the query of an existing view without dropping it.
Correct answer is: ALTER VIEW
Q.16 Which of the following is true about cascading actions in foreign keys?
They allow automatic updates/deletes in child tables
They prevent updates in child tables
They create a view
They enforce uniqueness
Explanation - Cascading actions (ON UPDATE CASCADE, ON DELETE CASCADE) automatically update or delete related rows in child tables.
Correct answer is: They allow automatic updates/deletes in child tables
Q.17 What happens if a CHECK constraint is violated during an INSERT?
The row is inserted anyway
The INSERT operation fails
A trigger is activated
The table is dropped
Explanation - A CHECK constraint ensures only valid data is inserted; violating it causes the INSERT operation to fail.
Correct answer is: The INSERT operation fails
Q.18 Which type of view can allow DML operations to propagate to the underlying table?
Simple view
Complex view with joins
Aggregate view
Materialized view
Explanation - Simple views based on a single table without aggregations often allow INSERT, UPDATE, or DELETE operations to reflect on the base table.
Correct answer is: Simple view
Q.19 What is the effect of a NOT NULL constraint on a column?
Column must have unique values
Column cannot have missing values
Column must reference another table
Column must have default value
Explanation - NOT NULL ensures that every row must contain a value for the column; NULL entries are not allowed.
Correct answer is: Column cannot have missing values
Q.20 Which SQL clause is used to define a column-level CHECK constraint?
CHECK(column_name condition)
CONSTRAINT column_name
FOREIGN KEY(column_name)
NOT NULL(column_name)
Explanation - A column-level CHECK constraint specifies a condition that each value in the column must satisfy.
Correct answer is: CHECK(column_name condition)
Q.21 Which type of trigger executes once per SQL statement regardless of affected rows?
ROW level
STATEMENT level
BEFORE level
AFTER level
Explanation - Statement-level triggers execute once for the entire statement, not for each row affected.
Correct answer is: STATEMENT level
Q.22 What is the main advantage of using a view?
Improved security by restricting access
Faster storage of data
Automatic updates
Preventing duplicates
Explanation - Views can restrict access to specific columns or rows, providing a level of security without exposing the underlying tables.
Correct answer is: Improved security by restricting access
Q.23 Which of the following statements is true about triggers?
They cannot access table data
They automatically execute in response to events
They are used to create views
They enforce NOT NULL constraints
Explanation - Triggers are automatically executed when a specified event occurs on a table or view, such as INSERT, UPDATE, or DELETE.
Correct answer is: They automatically execute in response to events
Q.24 Which constraint ensures that a column's value must match a value in another table?
PRIMARY KEY
UNIQUE
FOREIGN KEY
CHECK
Explanation - A FOREIGN KEY constraint enforces referential integrity by ensuring values in the child table match values in the parent table.
Correct answer is: FOREIGN KEY
Q.25 What does the DEFAULT constraint do?
Sets a default value if none is provided
Prevents NULL values
Ensures uniqueness
Creates a trigger
Explanation - The DEFAULT constraint provides a default value for a column when no value is specified during an INSERT operation.
Correct answer is: Sets a default value if none is provided
