Tuesday 24 February 2015

oDesk MySQL 5.0 Test Answers

Odesk MySQL 5.0 Test Questions and Answers

Question: 1
 Which operator will be evaluated first in the following statement:
select (age + 3 * 4 / 2 – 8) from emp
a.   +
b.   -
c.   /
d.   * (answer)

Question: 2
Can you run multiple MySQL servers on a single machine?
a.   No
b.   Yes (answer)

Question: 3
Which of the following are not String column types?
a.   BLOB
b.   ENUM
c.   SET
d.   TEXT
e.   LONGCHAR (answer)

Question: 4
What is the maximum size of a row in a MyISAM table?
a. No limit
b. OS specific
c. 65,534 (answer)
d. 2’147’483’648
e. 128

Question: 5
Is the following query valid?
create table foo (id int primary key auto_increment, name varchar);
a.   No (answer)
b.   Yes

Question: 6
Considering table foo has been created with:
create table foo (id int primary key auto_increment, name varchar(100));
Is the following query syntactically valid?
delete from foo where id = id-1;
a.   Yes (answer)
b.   No

Question: 7
Which one of the following must be specified in every DELETE statement?

a. Table Name (answer)
b. Database name
c. LIMIT clause
d. WHERE clause

Question: 8
Which of the following formats does the date field accept by default?
a.   DD-MM-YYYY
b.   YYYY-DD-MM
c.   YYYY-MM-DD (answer)
d.   MM-DD-YY
e.   MMDDYYYY

Question: 9
Which of the following are aggregate functions in SQL?
a.   Avg (answer)
b.   Select
c.   Order By
d.   Sum (answer)
e.   Union
f.   Group by
g.   Having

Question: 10
What is the correct order of clauses in the select statement?
1        select
2        order by
3        where
4        having
5        group by
a.   1,2,3,4,5
b.   1,3,5,4,2 (answer)
c.   1,3,5,2,4
d.   1,3,2,5,4
e.   1,3,2,4,5
f.   1,5,2,3,4
g.   1,4,2,3,5
h.   1,4,3,2,5

Question: 11
Consider the following tables:
Books——
BookId
BookName
AuthorId
SubjectId
PopularityRating(the popularity of the book on a scale of 1 to 10)
Language(such as French, English, German etc)
Subjects———
SubjectId
Subject(such as History, Geography, Mathematics etc)
Authors——–
AuthorId
AuthorName
Country
Which is the query to determine the number of Authors who have written books on more than 2 subjects?
Possible answers:
a. select AuthorName from Authors where Authorid in (select Authorid from Books group by SubjectId having count(*)>1) (answer)
b. select AuthorName from Authors where BookId in (select BookId from Books group by BookId having count(*)>1)
c. select AuthorName from Authors where Authorid in (select Authorid from Books group by SubjectId,Authorid having count(*)>1)
d. select AuthorName from Authors where Authorid in (select Authorid from Books group by Authorid having count(*)>1)
e. None of the above

Question: 12
The Flush statement cannot be used for:
a.   Closing any open tables in the table cache
b.   Closing open connections
c.   Flushing the log file
d.   Flushing the host cache (answer)

Question: 13
Which of the following statements are true?
a.   Names of databases, tables and columns can be up to 64 characters in length (answer)
b.   Alias names can be up to 255 characters in length (answer)
c.   Names of databases, tables and columns can be up to 256 characters in length
d.   Alias names can be up to 64 characters in length

Question: 14
Is it possible to insert several rows into a table with a single INSERT statement?
a.   No
b.   Yes (answer)

Question: 15
What is wrong with the following statement?
create table foo (id int auto_increment, name int);
a.   Nothing
b.   The id column cannot be auto incremented because it has not been defined as a primary key (answer)
c.   It is not spelled correctly. It should be: CREATE TABLE foo (id int AUTO_INCREMENT, name int);

