Академический Документы
Профессиональный Документы
Культура Документы
1. Given an SQL table named t having a column of type INT named c and the contents
below, what will the following query produce?
2. Given a populated SQL table having the definition below, what will the SELECT query
produce?
CREATE TABLE Shopping(ProductName VARCHAR(100),
Category VARCHAR(100),
Date DATETIME);
SELECT Category, Date, COUNT(DISTINCT ProductName) AS nr FROM Shopping
WHERE Date>(CURRENT_DATE-
INTERVAL 7 DAY) GROUP BY Date, Category HAVING nr>1;
a. the number of different products bought from each category every day in the last
7 days, only if more than one product from that category has been bought that day
b. the number of different products bought from each category more than 7 days
ago, if that category includes at least 2 products
c. the number of products bought from each category starting 7 days ago
d. the number of different products bought each day for dates older than a week
ago, only if more than one product from each category has been bought that day
A
3. Which of the following are true regarding NULL values in MySQL expressions?
(choose three)
a. the = operator can be used for testing if one of its operands is NULL
b. the <=> operator will return 1 if any of its operands is NULL
c. most operators return 0 when one of the operands is NULL
d. when testing if an expression evaluates as NULL, the IS NULL or IS NOT NULL
operators may be used
e. most operators return NULL when one of the operands is NULL
f. the <=> operator will return 1 if both operands are NULL
DEF
a. 0, 1 or 2
b. 1 or 2
c. 0 or 1
d. 0, 1 or -1
e. 0 or -1
5. What will be the value of the MySQL expression s1 = s2 if column s1 has the value
'Test' and column s2 has the value 'TEST'?
a. 1
b. NULL
c. the = operator can't take column name as operands
d. depends on the charset and collation of the columns
e. 0
D
6. Which of the following are valid ways of representing an integer value of 161 inside a
MySQL expression? (choose four)
a. `161`
b. 161
c. 0xA1
d. x'A1'
e. xA1
f. X'A1'
BCDF
8. What value will be inserted on the Year column when executing the statements below
on a MySQL server?
CREATE TABLE Dates(Year YEAR(4) NOT NULL);
INSERT INTO Dates VALUES(2);
a. 2002
b. 2
c. 1902
d. 0000, because the inserted value is not valid
A
9. Given an SQL table named People, having 10 records, and the two SELECT
statements below that operate on a column named Weight from that table, which of
the following is NOT true?
SELECT FLOOR(Weight) FROM People;
SELECT AVG(Weight) FROM People;
10. Which of the following are MySQL aggregate functions? (choose two)
a. INSTR()
b. MIN()
c. LPAD()
d. CONCAT_WS()
e. AVG()
f. LEAST()
BE
11. After the table having the definition below has been populated with data, which of the
following SELECT statements will NOT produce the same result as the others?
B
12. What values will be inserted in the Numbers table when executing the statements
below?
CREATE TABLE Numbers (c1 INT, c2 FLOAT, c3 INT);
INSERT INTO Numbers VALUES(8%5, 8/5, 8 DIV 5);
a. 3, 1.6, 3
b. 3, 1.6, 1
c. 1.6, 1.6, 3
d. 8, 1.6, 1.6
e. 1.6, 1.6, 1.6
13. Given an SQL table column named TimeInterval, containing values of the form
HH:MM:SS (where H=hour, M=minute, S=second), which of the following expressions
can be used for extracting the number of minutes from the values of that column?
(choose four)
a. MINUTE(TimeInterval)
b. SUBSTR(TimeInterval, 4, 2)
c. SUBSTR(TimeInterval,2,4)
d. LEFT(RIGHT(TimeInterval,5),2)
e. SUBSTR(TimeInterval,LOCATE(':',TimeInterval)+1,2)
f. SUBSTR(TimeInterval, 3, 5)
ABDE
14. Given a table named Dates that contains the columns Day, Month, Year and Fulldate,
how could the Fulldate column be populated based on the values found in the other
three? (choose two)
AD
15. Which of the following SQL statements will return all the records from the People table
whose names are missing? (choose two)
CE
TEST 6
1. What is the difference between an inner join and an outer join between two tables?
a. an inner join always retrieves all the records from one of the tables involved, while
an outer join only keeps records from one table that have corresponding records in the
other table
b. an inner join may only be performed on a single table, while an outer join may be
performed on multiple tables
c. an inner join only shows corresponding records from the tables involved, while an
outer join always returns all the records from one of the tables even if there are no
corresponding records in the other one
d. an inner join may only be performed inside the same database, while an outer
join may involve multiple tables from different databases or even different servers
2. Which of the following are true about the SQL query below? (choose two)
a. the result will always contain all the records from the Products table
b. if a category has no matching products, it will not be included in the query result
c. the result will always contain all the records from the Categories table
d. if a category has no matching products, it will still be displayed in the result, but
the columns corresponding to the Products table will contain the NULL value
e. the query will only select records that have NULL on the ProductID column
CD
3. Which of the following statements will correctly create a table named Users having a
unique index on the Username column? (choose two)
AB
4. Which of the following types of indexes could be defined on a table column if we need
the values of the column to be unique but want to allow NULL values?
a. non-unique index
b. unique index
c. there is no type of index that can enforce that set of restrictions
d. primary key
5. Which of the following are advantages of using indexes in SQL tables? (choose two)
AB
6. Which of the following statements will join the Products and Categories tables and
return all products from the 'books' category, if the c_id column from the Products table
is referring the c_id column from the Categories table? (choose two)
CE
7. Which of the following types of indexes can be defined in MySQL? (choose three)
ACD
8. Which answer correctly pairs each case described with the correct type of
relationship?
1. Students and Classes: each student may be part of multiple classes, and each class may
contain multiple students
2. Products and Categories: each product may be part of one category, and each category
may contain multiple products
3. Users and Usernames: each username corresponds to exactly one user
a. 1:1 b. 1:N c. M:N
a. 1-a,2-c,3-b
b. 1-b,2-c,3-a
c. 1-b,2-a,3-c
d. 1-c,2-b,3-a
e. 1-a,2-b,3-c
D
9. What will be the result of the SELECT query applied to the tables below?
a.
b.
c.
d.
10. Which of the following statements may be used for defining the column id as
the primary key of the Books table after the table has been created and filled
with data?
ABC
12. What is the difference between a unique index and a primary key?
a. a primary key allows for duplicate values while a unique index doesn't
b. a unique index allows for NULL values but a primary key does not
c. a unique index may be specified as part of the table's definition, while a primary
key may not
d. there may be multiple primary key indexes defined in one table, but only one
unique index is allowed
13. Given two related SQL tables named Pets and PetOwners having the
definitions below:
CREATE TABLE Pets (id INT AUTO_INCREMENT PRIMARY KEY, Name VARCHAR(50));
CREATE TABLE PetOwners (id INT AUTO_INCREMENT PRIMARY KEY, OwnerName VA
RCHAR(50), PetID INT);
what will the following query return after the tables have been populated with data?
SELECT * FROM Pets WHERE Pets.id = (SELECT * FROM PetOwners WHERE OwnerNa
me='John');
E
14. Which of the following are true about M-to-N relationships between two SQL
tables? (choose three)
a. a record from the first table may have more than one corresponding record in the
second table
b. M must be greater than N in order for the relationship to work
c. a record from the second table may have more than one corresponding record in
the first table
d. such a relationship is usually implemented in the database by creating a third
table having two foreign keys
e. an M-to-N relationship can't be defined on only two SQL tables – at least four
tables are required
ACD
15. An SQL table column that contains values of the primary key from another table
is called:
a. primary key
b. exported key
c. index key
d. unique key
e. foreign key
E
16. Which of the following queries return all the people that have 5 or 7 children
from the table having the definition below? (choose three)
a. SET autocommit=0
b. START TRANSACTION
c. SET autocommit=1
d. BEGIN
2. Which of the following types of SQL statements can be undone when cancelling
an ongoing transaction?
a. DCL
b. DDL
c. DML
d. none of the above
e. all of the above
3. Will the table having the definition below be able to support transactions?
D
4. After executing the set of SQL statements below, which of the following SQL
statements will fail?
D
5. Given the variable definition below, which of the following correctly creates a
prepared statement named st? (choose two)
SET @q = 'SELECT * FROM Products WHERE productID=?'
CE
6. Given the MySQL variable defined using the statement below, which of the
following SQL statements shows an incorrect use of this variable?
@a = 5;
A
7. If a MySQL client has an ongoing transaction with a MySQL server, which
actions of the client will make the changes made so far permanent? (choose
four)
ABDF
8. Which of the following SQL statements allows the client to obtain the list of
views defined in the current database?
a. SHOW TABLES
b. SHOW VIEWS
c. SHOW FULL TABLES
d. DESCRIBE VIEWS
e. SHOW CREATE VIEWS
9. Which of the following operators can be used for assigning a value to a MySQL
user-defined variable? (choose two)
a. :
b. =:
c. =
d. ==
e. :=
CE
10. Which of the following SQL statements correctly defines an SQL view?
11. What will be the values of variables @a and @b after the following set of SQL
statements executes?
SET @a=5; SET @b=@a+1; SELECT @a=6,@a:=@a+@b,@b=8;
a. 12 and 8
b. 11 and 6
c. 11 and 8
d. 12 and 6
a. rolling back a transaction will undo all changes made by all the server's clients
since starting the transaction
b. committing a transaction will undo all changes made by the client who started it
since the beginning of the transaction
c. if a client starts a transaction, any other client will be able to roll it back
d. rolling back a transaction will undo all changes made by the client who initiated it
since the start of the client's MySQL session
e. a transaction is a set of SQL statements that execute atomically (either all of them
succeed or they do not modify data)
E
13. SQL views can be used for: (choose three)
a. storing useful predefined queries in the database, that act as virtual tables
b. gradually changing the structure of a database while maintaining compatibility
with current client applications
c. atomically executing sets of SQL statements, with the possibility of rolling them
back in case of error
d. defining precompiled queries that can be later executed using various sets of
input parameters
e. restricting the columns and/or rows of an SQL table that a client can access
ABE
14. Which of the following is a precompiled query defined by the client that can be
later executed repeatedly with various input parameters?
a. transaction
b. prepared statement
c. user variable
d. view
15. Which of the following types of query can be used for defining an SQL view?
a. UPDATE
b. SELECT
c. DELETE
d. INSERT
16. Which of the following are true regarding MySQL client-defined (session)
variables? (choose two)
a. using aggregation functions in the SELECT statement that defines the view
b. creating a one-to-one relationship between the rows in the view and the rows in
the base table
c. defining a view that only contains derived columns (calculated using expressions)
d. using the MERGE algorithm
e. using DISTINCT in the SELECT statement that defines the view
f. using the TEMPTABLE algorithm
ACEF
18. Which of the following statements will show the list of columns that a view
produces? (choose three)
BDE
TEST 8
1. When executing the set of statements below using the mysql client, what will the CALL
statement produce?
DELIMITER $
SET @a=2;
CREATE PROCEDURE p(IN id INT) BEGIN
SELECT Name FROM Products WHERE productID=id INTO @b;
END$
CALL p(@a);
a. 10
b. 0
c. 4
d. NULL
4. What is wrong with the following stored function definition? (choose two)
BC
5. In MySQL stored routines, a condition is:
6. Which of the following types of SQL code stored on the server is attached to a table
and run automatically when table data is modified?
a. trigger
b. stored function
c. stored procedure
d. event
7. Which of the following are true about a MySQL stored function? (choose three)
BDF
8. Which of the following SQL statements can be used for forcefully exiting a labeled
BEGIN...END block inside a stored procedure?
a. LEAVE
b. REPEAT
c. LOOP
d. RETURNS
A
9. Which of the following is a valid use of a MySQL flow control construct?
10. A MySQL trigger can be automatically executed for which of the following types of
SQL statements? (choose three)
a. TRUNCATE
b. DROP
c. SELECT
d. UPDATE
e. DELETE
f. INSERT
DEF
11. Which of the following are true about a MySQL stored procedure? (choose three)
ADF
12. All of the following are true about MySQL local variables, EXCEPT:
a. local variables declared inside a stored routine will remain available after the
execution of the stored routine ends
b. local variables can be declared using the DECLARE statement
c. local variables must be declared before use
d. local variable names are not preceded with @
e. all local variables must be declared at the beginning of the stored routine, before
declaring any cursors, conditions or handlers
f. multiple local variables may be declared using a single DECLARE statement, but
they will all have the same type and default value
14. What is the value of @var after executing the following set of SQL statements?
SET @var = 0;
CASE @var+10
WHEN 0 THEN SET @var=10;
WHEN 10 THEN SET @var = 20;
WHEN 20 THEN SET @var = 30;
ELSE SET @var = 40;
END CASE;
a. 40
b. 10
c. 20
d. 30
C
15. A MySQL condition can be identified by its: (choose two)
a. attached cursor
b. MySQL error code
c. attached handler name
d. SQLSTATE code
BD
16. Choose the answer that corresponds to the correct order of DECLARE statements
inside a MySQL stored routine:
a. handlers
b. variables
c. cursors
d. conditions
a. a,b,c,d
b. b,d,c,a
c. c,d,b,a
d. d,b,c,a
B
17.What types of parameters may a MySQL stored procedure have? (choose three)
a. INOUT
b. RETURN
c. OUT
d. RETURNS
e. IN
ACE
18.Which of the following MySQL flow-control constructs are used for repeatedly
executing a set of SQL statements? (choose three)
a. CASE
b. LOOP
c. IF
d. REPEAT
e. WHILE
BDE