wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SQL.

Total questions: 84

Worksheet time: 42mins

Name
Class
Date
1.

The Books table has the following columns: ISBN - unique code of the book edition, title of the book, author of the book, number of pages. Which of these columns can be the Primary key?

a)

ISBN

b)

author

c)

pages

d)

title

2.

Select the Primary key from the following description: Groups (group_id, name, email)

a)

name

b)

email

c)

group_id

d)

name, group_id

3.

Select the Primary key from the following description: Teachers (teacher_id, lastname, email)

a)

email

b)

teacher_id

c)

Teachers

d)

lastname

4.

Select the Primary key from the following description: Schedule (schedule_id, course_id, teacher_id, group_id, time, room)

a)

schedule_id

b)

course_id

c)

teacher_id

d)

group_id

5.

The database has a Courses table with the following columns: course id, course name, number of credits. Select which of the following constraints can be implemented for this table?

a)

the number of credits can be from 1 to 6

b)

books for each course should be available in the university library

c)

course grades must range from 0 to 100%

d)

courses must last 3 months

6.

The database has a Schedule table with the following columns: schedule_id, course_id, teacher_id, group_id, time, room, day_of_week. Select which of the following constraints can be implemented for this table?

a)

lesson time can be from 08:00 to 22:00

b)

lessons should be interesting

c)

students must attend all lessons

d)

after each lesson, students must complete homework

7.

The database has a Schedule table with the following columns: schedule_id, course_id, teacher_id, group_id, time, room, day_of_week. Select the possible query for this table.

a)

show group lessons by its id

b)

show how well students understand

c)

the lesson material

show student marks by student_id

d)

show which course students like the most

8.

The database has a Courses table with the following columns: course id, course name, number of credits. Select the possible query for this table.

a)

show the number of credits by course name

b)

show course description by course name

c)

show the most interesting courses

d)

show a course with a lot of homework

9.

A teacher teaches one or more groups, each of which is taught by one or more teachers. The TEACHERS table has teacher_id, teacher_name columns. The GROUPS table has group_id, name columns. Identify a table with a Foreign Key(s) for the relationship between TEACHERS and GROUPS tables.

a)

TEACHERS

b)

GROUPS

c)

in the TEACHERS table or in the GROUPS table - both options are correct

d)

associative table between TEACHERS and GROUPS tables

10.

A teacher may be assigned with exactly one position. A position must be assigned to one or many teachers. The TEACHERS table has teacher_id, teacher_name, birthdate columns. The POSITIONS table has position_id, position_name columns. Identify a type of the relationship between TEACHERS and POSITIONS entities.

a)

many (teachers)-to-many (positions)

b)

one (positions)-to-many (teachers)

c)

one (teachers)-to-many (positions)

d)

one (teachers)-to-one (positions)

11.

A teacher may be assigned with exactly one position. A position must be assigned to one or more teachers. The TEACHERS table has teacher_id, teacher_name, birthdate columns. The POSITIONS table has position_id, position_name columns. Identify a table with a Foreign Key(s) for the relationship between TEACHERS and POSITIONS tables.

a)

in the TEACHERS table or in the POSITIONS table - both options are correct

b)

associative table between TEACHERS and POSITIONS tables

c)

TEACHERS

d)

POSITIONS

12.

A teacher teaches one or more groups, each of which is taught by one or more teachers. The TEACHERS table has teacher_id, teacher_name columns. The GROUPS table has group_id, name columns. Identify a type of the relationship between TEACHERS and GROUPS tables.

a)

one (groups)-to-many (teachers)

b)

one (teachers)-to-one (groups)

c)

one (teachers)-to-many (groups)

d)

many (teachers)-to-many (groups)

13.

A teacher teaches one or more subjects, each of which is taught by one or more teachers. Definitions of the entities are: Teachers (teacher_id, name, birthdate), Subjects (subject_id, name, description). Identify a type of the relationship between TEACHERS and SUBJECTS tables.

a)

many (teachers)-to-many (subjects)

b)

one (subjects)-to-many (teachers)

c)

one (teachers)-to-many (subjects)

d)

one (teachers)-to-one (subjects)

14.

A teacher teaches one or more subjects, each of which is taught by one or more teachers. Definitions of entities are: Teachers (teacher_id, name, birthdate), Subjects (subject_id, name, description). Identify a table with a Foreign Key(s) for the relationship between TEACHERS and SUBJECTS tables.

a)

in the Teachers table or in the Subjects table - both options are correct

b)

Subjects

c)

Teachers

d)

associative table between Teachers and Subjects tables

15.