Question: 16
Which of the following statements grants permission to Peter with password Software?
a.   GRANT ALL ON testdb.* TO peter PASSWORD ‘Software’
b.   GRANT ALL ON testdb.* TO peter IDENTIFIED by ‘Software’ (answer)
c.   GRANT ALL OF testdb.* TO peter PASSWORD ‘Software’
d.   GRANT ALL OF testdb.* TO peter IDENTIFIED by ‘Software’

Question: 17
Which one of the following correctly selects rows from the table myTable that have NULL in column column1?
a.   SELECT * FROM myTable WHERE column1 IS NULL (answer)
b.   SELECT * FROM myTable WHERE column1 = NULL
c.   SELECT * FROM myTable WHERE column1 EQUALS NULL
d.   SELECT * FROM myTable WHERE column1 NOT NULL
e.   SELECT * FROM myTable WHERE column1 CONTAINS NULL

Question: 18
Examine the data in the employees table given below:
last_name    department_id     salary
ALLEN              10              3000
MILLER            20              1500
King                  20              2200
Davis                 30             5000
Which of the following Subqueries will execute well?
a.   SELECT * FROM employees where salary > (SELECT MIN(salary) FROM employees GROUP BY department_id);
b.   SELECT * FROM employees WHERE salary = (SELECT AVG(salary) FROM employees GROUP BY department_id);
c.   SELECT distinct department_id FROM employees Where salary > ANY (SELECT AVG(salary) FROM employees GROUP BY department_id); (answer)
d.   SELECT department_id FROM employees WHERE SALARY > ALL (SELECT AVG(salary) FROM employees GROUP BY department_id); (answer)
e.   SELECT department_id FROM employees WHERE salary > ALL (SELECT AVG(salary) FROM employees GROUP BY AVG(SALARY));

Question: 19
Consider the following tables:
books
——
bookid
bookname
authorid
subjectid
popularityrating (the popularity of the book on a scale of 1 to 10)
language (such as French, English, German etc)
Subjects
———
subjectid
subject (such as History, Geography, Mathematics etc)
authors
——–
authorid
authorname
country
Which is the query to determine the Authors who have written at least 1 book with a popularity rating of less than 5?
a.   select authorname from authors where authorid in (select authorid from books where popularityrating<5) (answer)
b.   select authorname from authors where authorid in (select authorid from books where popularityrating<=5)
c.   select authorname from authors where authorid in (select bookid from books where popularityrating<5)
d.   select authorname from authors where authorid in (select authorid from books where popularityrating in (0,5))

Question: 20
Consider the following select statement and its output:
SELECT * FROM table1 ORDER BY column1;
Column1
——–
1
2
2
2
2
2
3
Given the above output, which one of the following commands deletes 3 of the 5 rows where column1 equals 2?
a. DELETE FIRST 4 FROM table1 WHERE column1=2
b. DELETE 4 FROM table1 WHERE column1=2
c. DELETE WHERE column1=2 LIMIT 4
d. DELETE FROM table1 WHERE column1=2 LIMIT 3 (answer)
e. DELETE FROM table1 WHERE column1=2 LEAVING 1

Question: 21
Which of the following statements relating to Alias names is true?
a.   Alias names are case sensitive
b.   Alias names are case in-sensitive
c.   Alias names are case sensitive on UNIX and not on Windows (answer)
d.   Alias names are case sensitive on Windows and not on UNIX<
e.   Alias names case sensitivity depends on lower_case_table_names system setting

Question: 22
The STUDENT_GRADES table has these columns:
STUDENT_ID INT
SEMESTER_END DATE
GPA FLOAT
Which of the following statements finds the highest Grade Point Average (GPA) per semester?
a.   SELECT MAX(GPA) FROM STUDENT_GRADES WHERE GPA IS NOT NULL
b.   SELECT GPA FROM STUDENT_GRADES GROUP BY SEMESTER_END
c.   SELECT MAX(GPA) FROM STUDENT_GRADES GROUP BY SEMESTER_END
d.   SELECT TOP 1 GPA FROM STUDENT_GRADES GROUP BY SEMESTER_END
e.   None of the above

