NEW
Font size
WorksheetsDatabase Constraints Quiz
Total questions: 40
Worksheet time: 3600secs
You are designing a Product table for an inventory system. Each product must have a unique serial number, and the price must always be greater than zero. What combination of constraints would you apply?
Primary Key on serial_number, Not Null on price
Unique on serial_number, Check constraint on price
Primary Key on serial_number, Check constraint on price > 0
Unique on serial_number, Not Null on price
Which constraint would ensure that no two rows in the same table have the same values in a specific column?
Not Null Constraint
Primary Key Constraint
Foreign Key Constraint
Unique Constraint
table Order with a column Customer ID references Customer table with the primary key Customer ID. What constraint would you use to enforce this relationship?
Primary Key Constraint
Check Constraint
Foreign Key Constraint
Unique Constraint
In which situation would you use an ON DELETE CASCADE referential constraint?
When you want to delete all orders if the related customer is deleted
When you want to prevent deleting a customer if they have existing orders
When you want to update all foreign keys when a primary key is modified
When you want to set the foreign key to null if the parent record is deleted
A Not Null constraint is used to:
Ensure no duplicates exist in a column
Ensure a column has a value and does not contain nulls
Ensure referential integrity between two tables
Ensure a column has unique values
You are tasked with creating a Customer table where the email address must be unique for each customer. What constraint would you apply to the email column?
Not Null Constraint
Foreign Key Constraint
Check Constraint
Unique Constraint
Each department can have multiple employees, but each employee can belong to only one department. What kind of relationship does this represent?
One-to-One
One-to-Many
Many-to-Many
Self-referencing
Which integrity constraint would you use to ensure that a salary column in an Employee table only accepts values greater than zero?
Foreign Key Constraint
Unique Constraint
Check Constraint
Primary Key Constraint
In a library database, each book can only be checked out by one member at a time, but a member can check out multiple books. What type of relationship should you define between Member and Book tables?
One-to-One
One-to-Many
Many-to-Many
Self-referencing
Which of the following is not a characteristic of a Primary Key?
Must be unique
Must be indexed
Can contain null values
Can be an integer or a string
You are designing a schema where an employee can be managed by another employee, and you need to model this relationship within the same table. How would you represent this?
Use a self-referencing foreign key in the Employee table
Create a One-to-One relationship between two different tables
Create a Many-to-Many relationship between two different tables
Store the manager information in a separate table
A Foreign Key constraint ensures that:
All values in a column are unique
All values in a column must refer to a valid value in another table
A column cannot contain null values
A column must meet certain conditions
Which of the following is a valid reason to use a Check Constraint?
To ensure that an email field contains a valid domain
To enforce unique values in a column
To prevent null values in a column
To ensure referential integrity between two tables
Suppose that there are two tables, Customer and Order. If a customer is deleted, all related orders should also be deleted. What referential action should you use?
ON DELETE CASCADE
ON DELETE SET NULL
ON DELETE RESTRICT
ON DELETE NO ACTION
In which situation would you use an ON DELETE SET NULL referential constraint?
When you want to delete child records when the parent record is deleted
When you want to prevent deleting parent records if there are child records
When you want to set the foreign key to null if the parent record is deleted
When you want to update the foreign key when the primary key is updated
A Customer table has a foreign key referencing the Country table, but you want to ensure that if a country is deleted, the related customer records should remain, with the Country ID set to null. How would you enforce this?
ON DELETE RESTRICT
ON DELETE CASCADE
ON DELETE SET NULL
ON DELETE NO ACTION
You are designing a hotel booking system where each room can only be booked by one customer at a time, but each customer can book multiple rooms during their stay. What type of relationship should you create between the Room and Customer tables?
One-to-One
One-to-Many
Many-to-Many
One-to-One with a Junction table
Which type of constraint would you apply to a column that should not contain duplicate values but can contain nulls?
Primary Key Constraint
Foreign Key Constraint
Check Constraint
Unique Constraint
In a sales database, you want to ensure that discounts are never negative. What constraint should you apply to the Discount column?
Foreign Key Constraint
Check Constraint
Primary Key Constraint
Not Null Constraint
What is the main purpose of a Foreign Key Constraint in a relational database?
To ensure that data is unique across rows
To prevent null values from being entered
To enforce referential integrity between tables
To ensure that values follow specific conditions
You have a Product table where each product can have multiple suppliers, and the supplier information is repeated for each product. What normal form is this table violating?
First Normal Form (1NF)
Second Normal Form (2NF)
Third Normal Form (3NF)
Fourth Normal Form (4NF)
Which of the following ensures that all data is atomic and eliminates repeating groups?
First Normal Form (1NF)
Second Normal Form (2NF)
Third Normal Form (3NF)
Boyce-Codd Normal Form (BCNF)
You have an Orders table where both Order ID and Product ID form the composite primary key. The Customer Name is also stored in this table but only depends on Order ID. What normal form does this table violate?
1NF
2NF
3NF
BCNF
table is in Second Normal Form (2NF) when:
It has no repeating groups
Every non-key attribute is fully dependent on the entire primary key
There are no transitive dependencies
Every functional dependency is a superkey
You are working with a university database where students can enroll in multiple courses, and each course is taught by a single instructor. How would you design this to meet 3NF?
Combine students, courses, and instructors into one table
Use composite keys without normalization
Create separate tables for students, courses, instructors, and a junction table for enrollments
Store instructor details with student data
Which normal form removes transitive dependencies, ensuring that non-key attributes do not depend on other non-key attributes?
First Normal Form (1NF)
Second Normal Form (2NF)
Third Normal Form (3NF)
Fourth Normal Form (4NF)
The following table stores customer orders, where Order ID and Customer Name are included. Customer Name only depends on Order ID, not on Product details. What normal form is violated?
1NF
2NF
3NF
BCNF
In which normal form must a table be if it is already in BCNF?
1NF
2NF
All of the above
3NF
In a Books table, you store Author Name, Book Title, and Publisher Name. The Publisher Name depends on the Author Name but not the Book Title. How would you bring this table to 3NF?
Leave it as is
Move Publisher Name to a separate table
Create a composite primary key
Normalize it to BCNF
Which of the following best describes Boyce-Codd Normal Form (BCNF)?
A stricter form of 2NF
A stricter form of 3NF
Focuses on eliminating partial dependencies
Only deals with multivalued dependencies
You are designing a database for a retail store. Each product can be supplied by multiple vendors, and each vendor can supply multiple products. How would you design this to eliminate redundancy?
Combine both products and vendors into a single table for simplicity.
Create separate tables for products, vendors, and a junction table for product-vendor relationships.
Denormalize the data by merging products and vendors into one table for easier access.
Use composite keys to link both products and vendors in a single relationship.
The following table stores student information where Student ID is the primary key, and a student can have multiple hobbies and enroll in multiple courses. What normal form is violated?
1NF
2NF
4NF
BCNF
A table is in 4NF if:
It is in BCNF and there are no multivalued dependencies
It is in 3NF and there are no transitive dependencies
It is in 2NF and there are no partial dependencies
It has a composite primary key
In a hospital database, each doctor can have multiple patients, and each patient can be treated by multiple doctors. How would you normalize this relationship?
Create a many-to-many relationship by using a junction table between doctors and patients.
Store all the data in a single table, utilizing composite keys to link the records.
Denormalize the data into one large table to improve query performance.
Use multiple foreign keys to link the tables but without any normalization.
Which normal form deals specifically with eliminating partial dependencies in composite keys?
1NF
2NF
3NF
4NF
You are creating a Students table where each student can enroll in multiple courses, but each course has only one instructor. If the table also has an Instructor ID for each course, what normal form is it violating?
1NF
2NF
3NF
BCNF
In which normal form are multivalued dependencies eliminated?
1NF
2NF
3NF
4NF
The following table stores courses and instructors, but each course has only one Instructor. If the course time is dependent on the Instructor, not the course itself, what normal form is violated?
1NF
2NF
3NF
BCNF
Why might you choose to denormalize a database?
To increase redundancy
To improve query performance
To reduce data anomalies
To enforce stronger data integrity
In a sales database, orders include both customer and product information. You need to avoid anomalies while maintaining performance. What strategy would you use?
Fully normalize the data to 3NF and use joins for all queries
Denormalize the data by combining customer and order information into one table
Normalize the data but introduce indexing for performance
Store everything in one table for simplicity