Entities Groups and Subjects have a many-to-many relationship type. For this reason a new associative table between them should be created - Schedule table. Definitions of tables are: Groups (group_code (PK), group_name), Subjects (subject_code (PK), subject_name, description). Identify attributes in the Schedule table.

a)

schedule_id (PK), group_code (FK), subject_code (FK)

b)

schedule_id (PK), subject_name (FK)

c)

schedule_id (PK), group_code (FK)

d)

schedule_id (PK), group_name (FK), subject_name (FK)

16.

Determine the relationship type between Courses and Teachers entities by the description: "One course can be taught by many teachers, and one teacher can teach many courses".

a)

none of the given

b)

one-to-one

c)

many-to-many

d)

one-to-many

17.

Determine the relationship type between Students and Groups entities by the description: "One student can be enrolled only in one group, and one group contains many students".

a)

none of the given

b)

one-to-one

c)

one-to-many

d)

many-to-many

18.

Determine the relationship type between Students and Readers entities by the description: "One student has only one reader's card, and one reader's card can belong to only one student".

a)

none of the given

b)

many-to-many

c)

one-to-one

d)

one-to-many

19.

In an ER-diagram an entity is represent by a

a)

ellipse

b)

rectangle

c)

rhombus

d)

circle

20.

Select the functional dependency according to the table description: Teachers (teacher_id, last_name, department_id)

a)

none of the given

b)

full

c)

transitive

d)

partial

21.

Select the functional dependency according to the table description: Courses (course_id, course_name, credits)

a)

transitive

b)

none of the given

c)

partial

d)

full

22.

Select the Normal Form by the table description: Teachers (teacher_id, last_name, department_id)

a)

2

b)

3

c)

1

d)

0

23.

Select the Normal Form by the table description: Courses (course_id, major_id, course_name, credits, major_name)

a)

0

b)

3

c)

2

d)

1

24.

Select the Normal Form by the table description: Groups (group_id, group_name, adviser_id, adviser_last_name)

a)

1

b)

0

c)

2

d)

3

25.

Select the Normal Form by the table description: Students (stud_id, last_name, subject_ids)

a)

0

b)

1

c)

2

d)

3

26.

Select the functional dependency according to the table description: Students (stud_id, last_name, group_id)

a)

partial

b)

full

c)

transitive

d)

none of the given

27.

Answer if the next table has a partial dependency: Courses (course_id, major_id, course_name, credits, major_name)

a)

no

b)

yes

28.

Answer if the next table has a partial dependency: Teachers (teacher_id, last_name, department_id)

a)

yes

b)

no

29.

Answer if the next table has a partial dependency: Schedule (teacher_id, group_id, course_id, time, room)

a)

yes

b)

no

30.

Complete the code to create the table Teachers (teach_id, last_name, depart_id (FK)): CREATE TABLE Teachers teach_id int PRIMARY KEY, last_name varchar(20), depart_id int, _______ (depart_id) REFERENCES Departments(depart_id));

a)

FOREIGN KEY

b)

FOREIGN

c)

PRIMARY KEY

d)

KEY

31.

Complete the code to drop the table Courses:

a)

REMOVE TABLE

b)

DELETE TABLE

c)

DROP COLUMN

d)

DROP TABLE

32.

Complete the code to create the table Departments (dep_id, dep_name): CREATE TABLE Departments dep_id int _______, dep_name varchar(15));

a)

PRIMARY KEY

b)

KEY

c)

FOREIGN KEY

d)

PRIMARY

33.

Complete the code to create the table Students (stud_id, last_name): CREATE TABLE Students stud_id int, last_name varchar(20), ________ (stud_id));

a)

KEY

b)

PRIMARY KEY

c)

FOREIGN KEY

d)

PRIMARY

34.

Complete the code to create the table Groups (group_id, group_name): ________ Groups (group_id int PRIMARY KEY, group_name varchar(20));

a)

CREATE

b)

CREATE TABLE

c)

TABLE

d)

ALTER TABLE

35.

The SQL command which allows to change the structure of a table is

a)

ALTER DATABASE

b)

DROP TABLE

c)

ALTER TABLE

d)

CREATE TABLE

36.

Which of the following SQL statements can be used to create a table?

a)

CREATE TABLE

b)

ALTER TABLE

c)

CREATE DATABASE

d)

ADD TABLE

37.

Complete the code to create the table Courses (course id, name): CREATE TABLE Courses( course_id int _______, name varchar(10));

a)

PRIMARY KEY

b)

KEY

c)

PRIMARY

d)

FOREIGN KEY

38.