Question: 23
What is true about the ENUM data type?
a.   An enum value may be a user variable
b.   An enum may contain number enclosed in quotes
c.   An enum cannot contain an empty string
d.   An enum value may be NULL
e.   None of the above is true

Question: 24
Which of the following is not a valid Arithmetic operator?
a.   +
b.   -
c.   *
d.   \
e.   %
f.   All are valid

Question: 25
Which of the following is not a valid Logical operator?
a.   &
b.   &&
c.   AND
d.   !
e.   NOT

Question: 26
Which of the following queries is valid?
a.   Select * from students where marks > avg(marks);
b.   Select * from students order by marks where subject = ‘SQL’;
c.   Select * from students having subject =’SQL’;
d.   Select name from students group by subject, name;
e.   Select group(*) from students;
f.   Select name,avg(marks) from students;
g.   None of the above

Question: 27
Which of the following statements are true?
a.   BLOB and TEXT columns cannot have DEFAULT values
b.   BLOB columns are treated as binary strings (byte strings)
c.   BLOB columns have a charset
d.   TEXT columns cannot be indexed
e.   None of the above is true

Question: 28
Examine the code given below:
SELECT employee_id FROM employees WHERE commission_pct=.5 OR salary > 23000
Which of the following statements is correct with regard to this code?
a.   It returns employees whose salary is 50% more than $23,000
b.   It returns employees who have 50% commission rate or salary greater than $23,000
c.   It returns employees whose salary is 50% less than $23,000
d.   None of the above

Question: 29
What kind of joins does MySQL support?
a.   dual join
b.   right join
c.   natural join
d.   middle join
e.   STRAIGHT_JOIN

Question: 30
What is the correct SQL syntax for selecting all the columns from the table Persons where the LastName is alphabetically between (and including) “Hansen” and “Pettersen”?
a.   SELECT * FROM Persons WHERE LastName > ‘Hansen’, LastName < ‘Pettersen’
b.   SELECT LastName > ‘Hansen’ AND LastName < ‘Pettersen’ FROM Persons
c.   SELECT * FROM persons WHERE LastName > ‘Hansen’ AND LastName > ‘Pettersen’
d.   SELECT * FROM Persons WHERE LastName BETWEEN ‘Hansen’ AND ‘Pettersen’

Question: 31
Which query will display data from the Pers table relating to Analysts, Clerks and Salesmen who joined between 1/1/2005 and 1/2/2005 ?
a.   select * from Pers where joining_date from #1/1/2005# to #1/2/2005#, job=Analyst or clerk or salesman
b.   select * from Pers where joining_date between #1/1/2005# to #1/2/2005#, job=Analyst or job=clerk or job=salesman
c.   select * from Pers where joining_date between #1/1/2005# and #1/2/2005# and (job=Analyst or clerk or salesman)
d.   None of the above

Question: 32
Which of the following operators has the highest precedence?
a.   BINARY
b.   NOT
c.   <<
d.   %

Question: 33
Which of the following results in 0 (false)?
a.   “EXPERTRATING” LIKE “EXP%”
b.   “EXPERTRATING” LIKE “Exp%”
c.   BINARY “EXPERTRATING” LIKE “EXP%”
d.   BINARY “EXPERTRATING” LIKE “Exp%”
e.   All will result in 1 (true)

Question: 34
What is true regarding the SET data type?
a.   A SET can have zero or more values
b.   A SET value may contain a comma
c.   A SET can have a maximum of 64 different members
d.   MySQL stores SET values as strings
e.   None of the above is true

Question: 35
If you try to perform an arithmetic operation on a column containing NULL values, the output will be:
a.   0
b.   NULL
c.   An error will be generated
d.   Cannot be determined

Question: 36
Which of the following is not a MySQL statement?
a.   ENUMERATE
b.   EXPLAIN
c.   KILL
d.   LOAD DATA
e.   SET

