wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Database Constraints Quiz

Total questions: 86

Worksheet time: 43mins

Name
Class
Date
1.

What is the purpose of constraints in a database table?

a)

To specify rules for the data in a table

b)

To delete data from a table

c)

To create relationships between tables

d)

To format the data in a table

2.

Which of the following ensures the accuracy and reliability of the data in a table?

a)

Constraints

b)

Primary key

c)

Foreign key

d)

Index

3.

What does a primary key do in a database table?

a)

Refers to the primary key in another table

b)

Uniquely identifies each row in the table

c)

Limits the type of data in the table

d)

Specifies rules for the data in the table

4.

What is the role of a foreign key in a database table?

a)

Specifies rules for the data in a table

b)

Refers to the primary key in another table and relates two tables

c)

Uniquely identifies each row in the table

d)

Ensures the accuracy and reliability of the data

5.

What does the UNIQUE constraint in MySQL ensure?

a)

All values in a column are unique/different.

b)

A column cannot have a NULL value.

c)

A default value is set for a column when no value is specified.

d)

All values in a column are identical.

6.

Which constraint ensures that a column cannot have a NULL value in MySQL?

a)

UNIQUE

b)

NOT NULL

c)

DEFAULT

d)

PRIMARY KEY

7.

What is the purpose of the DEFAULT constraint in MySQL?

a)

To ensure all values in a column are unique.

b)

To prevent NULL values in a column.

c)

To set a default value for a column when no value is specified.

d)

To enforce a primary key in a table.

8.

What do NULL values represent in MySQL?

a)

Missing unknown data.

b)

Duplicate data.

c)

Default values.

d)

Primary key values.

9.

What is the primary purpose of the AUTO_INCREMENT feature in a database table?

a)

To allow duplicate values in a column.

b)

To automatically generate a unique number for each new record.

c)

To delete records automatically.

d)

To sort records in ascending order.

10.

By default, what is the starting value for AUTO_INCREMENT in a database table?

a)

0

b)

1

c)

10

d)

100

11.

What is AUTO_INCREMENT most commonly used for in a database table?

a)

Generating a unique primary key for each new record.

b)

Sorting records alphabetically.

c)

Creating foreign keys automatically.

d)

Deleting duplicate records.

12.

What is the purpose of the `AUTO_INCREMENT` attribute in the `CREATE TABLE` statement?

a)

To ensure a column is unique.

b)

To automatically generate sequential values for a column.

c)

To set a default value for a column.

d)

To define a foreign key relationship.

13.

Which SQL keyword is used to specify the database to work with in the given example?

a)

SELECT

b)

USE

c)

CREATE

d)

INSERT

14.

In the `CREATE TABLE groups` statement, what does the `UNIQUE` constraint ensure for the `name` column?

a)

The column can only contain numeric values.

b)

The column cannot have duplicate values.

c)

The column must have a default value.

d)

The column cannot be null.

15.

What is the default value assigned to the `profile` column in the `groups` table?

a)

NULL

b)

"IT"

c)

"Default"

d)

"Profile"

16.

What type of relationship is established between the `students` table and the `groups` table using the `FOREIGN KEY` constraint?

a)

One-to-one relationship.

b)

One-to-many relationship.

c)

Many-to-many relationship.

d)

No relationship.

17.

Which data type is used for the `DOB` column in the `students` table?

a)

VARCHAR

b)

INT

c)

DATE

d)

TEXT

18.

What is the purpose of the "INSERT INTO" statement in SQL?

a)

To delete data from a table

b)

To update data in a table

c)

To add new data to a table

d)

To retrieve data from a table

19.

In the SQL statement "INSERT INTO groups (name, profile) VALUES ('C1', 'computing');", what does "groups" represent?

a)

A column name

b)

A table name

c)

A database name

d)

A function name

20.

What happens if a value for a column with a default value is not provided in an "INSERT INTO" statement?

a)

The column remains empty

b)

The default value is used

c)

An error is generated

d)

The table is deleted

21.

In the SQL statement "INSERT INTO groups (name) VALUES ('N3');", why is the "profile" column not specified?

a)

It is an auto-incremented field

b)

It has a default value

c)

It is a primary key

d)

It is a foreign key

22.

An example of SQL "INSERT INTO" statements with explanations of column names and default values.

a)

INSERT INTO students (id, name, age) VALUES (1, 'John', DEFAULT);

b)

INSERT INTO students (id, name, age) VALUES ('John', 1, DEFAULT);

c)