Complete the code to create the table Departments (dep_ id, name, faculty_id), where faculty_id is a FK to the table Faculties: CREATE TABLE Departments (dep_id int PRIMARY KEY, name varchar(10), faculty_id int, ________ (faculty_id) REFERENCES Faculties(faculty_id));

a)

FOREIGN KEY

b)

PRIMARY KEY

c)

REFERENCES

d)

FOREIGN

39.

Complete the code to create the table Departments (dep id, dep_name), where dep_name attribute has the not null constraint: CREATE TABLE Departments (dep_id int PRIMARY KEY, dep_name varchar(10) IS ________));

a)

NOT NULL

b)

UNIQUE

c)

NULL

d)

PRIMARY KEY

40.

Complete the code for the following table Subjects (subj_id (PK), name, credits): UPDATE Subjects SET credits=5 _______ credits=3;

a)

WHERE

b)

WHEN

c)

IF

d)

WITH

41.

Complete the code for the following table Subjects (subj_id (PK), name, credits): _______ SET credits=credits+1;

a)

UPDATE Subjects

b)

ALTER TABLE Subjects

c)

Subjects

d)

UPDATE

42.

Complete the code for the following table Faculties(facult_id (PK), name): DELETE FROM Faculties ______ facult_id=1;

a)

WHEN

b)

SET

c)

WITH

d)

WHERE

43.

Complete the code for the following table Groups(group_id (PK), name): ______ SET name='Database Design' WHERE group_id=1;

a)

ALTER TABLE Groups

b)

Groups

c)

UPDATE

d)

UPDATE Groups

44.

Complete the code for the following table Groups(group_id (PK), name): DELETE FROM Groups _____ group_id=1;

a)

DROP

b)

WHEN

c)

WITH

d)

WHERE

45.

Complete the code for the following table Students(stud_id (PK), lastname): DELETE FROM Students WHERE _____= 1;

a)

id

b)

stud_id

c)

student_number

d)

PK

46.

Complete the code: _____ Students VALUES (1,'FirstName1','LastName1','2000-01-01'1);

a)

INSERT INTO

b)

DELETE FROM

c)

CREATE TABLE

d)

UPDATE

47.

Complete the code: DELETE FROM Students ______ stud_id=2;

a)

WHERE

b)

AND

c)

WHEN

d)

WITH

48.

Complete the code for the following table Departments(dep_id(PK), name): UPDATE Departments _____ name='IT' WHERE depart_id=1;

a)

SET

b)

FOR

c)

WHERE

d)

GET

49.

Complete the code for the following table Faculties(facult_id (PK), name): ______ Faculties SET name='Information Technology' WHERE name='IT';

a)

ALTER TABLE

b)

UPDATE

c)

CHANGE

d)

UPDATE Faculties

50.

Rows are also called records 

a)

True

b)

False

51.

Primary key must contain unique values

a)

True

b)

False

52.

What is  Subject Area Analysis?

a)

Subject area analysis determines initial functionality requirements and defines project boundaries.

b)

Subject area analysis allows you to identify essence of project.

c)

Subject area analysis defines information in the future project.

d)

All answers are correct.

53.

Database is an organized collection of data, stored and accessed electronically.   

a)

True

b)

False

54.

Tables are also called relations

a)

True

b)

False

55.

The database has a Students table with the following columns: student_id, first_name, last_name, iin, email, phone_number. Select which of the following constraints cannot be implemented for this table?

a)

IIN must be unique

b)

first name cannot be empty

c)

number of symbols of phone number must be 11

d)

student must have excellent grades

56.

Primary key can be empty

a)

True

b)

False

57.

Rows are also called  tuples   

a)

True

b)

False

58.

Primary key is a column in a table which uniquely identifies each row in a table

a)

True

b)

False

59.

Columns are also called attributes

a)

True

b)

False

60.

What is Relational database? 

Define incorrect answer.

a)

Relational database is a database based on the relational model of data

b)

Relational database is a database that does not use tables and attributes

c)

Relational model organizes data into tables of columns and rows, with a unique key (or Primary key) identifying each row

d)

Relational database is a database proposed by E.F. Codd in 1970

61.

The University database contains Teachers and Advisors tables. Usually teachers and advisors are different people, but some of them may hold 2 positions and, as a result, will be recorded in both tables. The Teachers table contains teach_id (PK), last_name, first_name attributes, while the Advisors table contains adv_id (PK), last_name, first name attributes. Which operator (command) can be used to obtain a list of only teachers - excluding those people who occupy 2 positions at the same time?

a)

INTERSECT

b)

UNION

c)

EXCEPT

62.