Question: 37
To quote a string within a string, which of the following can you use?
a.   “This is the “quoted” message”
b.   “This is the “”quoted”” message”
c.   ‘This is the “quoted” message’
d.   “This is the \”quoted\” message”

Question: 38
State whether true or false:
Transactions and commit/rollback are supported by MySQL using the MyISAM engine
a.   True
b.   False

Question: 39
What will happen if some of the columns in a table are of char datatype and others are of varchar datatype?
a.   Nothing will happen
b.   MySQL will generate an error
c.   MySQL will convert all varchar datatypes into char
d.   MySQL will convert all char datatypes into varchar

Question: 40
Examine the query:- select (2/2/4) from tab1; where tab1 is a table with one row. This would give a result of:
a.   4
b.   2
c.   1
d.   .5
e.  .25
f.    0
g.    8
h.   24

Question: 41
Examine the two SQL statements given below:
SELECT last_name, salary, hire_date FROM EMPLOYEES ORDER BY salary DESC
SELECT last_name, salary, hire_date FROM EMPLOYEES ORDER BY 2 DESC
What is true about them?
a.   The two statements produce identical results
b.   The second statement returns an error
c.   There is no need to specify DESC because the results are sorted in descending order by default
d.   None of the above statments is correct

Question: 42
MySQL supports 5 different int types. Which one takes 3 bytes?
a.   TINYINT
b.   MEDIUMINT
c.   SMALLINT
d.   INT
e.   BIGINT

Question: 43
What does SQL stand for?
c)   Structured Query Language (answer)

Question: 44
Which SQL statement is used to extract data from a database?
d)   SELECT (answer)

Question: 45
Which SQL statement is used to update data in a database?
a)  UPDATE (answer)

Question: 46
Which SQL statement is used to delete data from a database?
b) DELETE (answer)

Question: 47
Which SQL statement is used to insert new data in a database?
c)  INSERT (answer)

Question: 48
With SQL, how do you select a column named "FirstName" from a table named "Persons"?
b)  SELECT FirstName FROM Persons (answer)

Question: 49
With SQL, how do you select all the columns from a table named "Persons"?
d)  SELECT * FROM Persons (answer)

Question: 50
With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" is "Peter"?
eter'
d)SELECT * FROM Persons WHERE FirstName='Peter' (answer)

Question: 51
With SQL, how do you select all the records from a table named "Persons" where the value of the column "FirstName" starts with an "a"?
d) SELECT * FROM Persons WHERE FirstName LIKE 'a%' (answer)

Question: 52
The OR operator displays a record if ANY conditions listed are true. The AND operator displays a record if ALL of the conditions listed are true
a) True (answer)

Question: 53
With SQL, how do you select all the records from a table named "Persons" where the "FirstName" is "Peter" and the "LastName" is "Jackson"?
b)   SELECT * FROM Persons WHERE FirstName='Peter' AND LastName='Jackson' (answer)

Question: 54
With SQL, how do you select all the records from a table named "Persons" where the "LastName" is alphabetically between (and including) "Hansen" and "Pettersen"?
b) SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen' (answer)

Question: 55
Which SQL statement is used to return only different values?
d)  SELECT DISTINCT (answer)

Question: 56
Which SQL keyword is used to sort the result-set?
c)  ORDER BY (answer)

Question: 57
With SQL, how can you return all the records from a table named "Persons" sorted descending by "FirstName"?
b) SELECT * FROM Persons ORDER BY FirstName DESC (answer)

Question: 58
With SQL, how can you insert a new record into the "Persons" table?
a)  INSERT INTO Persons VALUES ('Jimmy', 'Jackson') (answer)

Question: 59
With SQL, how can you insert "Olsen" as the "LastName" in the "Persons" table?
a)  INSERT INTO Persons (LastName) VALUES ('Olsen') (answer)