INSERT INTO students VALUES (1, 'John', DEFAULT);

d)

INSERT INTO students (id, name, age) VALUES (DEFAULT, 'John', 1);

23.

What is the purpose of the `INSERT INTO` statement in SQL?

a)

To delete rows from a table

b)

To update rows in a table

c)

To add new rows to a table

d)

To create a new table

24.

Which of the following is true about auto-incremented fields in SQL when using the `INSERT INTO` statement?

a)

Auto-incremented fields must always be specified in the `INSERT INTO` statement

b)

Auto-incremented fields are automatically populated and do not need to be specified

c)

Auto-incremented fields must be manually updated after insertion

d)

Auto-incremented fields are optional but recommended to specify

25.

In the example `INSERT INTO students (DOB, name, groupID) VALUES ("1997-02-11", "Jeff", 1);`, what does `groupID` represent?

a)

The name of the student

b)

The date of birth of the student

c)

The group identifier for the student

d)

The auto-incremented field for the student

26.

What happens if you omit column names in the `INSERT INTO` statement, as shown in the example `INSERT INTO students VALUES ("", "Kate", "1997-09-22", 1);`?

a)

The database will throw an error

b)

The values will be inserted into the table in the order of the columns

c)

The values will be ignored

d)

The database will automatically assign default values to all columns

27.

What is the correct format for inserting a date in MySQL?

a)

DD-MM-YYYY without quotations

b)

MM-DD-YYYY inside quotations

c)

YY-MM-DD inside quotations

d)

YYYY-DD-MM without quotations

28.

Which data type in MySQL is used to insert the current date and time automatically?

a)

Date

b)

Timestamp

c)

Time

d)

Datetime

29.

What does the following SQL query do: `SELECT * FROM groups;`?

a)

Deletes all records from the 'groups' table

b)

Selects all columns and rows from the 'groups' table

c)

Updates all records in the 'groups' table

d)

Creates a new table named 'groups'

30.

In the provided example, what is the profile associated with groupID 5 in the 'groups' table?

a)

Networking

b)

IT

c)

Multimedia

d)

Computing

31.

What is the studentID of the student named 'Mark' in the 'students' table?

a)

1

b)

4

c)

5

d)

6

32.

What is the primary purpose of the SQL WHERE clause?

a)

To insert data into a table

b)

To filter or search data based on specified criteria

c)

To delete data from a table

d)

To create a new table

33.

Which SQL statement correctly uses the WHERE clause to filter data?

a)

SELECT column_name FROM table_name WHERE column_name operator value;

b)

INSERT INTO table_name WHERE column_name operator value;

c)

DELETE FROM table_name WHERE column_name operator value;

d)

CREATE TABLE table_name WHERE column_name operator value;

34.

In SQL, what does the WHERE clause help achieve when querying a database?

a)

It sorts the data in ascending order

b)

It extracts records that meet specific criteria

c)

It combines multiple tables into one

d)

It updates all records in a table

35.

Which of the following is an example of an arithmetic operator in SQL?

a)

AND

b)

+

c)

=

d)

LIKE

36.

Which operator is used in SQL for comparing two values to check if they are not equal?

a)

!=

b)

AND

c)

%

d)

LIKE

37.

Which of the following is a logical operator in SQL?

a)

BETWEEN

b)

*

c)

=

d)

%

38.

What type of operator is used to perform mathematical calculations in SQL?

a)

Logical Operators

b)

Arithmetic Operators

c)

Comparison Operators

d)

Aggregate Functions

39.

Which of the following operators can be used to filter data based on a range in SQL?

a)

BETWEEN

b)

+

c)

!=

d)

%

40.

What does the `WHERE` clause in SQL allow you to do when working with dates?

a)

Filter data based on specific date conditions.

b)

Create new tables based on date values.

c)

Delete rows from a table based on date values.

d)

Update date values in a table.

41.

In the query `SELECT * FROM students WHERE year(DOB)='1997';`, what does the `year(DOB)` function do?

a)

Extracts the year from the `DOB` column.

b)

Converts the `DOB` column into a string.

c)

Filters rows where the `DOB` column is null.

d)

Adds a year to the `DOB` column.

42.

Which of the following is true about comparing dates in SQL?

a)

Dates can be compared as string values or numeric values.

b)

Dates must always be compared as numeric values.

c)

Dates cannot be compared directly in SQL.

d)

Dates must be converted to integers before comparison.

43.

What will the query `SELECT * FROM students WHERE month(DOB)='5';` return?

