Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

SQL MCQ

Total questions: 51

Worksheet time: 38mins

Name
Class
Date
1.

Which answer is NOT a type of table index?

a)

nonclustered

b)

unique

c)

heap

d)

hash

2.

The keywords AND, IN, LIKE, and between all belong to a category called what?

a)

joining operations

b)

linking operations

c)

criteria operations

d)

logical operations

3.

What is the result of this series of statements?

BEGIN TRY

SELECT 'Foo' ASResult;

END TRY

BEGIN CATCH

SELECT 'Bar' ASResult;

END CATCH

a)

Foo

b)

FooBar

c)

Foo Bar

d)

Bar

4.

Given these two tables, which query generates a listing showing student names

and the department office location where you could reach each student?

a)

SELECT Students.first_name, Students.last_name, Departments.office_location FROM Students, Departments;

b)

SELECT Students.first_name, Students.last_name, Departments.office_location

FROM Students JOIN Departments ON Students.department = Departments.department;

c)

SELECT Students.first_name, Students.last_name, Departments.office_location

FROM Students JOIN Departments;

d)

SELECT Students.first_name, Students.last_name, Departments.office_location

FROM Students ON Students.department = Departments.department;

5.

Given the Games table pictured, which query generates the results shown?

a)

SELECTGameType, MaxPlayers, count(*) ASNumberOfGames

FROMGames

GROUP BYMaxPlayers, GameType

ORDER BYMaxPlayers, GameType;

b)

SELECTGameType, MaxPlayers, count(*) ASNumberOfGames

FROMGames

GROUP BYGameType, MaxPlayers

ORDER BYGameType;

c)

SELECTGameType, count(Players) ASMaxPlayers, NumberOfGames

FROMGames

GROUP BYGameType, MaxPlayers

ORDER BYGameType;

d)

SELECTGameType, MaxPlayers, count(*) ASNumberOfGames

FROMGames

GROUP BYGameType

ORDER BYMaxPlayers;

6.

Which answer is a possible result of the sequence of commands below?

DECLARE@UniqueID uniqueidentifier = NEWID();

SELECT@UniqueID ASResult;

a)

1

b)

bb261196-66a5-43af-815d-123fc593cf3a

c)

z350mpj1-62lx-40ww-9ho0-4u1875rt2mx4

d)

0x2400001155F04846674AD4590F832C0

7.

You need to find all students that are not on the "Chemistry Cats" team. Which

query does NOT work for this task?

a)

WHERE team NOT 'Chemistry Cats';

b)

WHERE team <> 'Chemistry Cats';

c)

WHERE team != 'Chemistry Cats';

d)

WHERE NOT team = 'Chemistry Cats';

8.

You need to write a query that returns all Employees that have a LastName starting with the letter A. Which WHEREclause should you use to fill in the blank in this query?

a)

WHERE LastName = A*

b)

WHERE LastName = LIKE '%A%'

c)

WHERE LastName LIKE 'A%'

d)

WHERE LastName IN ('A*')

9.

Which query shows the first name, department, and team of all students with the

two lowest points?

a)

SELECT LIMIT(2) first_name, department, team FROM Students ORDER BY points ASC;

b)

SELECT TOP(2) first_name, deprtment, team FROM Students ORDER BY points DESC;

c)

SELECT TOP(2) WITH TIES first_name, department, team FROM Students ORDER BY

points;

d)

SELECT BOTTOM(2) first_name, department, team FROM Students ORDER BY points ASC;

10.

What is the result of this statement?

SELECT FLOOR(-1234.321)

a)

-1234.3

b)

-1234

c)

-1235

d)

1234.321

11.

Which is the best approach to update the last name of the student Donette

Figgins to Smith

a)

UPDATE Students SET last_name = 'Smith' WHERE email =

'dfiggins@rouxacademy.com';

b)

UPDATE Students SET last_name = 'Figgins' WHERE email =

'dfiggins@rouxacademy.com';

c)

UPDATE Students SET last_name = 'Figgins' WHERE last_name = 'Smith' AND firstname = 'Donette';

d)

UPDATE Students SET last_name = 'Smith' WHERE last_name = 'Figgins' AND firstname = 'Donette';

12.

Which of these data types is an approximate numeric?

a)

real

b)

bit

c)

decimal

d)

numeric

13.

You need to remove all data from a table name Products. Which query fully logs

the removal of each record?

a)

TRUNCATE FROM Products *;

b)