Question: 60
How can you change "Hansen" into "Nilsen" in the "LastName" column in the Persons table?
b) UPDATE Persons SET LastName='Nilsen' WHERE LastName='Hansen' (answer)

Question: 61
With SQL, how can you delete the records where the "FirstName" is "Peter" in the Persons Table?
a)  DELETE FROM Persons WHERE FirstName = 'Peter' (answer)

Question: 62
With SQL, how can you return the number of records in the "Persons" table?
b) SELECT COUNT(*) FROM Persons (answer)

Question: 63
Given an employees table as follows: empid name managerid a1 bob NULL b1 jim a1 B2 tom a1 What value will select count(*) from employees return?
c) 3 (answer)

Question: 64
The result of a SELECT statement can contain duplicate rows.
a)  True (answer)

Question: 65
Sometimes the expression "select count(*)" will return fewer rows than the expression "select count(value)".
b) False (answer)

Question: 66
What type of lock will deny users any access to a table?
c) EXCLUSIVE (answer)

Question: 67
Which of the following is the correct SQL statement to use to remove rows from a table?
c) DELETE (answer)

Question: 68
The only way to join two tables is by using standard, ANSI syntax.
b) False (answer)

Question: 69
A NULL value is treated as a blank or 0.
b) False (answer)

Question: 70
The left outer join is one type of outer join. Another one is the.
e)all of the above (answer)

Question: 71
Which of the following is not a numeric group function?
 Highest (answer)

Question: 72
Which of the following statements are true?
With DDL you can create and remove tables, schemas, domains, indexes and views (answer)

Question: 73
Which of the following clauses are not allowed in a single row sub-query?
Order by (answer)

Question: 74
What is the collection of information stored in a database at a particular moment called?
 Instance (answer)

Question: 75
The overall logical structure of a database can be expressed graphically by:
 Entity-Relationship Diagram (answer)

Question: 76
Consider the following tables:
Books
------
BookId
BookName
AuthorId
SubjectId
PopularityRating       (the popularity of the book ON a scale of 1 TO 10)
Languag?               (such AS French, English, German etc)
Subjects
---------
SubjectId
Subject    (such AS History, Geography, Mathematics etc)
Authors
--------
AuthorId
AuthorName
Country
What is the query to determine which German books(if any) are more popular than all the French?
 select bookname from books where language='German' and popularityrating> (select max(popularityrating) from books where language='French') (answer)

Question: 77
Which statements are true for views?
 The definition of a view is stored in data dictionary
 Views provide a more secure way of retrieving data (answer)

Question: 78
Consider the following tables:
Books
------
BookId
BookName
AuthorId
SubjectId
PopularityRating (the popularity of the book ON a scale of 1 TO 10)
Languag? (such AS French, English, German etc)
Subjects
---------
SubjectId
Subject (such AS History, Geography, Mathematics etc
Authors
--------
AuthorId
AuthorName
Country
What is the query to determine which Authors have written books on two or more subjects? 
 select AuthorName from Authors where Authorid in (select Authorid from Books group by SubjectId having count(*)>1) (answer)

Question: 79
What does the term DDL stand for?
 Data Definition Language (answer)

Question: 80
The concept of data independence is similar to the concept of ________
 Abstract data type (answer)

Question: 81
What are the programs that execute automatically whenever DML operations are performed on tablds called?
 Triggers (answer)

Question: 82
What clause should be used to display the rows of a table in ascending order of a particular column?
 Order By (answer)

Question: 83
What is the error in the following query if the Students table contains several records?
SELECT name FROM students WHERE name =
(SELECT name FROM students ORDER BY name);
 = should be replace by in operator
 An order by clause is not allowed in a subquery

Question: 84
How can data be accessed by users who do not have direct access to the tables?
 By creating views (answer)

Question: 85
There is a column c1 in the table t to which a primary key pk is to be added. What will be the correct syntax?
 Alter table t add primary key(c1); (answer)

Question: 86
The primary key index does not allow ________ data in a field.
 Null (answer)

 Duplicate (answer)

No comments: