You are on page 1of 6

1. Which of the following is NOT true about SQL transactions?

1. a transaction is cancelled using the ROLLBACK comand


2. the changes made by a transaction are saved in the database only when issuing
the COMMIT command
3. a transaction is started using the START TRANSACTION command
4. a transaction defines an atomic set of operations – either all of them succeed or
the entire transaction fails
5. the changes made by DDL commands included in a transaction can be
rolled back (cancelled)
ANS: 5

2. Which of the following features is supported by both the mysql and mysqli PHP
extensions?

1.  multi-query
2.  object-oriented programming interface
3.  procedural programming interface
4.  prepared statements
5.  transactions
6.  no answer
ANS: 3

3. Which of the following is a correct PDO DSN for connecting to a MySQL database
named People?

1.  mysql;host=localhost:3306,db=People
2.  mysql:host=localhost;port=3306;dbname=People
3.  mysql://host=localhost,port=3306,dbname=People
4.  mysql:host=localhost;port=3306;db=People
5.  mysql:hostname=localhost,port=3306,db=People
6.  no answer
ANS: 2

4. Prepared statements are useful when we need to:

1.  issue the same SQL query multiple times but with different parameter values
2.  query a MySQL server using functions from the mysql extension
3.  speed up a single query that searches through the values of a certain column from
an SQL table
4.  design the table structure of a future SQL database
5.  create a group of SQL statements that will execute atomically (they must all
succeed, or the whole operation fails)
6.  no answer
ANS: 1

5. Which of the following are true about the following SQL query, if the Products table
has 3 columns and 6 records and the Categories table has 2 columns and 3 records?
(choose three)

SELECT * FROM Products,Categories;

1.  the result of the query will have 9 records


2.  the result of the query will have 6 columns
3.  the result of the query will have 18 records
4.  the query is a join between the two SQL tables
5.  the result of the query will have 5 columns
ANS: 3, 4, 5

6. Which code fragment could be used after the sequence below in order to display the
list of names extracted from an SQL table named People? (choose three):

try{
$pdo = new PDO('mysql:host=localhost;dbname='Beings','user','pass');
}catch(PDOException $e){
die("An error has occured: ".$e->getMessage());
}

// next is the code for extracting and displaying the people's names
???

1. $r = $pdo->query("SELECT * FROM People");
$s = $r->fetchAll(PDO::FETCH_ASSOC);
foreach($s as $p)
echo $p['Name']."<br />";

2. $r = $pdo->query("SELECT * FROM People");
foreach($s = $r->fetch(PDO::FETCH_ASSOC))
echo $s['Name']."<br>";

3. foreach($pdo->query("SELECT * FROM people") as $s)
echo $s['Name']."<br>";
4. $r = $pdo->query("SELECT * FROM People");
while($s = $r->fetch(PDO::FETCH_NUM))
echo $s['Name']."<br>";

5. $r = $pdo->query("SELECT * FROM People");
while($s = $r->fetch(PDO::FETCH_ASSOC))
echo $s['Name']."<br>";

ANS: 1, 3, 5

7. An SQL table column whose values refer to the primary key from another table is
called:

1.  unique index
2.  primary key
3.  exported index
4.  linked column
5.  foreign key
6.  no answer
ANS: 5

8. Which of the following are true about the SQL query below? (choose two)

SELECT * FROM Categories LEFT JOIN Products ON (Product.ID = Categories.Produc
tID)

1.  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
2.  the result will always contain all the records from the Categories table
3.  if a category has no matching products, it will not be included in the query result
4.  the query will only select records that have NULL on the ProductID column
5.  the result will always contain all the records from the Products table
ANS: 1, 2

9. Which of the following are true about M-to-N relationships between two SQL tables?
(choose three)

1.  such a relationship is usually implemented in the database by creating a


third table having two foreign keys
2.  a record from the second table may have more than one corresponding
record in the first table
3.  an M-to-N relationship can't be defined on only two SQL tables – at least four
tables are required
4.  a record from the first table may have more than one corresponding record
in the second table
5.  M must be greater than N in order for the relationship to work
ANS: 1, 2, 4

10. Which of the following are valid ways of creating an SQL table named People that
has a unique index on the Name column? (choose three)

1. CREATE TABLE People(Name VARCHAR(50) NOT NULL ADD INDEX UNI
QUE, Age INT);
2. CREATE TABLE People (Name VARCHAR(50) NOT NULL, Age INT);
ALTER TABLE People ADD UNIQUE(Name);

3. CREATE TABLE People(Name VARCHAR(50) NOT NULL INDEX TYPE UNI
QUE, Age INT);

4. CREATE TABLE People (Name VARCHAR(50) NOT NULL UNIQUE, Age 
INT);

5. CREATE TABLE People (Name VARCHAR(50) NOT NULL, Age INT);
CREATE UNIQUE INDEX Name ON People(Name);

ANS: 2, 4, 5

11. The PHP programmer can NOT work with a MySQL database using:

1.  the procedural programming interface of the PHP mysql extension


2.  the procedural programming interface of the PHP mysqli extension
3.  the object-oriented programming interface of the PHP PDO extension
4.  the object-oriented programming interface of the PHP mysqli extension
5.  the object-oriented programming interface of the PHP mysql extension
6.  no answer
ANS: 5

12. What will the following code sequence display in the browser when executed via a
web server?
$c = new mysqli('localhost', 'user', 'pass', 'db');
$sql = "SELECT * FROM People";
$result = mysqli_query($sql);
while($p = mysqli_fetch_assoc($r))
echo "$p[name]\n";

1.  an error, because the correct syntax for the last line should have been echo
"$p['name']\n";
2.  an error, because the constructor of the mysqli class only accepts 3 arguments
3.  an error, because the mysqli_query() function must receive the connection
identifier as its first argument
4.  a list of people names, one on each line
5.  a list of people names, one after another on one line
6.  no answe
ANS: 3

13. Which of the following are advantages of using indexes in SQL tables? (choose two)

1.  increased speed when issuing INSERT queries that add data to an indexed
column
2.  increased speed of SELECT statements having WHERE clauses that refer to
indexed columns
3.  less space occupied by SQL tables that contain indexes
4.  increased speed when deleting data from an SQL table that contains indexed
columns
5.  increased speed when sorting query results (using ORDER BY) according to
an indexed column
ANS: 2, 5

14. Which of the following correctly describe the predefined classes from the mysqli
extension? (choose three)

1.  the mysqli_result class represents a result set obtained from a query


2.  the mysqli class is an abstract class that is extended by all the other classes from
the mysqli extension
3.  the mysqli_stmt class represents a prepared statement
4.  the mysqli_result class represents the error info generated by an SQL query
5.  the mysqli class represents a connection between PHP and a MySQL
database
ANS: 1, 3, 5
15. Which of the following are true regarding the properties of the various types of
MySQL indexes? (choose three)

1.  a column declared as a primary key may not contain NULL values


2.  a column declared as a primary key may contain NULL values
3.  a single-column unique index will allow multiple NULL values on that
column if the column was not defined using the NOT NULL attribute
4.  each value of a column declared as the primary key of a table uniquely
identifies its row (record) in the table
5.  a unique index defined on a table column introduces no restrictions on the data
contained in that column
ANS: 1, 3, 4

You might also like