DELETE FROM Products;

c)

DELETE * FROM Products;

d)

TRUNCATE TABLE Products;

14.

What is the result of this query?

SELECT 1 / 2 ASResult;

a)

0.5

b)

error

c)

0

d)

2

15.

which data type will most efficiently store a person's age in years?

a)

float

b)

int

c)

tinyint

d)

bigint

16.

What is the result of this query?

SELECT 'abc\

def' ASResult;

a)

abc\def

b)

abcdef

c)

error

d)

abc def

17.

To select a random student from the table, which statement could you use?

a)

SELECT TOP(1) first_name, last_name FROM Students ORDER BY NEWID();

b)

SELECT TOP(1) RAND(first_name, last_name) FROM Student;

c)

SELECT TOP(1) first_name, last_name FROM Student;

d)

SELECT TOP(1) first_name, last_name FROM RAND(Student);

18.

What result is returned after executing the following commands?

DECLARE@MyVariable int;

SET@MyVariable = 1;

GO

SELECT@MyVariable;

a)

error

b)

1

c)

null

d)

@MyVariable

19.

Which statement creates a new database schema named Sales and establish

Sharon as the owner?

a)

ALTER USER Sharon WITH DEFAULT_SCHEMA = Sales;

b)

ALTER USER Sharon SET SCHEMA Sales;

c)

CREATE SCHEMA Sales SET OWNER Sharon;

d)

CREATE SCHEMA Sales AUTHORIZATION Sharon;

20.

The result of a CROSS JOINbetween a table with 4 rows, and one with 5 rows, will

give with _ rows.

a)

1024

b)

20

c)

0

d)

9

21.

You need to write a query that returns all products that have a SerialNumber

ending with "10_3". Which WHEREclause should you use to fill in the blank in this

query?

SELECTProductID, ProductName, SerialNumber

FROMProducts______ ;

a)

WHERE SerialNumber LIKE '%10_3'

b)

WHERE SerialNumber LIKE ('%10'+'_'+'3')

c)

WHERE SerialNumber LIKE '%10"_"3'

d)

WHERE SerialNumber LIKE '%10[_]3'

22.

When no join type between multiple tables in a query's FROMclause is specified,

what type of join is assumed?

a)

INNER

b)

RIGHT

c)

LEFT

d)

FULL

23.

How many bytes of storage does the int data type consume?

a)

1 byte

b)

2 bytes

c)

4 bytes

d)

8 bytes

24.

What does a RIGHT JOINensure?

a)

that only records from the rightmost table will be displayed

b)

that no records from the rightmost table are displayed if the records dont have corresponding records in the left table

c)

that records from the rightmost table will be displayed only if the records have a

corresponding value in the leftmost table

d)

that all records from the rightmost table are represented in the result, even if there are

no corresponding records in the left table

25.

You execute the following three queries. What is the result?

Create tablestudents(id int identity(1000,1), firstname varchar(20),

lastname varchar(30));

insert intostudents(firstname,lastname)values('mark','twain');

select * fromstudents;

a)

studentid firstname lastname 1 1001 mark twain

b)

studentid firstname lastname 1 1 mark twain

c)

studentid firstname lastname 1 1000 mark twain

d)

studentid firstname lastname 1 null mark twain

26.

Given a table with the following structure, which query returns all student names

with the highest grade?

CREATE TABLEStudents (

StudentName varchar(50),

Grade int);

a)

SELECT StudentName FROM Students WHERE Grade = MAX(Grade);

b)

SELECT TOP(1) StudentName FROM Students ORDER BY Grade;

c)

SELECT TOP(1) WITH TIES StudentName FROM Students ORDER BY Grade DESC;

d)

SELECT StudentName, MAX(Grade) FROM Students ORDER BY Grade DESC;

27.

What role does "inventory" play?

selectbookid, boooktitle, bookauthor,quantityonhand from inventory.books;

a)

you only want to see results from books currently in inventory

b)

it instructs the query engine to find the books table in the inventory schema

c)

it instructs the query engine to find the books table in the inventory database

d)

it instructs the query engine to join the books table to the inventory schema

28.

What is the result of an INNER JOINbetween table1 and table2?

a)

Only records that have corresponding entries in table1 and table2 are displayed

b)

No records from table1 are ever displayed

c)

All records from table1 are displayed, regardless of whether the records have a

corresponding row in table2

d)

Only records that have no corresponding records in table1 or table2 are displayed

29.