Complete the code to get all columns from the table: SELECT ___ FROM Groups;

a)

*

b)

ALL COLUMNS

c)

group_id

d)

ALL

63.

The University database contains Teachers and Advisors tables. Usually teachers and advisors are different people, but some of them may hold 2 positions and, as a result, will be recorded in both tables. The Teachers table contains teach_id (PK), last_name, first_name attributes, while the Advisors table contains adv_id (PK), last_name, first_name attributes. Which operator (command) can be used to obtain a list of only those people who occupy 2 positions at the same time?

a)

UNION

b)

INTERSECT

c)

EXCEPT

64.

The University database contains Students and Groups tables. The Students table contains stud_id (PK), first_name, last_name, group_id (FK to the Groups table). The Groups table contains group_id (PK), name. Which of the following commands will list the names of students and the names of their groups? Only those students who are already enrolled in groups should be included in the list.

a)

RIGHT JOIN

b)

INNER JOIN

c)

FULL JOIN

d)

LEFT JOIN

65.

The University database contains Teachers and Advisors tables. Usually teachers and advisors are different people, but some of them may hold 2 positions and, as a result, will be recorded in both tables. The Teachers table contains teach_id (PK), last_name, first_name attributes, while the Advisors table contains adv_id (PK), last_name, first_name attributes. Which operator (command) can be used to obtain a general list of all teachers and advisors (in the form of a table with 2 columns first_name and last_name) ?

a)

UNION

b)

INTERSECT

c)

EXCEPT

66.

Complete the code to get all columns from the table: SELECT _____ FROM Departments;

a)

ALL COLUMNS

b)

ALL

c)

*

d)

department_id

67.

Aggregate function ... selects the average value.

a)

avg()

b)

sum()

c)

count()

d)

average()

68.

Aggregate function ... selects the minimum value.

a)

minimum()

b)

min()

c)

small()

d)

least()

69.

The ... clause divides the rows returned from the SELECT statement into groups. Then for each group, you can apply an aggregate function.

a)

HAVING

b)

GROUP BY

c)

WHERE

d)

ORDER BY

70.

The ... clause allows to sort rows by returned from a SELECT statement in ascending or descending order based on the specified criteria.

a)

ORDER BY

b)

HAVING

c)

GROUP BY

d)

ORDER WITH

71.

Aggregate function ... selects the maximum value

a)

peak()

b)

high()

c)

maximum()

d)

max()

72.

Aggregate function ... selects the number of occurrences (the number of tuples that satisfy a selection condition).

a)

amount()

b)

sum()

c)

count()

d)

number()

73.

The ... operator compares the value of attribute to each value returned by the subquery. This keyword (which must follow a comparison operator) returns TRUE if the comparison is TRUE for any of the values in the column that the subquery returns.

a)

EXISTS

b)

ANY

c)

AT LEAST

d)

ALL

74.

Write the possible operator when a result of a subquery is multiple values (multiple fields).

a)

none of the given

b)

=

c)

<>

d)

IN

75.

SELECT SQL statement(s) with which subqueries can be used.

a)

only with INSERT

b)

only with UPDATE and DELETE

c)

only with SELECT

d)

all of the given

76.

The ... operator (which must follow a comparison operator) compares the value of attribute to every value returned by the subquery. The result is true if all rows yield true. The result is false if any false result is found.

a)

EXISTS

b)

ALL

c)

ANY

d)

EVERY

77.

Select the condition when the «=» operator can be used with a subquery.

a)

the result of the subquery is one value (one field)

b)

the subquery contains the GROUP BY keyword

c)

the result of the subquery is multiple values (multiple fields)

d)

none of the given

78.

SQL allows testing the emptiness of a subquery's result using the ... keyword.

a)

IS NULL

b)

ANY

c)

ALL

d)

EXISTS

79.

Can the SELECT statement on which the view is based contain a join operation?

a)

yes

b)

no

80.

If the records in the physical table have changed, will the view show the updated records?

a)

yes

b)

no

81.

What statement is used to create a view?

a)

ADD VIEW

b)

NEW VIEW

c)

CREATE TABLE

d)

CREATE VIEW

82.

Which statement can be used to slightly change the structure of a view?

a)

ALTER TABLE

b)

CREATE OR REPLACE VIEW

c)

ALTER VIEW

d)

CHANGE VIEW

83.

What statement can be used to show rows from a view?

a)

CHOOSE

b)

SHOW

c)

CREATE TABLE

d)

SELECT

84.

What keyword is used to create а СТЕ?

a)

BY

b)

СТЕ

c)

WITH

d)

USING