a)

Rows where the month in the `DOB` column is May.

b)

Rows where the year in the `DOB` column is 2005.

c)

Rows where the day in the `DOB` column is the 5th.

d)

Rows where the `DOB` column is null.

44.

In the query `SELECT * FROM students WHERE day(DOB)>=10 AND day(DOB)<=15;`, what does the condition `day(DOB)>=10 AND day(DOB)<=15` do?

a)

Filters rows where the day in the `DOB` column is between 10 and 15.

b)

Filters rows where the month in the `DOB` column is October.

c)

Filters rows where the year in the `DOB` column is 2015.

d)

Filters rows where the `DOB` column is null.

45.

What is the primary key in the "customers" table?

a)

id

b)

name

c)

address

d)

customer_id

46.

Which column in the "orders" table is a foreign key?

a)

order_id

b)

customer_id

c)

item

d)

supplier

47.

What is the price of the "Nexus-6P" item in the "items" table?

a)

200

b)

250

c)

300

d)

350

48.

Which supplier provides the "Xbox-360" item?

a)

Google

b)

Microsoft

c)

Sony

d)

Amazon

49.

What is the phone number of the supplier "Sony"?

a)

865-898-644

b)

661-182-856

c)

500-122-999

d)

400-123-888

50.

What does the BETWEEN operator in SQL do?

a)

Selects values within a range, including numbers, text, or dates.

b)

Selects values that match a specific pattern.

c)

Selects values that are equal to a given value.

d)

Selects values that are greater than a given value.

51.

Which SQL query retrieves items with a price between 150 and 250?

a)

SELECT * FROM ITEMS WHERE price BETWEEN 150 AND 250;

b)

SELECT * FROM ITEMS WHERE price > 150 AND price < 250;

c)

SELECT * FROM ITEMS WHERE price = 150 OR price = 250;

d)

SELECT * FROM ITEMS WHERE price NOT BETWEEN 150 AND 250;

52.

What is the result of the query: SELECT * FROM customers WHERE address BETWEEN "Banepa" AND "Kathmandu"?

a)

It retrieves customers whose addresses are alphabetically between "Banepa" and "Kathmandu".

b)

It retrieves customers whose addresses are exactly "Banepa" and "Kathmandu".

c)

It retrieves customers whose addresses are not "Banepa" or "Kathmandu".

d)

It retrieves customers whose addresses are alphabetically after "Kathmandu".

53.

Which of the following data types can the BETWEEN operator work with in SQL?

a)

Numbers, text, and dates.

b)

Only numbers.

c)

Only text.

d)

Only dates.

54.

What does the IN operator in SQL allow you to do?

a)

Specify multiple values in a WHERE clause to perform membership checks.

b)

Perform arithmetic operations in a SELECT statement.

c)

Sort data in ascending or descending order.

d)

Create new tables in a database.

55.

Which SQL query retrieves all rows where the customer_id is 1, 2, or 3 using the IN operator?

a)

SELECT * FROM orders WHERE customer_id IN (1,2,3);

b)

SELECT * FROM orders WHERE customer_id = 1 OR customer_id = 2 OR customer_id = 3;

c)

SELECT * FROM orders WHERE customer_id BETWEEN 1 AND 3;

d)

SELECT * FROM orders WHERE customer_id LIKE '1,2,3';

56.

What is the result of the query "SELECT * FROM orders WHERE customer_id IN (1,2,3);" based on the provided table?

a)

Rows with customer_id 1, 2, and 3 are retrieved.

b)

Rows with customer_id 4 and 5 are retrieved.

c)

All rows in the table are retrieved.

d)

No rows are retrieved.

57.

Which of the following is NOT a valid use case for the IN operator in SQL?

a)

Checking membership of values in a WHERE clause.

b)

Filtering rows based on multiple values.

c)

Performing arithmetic operations.

d)

Simplifying complex OR conditions.

58.

What is the purpose of the LIKE operator in a WHERE clause in SQL?

a)

To perform arithmetic operations

b)

To search for a specified pattern

c)

To insert data into a table

d)

To delete data from a table

59.

Which of the following patterns will match addresses starting with the letter "k" in SQL using the LIKE operator?

a)

%k

b)

k%

c)

_k

d)

%k%

60.

Using the LIKE operator, what does the pattern "%u" match in SQL?

a)

Any string containing the letter "u"

b)

Strings starting with the letter "u"

c)

Strings ending with the letter "u"

d)

Strings with "u" as the second character