To remove all of the content from the Students table but keep the schema, which

statement should you use?

a)

TRUNCATE TABLE Students;

b)

TRUNCATE * FROM Students;

c)

DROP TABLE Students;

d)

REMOVE * FROM Students;

30.

Review the CREATE TABLEstatement below. Which option, when placed in the

blank space, ensures that the BookISBN column will not contain any duplicate values?

CREATE TABLEBooks (

BookID int PRIMARY KEY,

BookISBN char(13) NOT NULL_____,

BookTitle nvarchar(100) NOT NULL

);

a)

NO DUPLICATES

b)

UNIQUE CONSTRAINT AK_Books_BookISBN

c)

DUPLICATE CONSTRAINT (AK_Books_BookISBN)

d)

CONSTRAINT AK_Books_BookISBN UNIQUE

31.

Given a table with the following structure, which query will not return the lowest

grade earned by any student?

CREATE TABLEStudents (

StudentName varchar(50),

Grade int

);

a)

SELECTStudentName

FROMStudents

WHEREGrade =(SELECT MIN(Grade) FROMStudent);

b)

SELECT TOP(1) Grade

FROMStudents

ORDER BYGrade;

c)

SELECT MIN(Grade)

FROMStudents

d)

SELECT MIN(Grade)

FROMStudents

ORDER BYGrade;

32.

You would like to have a record added to a TableB every time a record is modified

in TableA. What technique should you look at implementing?

a)

You should create a DML trigger on the server.

b)

You should create a DDL trigger on the database.

c)

You should create a DML trigger on TableA.

d)

You should create a DML trigger on TableB.

33.

What is the problem with this code?

DECLARE@Counter int;

SET@Counter = 1;

WHILE@Counter > 0

BEGIN

SET@Counter =@Counter +1;

END;

a)

There is no END WHILE statement;

b)

The local varaible is not available to the WHILE block.

c)

The query causes an infinite loop.

d)

"Counter" is an invalid variable name.

34.

What is the result of this query?

SELECT 123+'123' ASResult;

a)

error

b)

'123''123'

c)

123123

d)

246

35.

To combine the results of two or more SELECTstatements, removing duplicates,

which keyword can you use?

a)

DEDUPE

b)

SELECT

c)

MERGE

d)

UNION

36.

You run this series of statements. What is the final result?

CREATE TABLEMyTable (MyValue int);

INSERT INTOMyTable VALUES(1);

WHILE(SELECTMyValue FROMMyTable) < 5

BEGIN

UPDATEMy Table SETMyValue =MyValue + 1;

END;

SELECTMyValue ASResult FROMMyTable;

a)

5

b)

error

c)

1

d)

6

37.

Is there an error with this query? If so, which statement best describes the

problem?

SELECTOrderID, SUM(LineTotal) ASSubTotal

FROMSales

WHERE SUM(LineTotal) > 1000

GROUP BYOrderID

ORDER BYOrderID;

a)

Yes, a WHEREclause cannot be used with an aggregate function.

b)

Yes, you cannot GROUP BYand ORDER BYthe same field.

c)

No, there is nothing wrong with this query.

d)

Yes, the WHEREclause should use the SubTotalalias.

38.

You created the two tables below. Later, you decide that you want the database to

remove all books from the Books table if the related publisher is deleted from the

Publishers table. What command should you run?

CREATE TABLEBooks (

BookID int PRIMARY KEY,

BookTitle nvarchar(100) NOT NULL,

PublisherID int NOT NULL

);

CREATE TABLEPublishers (

PublisherID int PRIMARY KEY,

PublisherName nvarchar(50)

);

a)

ALTER TABLEBooks

ADD CONSTRAINTFK Books_PublisherID

FOREIGN KEY(PublisherID)

REFERENCESPublishers (PublisherID) ON UPDATE SET NULL

b)

ALTER TABLEBooks

ADD CONSTRAINTFK Books_PublisherID

FOREIGN KEY(PublisherID)

REFERENCESPublishers (PublisherID) ON DELETE CASCADE

c)

ALTER TABLEBooks

ADD CONSTRAINTFK_Books_PublisherID

FOREIGN KEY(PublisherID)

REFERENCESPublishers (PublisherID)

d)

ALTER TABLEPublishers

ADD CONSTRAINTFK_Publishers_PublisherID

FOREIGN KEY(PublisherID)

REFERENCESBooks (PublisherID) CASCADE DELETE

39.

Your database currently has a table called Inventory in the Warehouse schema.

You need to move the table to the Products schema. Which query accomplishes this

goal?

a)

ALTER SCHEMA Products TRANSFER Warehouse.Inventory;

b)

ALTER TABLE Warehouse.Inventory TRANSFER Products.Inventory;

c)

ALTER TABLE Warehouse.Inventory ADD SCHEMA Products;

d)

ALTER SCHEMA Warehouse ADD TABLE Inventory;

40.

Which option—when placed in the blank space—establishes the PersonlD column

as the primary key for the table with a nonclustered index?

CREATE TABLE People(

PersonID int NOT NULL,

PersonName nvarchar(50),

_______

);

a)

INDEX ON PersonID (PRIMARY KEY PK_People)

b)

ADD NONCLUSTERED PRIMARY KEY CONSTRAINT PK_People ON PersonID

c)

CONSTRAINT PK_People PRIMARY KEY NONCLUSTERED (PersonID)

d)

PRIMARY KEY CONSTRAINT (PersonID) NONCLUSTERED INDEX

41.

You need to create a simple database backup in the server's Z:\Backups

directory. Which query should you use?

a)

BACKUP MyDatabase TO LOCATION = 'Z:\Backups\MyDatabase.bak';

b)

CREATE BACKUP (DATABASE = 'MyDatabase' TO DISK = 'Z:\Backups\MyDatabase. bak');

c)

BACKUP DATABASE MyDatabase ON 'Z:\Backups\MyDatabase.bak';

d)

BACKUP DATABASE MyDatabase TO DISK = 'z:\Backups\MyDatabase.bak';

42.

Suppose you want to have the name of a transaction called myTransaction

recorded in the transaction log. Which statement represents the best way to

accomplish this?

a)

BEGIN TRAN myTransaction BEGIN LOG;

b)

BEGIN TRAN myTransaction WITH LOG;

c)

BEGIN TRAN myTransaction WITH MARK;

d)

BEGIN TRAN WITH MARK myTransaction;

43.

Though not currently a requirement, what will a future release of SQL Server

require of all SQL statements?Though not currently a requirement, what will a future

release of SQL Server require of all SQL statements?

a)

All statements must end with a semicolon.

b)

All statements must operate on a table of data.

c)

All statements must always be written in uppercase letters.

d)

All statements must include more than one variable.

44.

Which is the best approach to update the last name and email address of a

student with ID 56295?

a)

UPDATE Students SET last_name='Smith', email = 'dsmith@rouxacademy.com' WHERE

id='56295';

b)

UPDATE Students SET last_name='Smith', email = 'dsmith@rouxacademy.com' WHERE

id=56295;

c)

UPDATE Students SET last_name='Smith' AND email = 'dsmith@rouxacademy.com'

WHERE id=56295;

d)

UPDATE Students SET last_name='Smith' AND email = 'dsmith@rouxacademy.com'

WHERE id='56295';

45.

What is the result of this query?

SELECT 123+'abc' ASResult;

a)

123abc

b)

123'abc'

c)

'123abc'

d)

error

46.

What output will the following SQL sequence produce? Assume that the tables

have been created and all the columns exist.

INSERT INTOAccount (acct,bal) VALUES('12345', 100);

UPDATEAccount SETbal=bal+100;

BEGIN;

UPDATEAccount SETbal=bal+100.

ROLLBACK;

SELECTbal FROMAccount WHEREacct='12345';

);

a)

100

b)

200

c)

300

d)

You will get an error because ROLLBACK deletes the row that was update

47.

Which statement deletes a table named Inventory from the Products database?

a)

DROP TABLE Products.Inventory;

b)

USE Products;

DROP TABLE Inventory;

c)

USE Products;

DELETE Inventory;

d)

USE Products.Inventory;

DROP TABLE Inventory;

48.

In a SELECT statement, which clause should always be used with the TOP clause in

order to predictably indicate which rows are affected by TOP?

a)

GROUP BY

b)

HAVING

c)

WHERE

d)

ORDER BY

49.

Which data type should you choose when you nedd to store dates and times that

include time zone information?

a)

datetimeoffset

b)

smalldatetime

c)

datetime

d)

datetime2

50.

What is the result of this query?

SELECT 123+'123' ASResult;

a)

123'123'

b)

error

c)

246

d)

123123

51.

What is an example of a DDL command in SQL ?

a)

merge

b)

drop

c)

delete

d)

truncate table