61.

Which of the following SQL queries will retrieve rows where the address contains "it"?

a)

SELECT * FROM customers WHERE address LIKE "it%";

b)

SELECT * FROM customers WHERE address LIKE "%it%";

c)

SELECT * FROM customers WHERE address LIKE "_it";

d)

SELECT * FROM customers WHERE address LIKE "it";

62.

Which aggregate function in SQL is used to calculate the sum of all values in a column?

a)

MAX()

b)

MIN()

c)

SUM()

d)

AVG()

63.

What does the MAX() function in SQL return when applied to a column?

a)

The sum of all values in the column

b)

The maximum value in the column

c)

The minimum value in the column

d)

The average value in the column

64.

If the prices of items in a table are 200, 300, 300, and 250, what will the result of the SUM(price) query be?

a)

1050

b)

950

c)

1000

d)

1100

65.

Which aggregate function in SQL is used to calculate the average value of a column?

a)

AVG()

b)

SUM()

c)

MIN()

d)

MAX()

66.

What is the purpose of the MIN() function in SQL?

a)

To find the maximum value in a column

b)

To find the minimum value in a column

c)

To calculate the sum of all values in a column

d)

To calculate the average value of a column

67.

What is the result of the SQL query `SELECT 2 + 2;` in MariaDB?

a)

2

b)

4

c)

0

d)

6

68.

What is the result of the SQL query `SELECT 2 - 2;` in MariaDB?

a)

2

b)

4

c)

0

d)

-2

69.

What does the "AS" keyword in SQL do?

a)

It performs arithmetic operations.

b)

It is used to give a temporary column name.

c)

It is used to delete a column.

d)

It is used to create a new table.

70.

What is the result of the SQL query "SELECT 9 / 3 AS quotient;"?

a)

3.0000

b)

0

c)

9

d)

1

71.

What is the result of the SQL query "SELECT 9 % 3 AS remainder;"?

a)

3

b)

0

c)

9

d)

1

72.

What is the purpose of the SQL query shown in the image?

a)

To calculate the total price of all items.

b)

To calculate the discounted price of each item.

c)

To delete items from the database.

d)

To update the supplier information for each item.

73.

What arithmetic operation is used in the SQL query to calculate the discounted price?

a)

Addition

b)

Subtraction

c)

Multiplication

d)

Division

74.

What does the expression `price - (price * 0.10)` in the SQL query represent?

a)

The original price of the item.

b)

The discounted price of the item.

c)

The tax added to the price.

d)

The supplier's profit margin.

75.

How many rows are displayed in the result set after executing the SQL query?

a)

5 rows

b)

6 rows

c)

7 rows

d)

8 rows

76.

Which SQL clause is used to rename the calculated column in the query?

a)

WHERE

b)

AS

c)

SELECT

d)

FROM

77.

What is the main purpose of a data dictionary?

a)

To store actual data in a database

b)

To provide metadata or information about data

c)

To organize data in a hierarchical structure

d)

To enforce constraints on database tables

78.

How is a data dictionary typically organized?

a)

In a hierarchical tree structure

b)

In a spreadsheet format

c)

In a graphical user interface

d)

In a textual document

79.

What type of information does a data dictionary include about tables and fields?

a)

Information about database users

b)

Information about data type and field length

c)

Information about database security

d)

Information about database backups

80.

Which of the following statements is true about the layout or information in a data dictionary?

a)

It follows a strict standard format

b)

It has no one set standard in terms of layout or information

c)

It is always organized alphabetically

d)

It is always organized by data type

81.

What does a data dictionary technically represent?

a)

A database about a database

b)

A collection of database queries

c)

A list of database users

d)

A backup of database tables

82.

What is the purpose of the "ID" column in the "Employee" entity of the data dictionary?

a)

To store the name of the employee

b)

To uniquely identify each employee

c)

To reference the department ID

d)

To store the length of the employee's name

83.

Which data type is used for the "ID" column in the "Employee" entity?

a)

VARCHAR

b)

INT

c)

CHAR

d)

TEXT

84.

What does the "Auto incremented" note in the "ID" column signify?

a)

The value of the column is manually entered

b)

The value of the column automatically increases for each new record

c)

The column is used as a foreign key

d)

The column is nullable

85.

Which column in the "Employee" entity is marked as a foreign key?

a)

ID

b)

Name

c)

Department

d)

Notes

86.

What is the length of the "Name" column in the "Employee" entity?

a)

32

b)

255

c)

128

d)

64