Database MCQ Set 1
1. The general statement-issuing routine is ___
a) mysql_real_query()
b) mysql_query_real()
c) mysql_image_query()
d) mysql_query_image()
Answer
Answer: a [Reason:] The general statement-issuing routine is mysql_real_query(). The statement is provided as a counted string (a string plus a length). The length of the statement string must be kept track of.
2. Which of these is more restrictive?
mysql_query(), mysql_real_query()
a) mysql_query()
b) mysql_real_query()
c) same
d) machine dependent
Answer
Answer: a [Reason:] The statement-issuing function other than ‘mysql_real_query()’ is ‘mysql_query()’. It is more restrictive in what it allows in the statement string although it is often easier to use.
3. For failure, mysql_query() returns ___
a) 0
b) 1
c) -1
d) a non-zero
Answer
Answer: d [Reason:] Both of the functions named ‘mysql_query()’ and ‘mysql_real_query()’ return zero for statements that succeed. They return non zero for failure. A statement is successfully executed if the server accepts it.
4. How many of the following return rows?
SELECT, SHOW, DESCRIBE
a) 0
b) 1
c) 2
d) 3
Answer
Answer: d [Reason:] In MySQL, it is important to note that ‘SELECT’ is not the only statement that returns some rows. Statements like ‘SHOW’, ‘DESCRIBE’, ‘EXPLAIN’ and ‘CHECK TABLE’ do so as well.
5. mysql_fetch_row() returns ___
a) integer
b) float
c) structure
d) pointer
Answer
Answer: d [Reason:] ‘mysql_fetch_row()’ returns a MYSQL_ROW value, a pointer to an array of values. If the return value is assigned to a variable named row each value within the row is accessed as row[i].
6. The columns containing binary value that include null bytes will not print properly using the %s printf() format specifier.
a) True
b) False
Answer
Answer: a [Reason:] The columns containing binary value including null bytes do not print properly using the %s printf() format specifier. printf() expects a null terminated string. It prints the column value only up to the first null byte.
7. mysql_store_result() does not return a result set.
a) True
b) False
Answer
Answer: b [Reason:] The functions ‘mysql_store_result()’ and ‘mysql_use_result()’ are similar because both of them take a connection handler argument and then return a result set after carrying out processes.
8. How many of the following take a connection handler as argument?
mysql_store_result(), mysql_use_result()
a) 0
b) 1
c) 2
d) 3
Answer
Answer: c [Reason:] The functions ‘mysql_store_result()’ and ‘mysql_use_result()’ are similar because both of them take a connection handler argument and then return a result set after carrying out the processes.
9. Which of these has lower memory requirement?
mysql_use_result(), mysql_store_result()
a) mysql_use_result()
b) mysql_store_result()
c) same
d) machine dependent
Answer
Answer: a [Reason:] The function ‘mysql_use_result()’ has lower memory requirements than ‘mysql_store_result()’ because only enough space to handle a single row at a time needs to be allocated. This can be faster.
10. How many of the following is considered as a special character by ‘mysql_real_escape_string()’?
null byte, single quote, backslash
a) 0
b) 1
c) 2
d) 3
Answer
Answer: d [Reason:] The characters that ‘mysql_real_escape_string()’ considers special are the null byte, single quote, double quote, ‘backslash’, ‘newline’, ‘carriage return’ and the ‘Control-Z’.
Database MCQ Set 2
1. RTF refers to ________
a) Rich Text Format
b) Right Text Format
c) Rich Text Function
d) Right Text Function
Answer
Answer: a [Reason:] RTF (Rich Text Format) is a format developed by Microsoft that is understood by many word processors. MS-Word is one such program. Many others such as ‘OpenOffice’ understand it too.
2. The function returning an array of row values is ________
a) fetchrow_array()
b) fetchrow_arrayref()
c) fetch()
d) fetchrow_hashref()
Answer
Answer: a [Reason:] The function ‘fetchrow_array()’ returns an array of row values. ‘fetchrow_arrayref()’ returns a reference to an array of row values. ‘fetch()’ is the same as fetchrow_arrayref().
3. The function returning reference to hash of row values is ________
a) fetchrow_array()
b) fetchrow_arrayref()
c) fetch()
d) fetchrow_hashref()
Answer
Answer: d [Reason:] The function ‘fetchrow_hashref()’ returns reference to hash of row values. ‘fetchrow_arrayref()’ returns a reference to an array of row values. ‘fetch()’ is the same as fetchrow_arrayref().
4. fetchrow_hashref() returns reference to hash of row values keyed by ________
a) row name
b) column name
c) table name
d) database name
Answer
Answer: b [Reason:] The function ‘fetchrow_hashref()’ returns reference to hash of row values, keyed by the column name. The function ‘fetchrow_arrayref()’ returns a reference to an array of row values.
5. The function returning reference to array of row values is ________
a) fetchrow_array()
b) fetchrow_arrayref()
c) fetch()
d) fetchrow_hashref()
Answer
Answer: b [Reason:] ‘fetchrow_arrayref()’ returns a reference to an array of row values. The function ‘fetchrow_hashref()’ returns reference to hash of row values. ‘fetch()’ is the same as fetchrow_arrayref().
6. What is the maximum non zero value for FLOAT?
a) 3.402823466E+38
b) 3.402823466E+37
c) 3.402823466E+39
d) 3.402823466E+35
Answer
Answer: a [Reason:] In MySQL, each datatype has its own range. Data types give an idea of the kind of values and the ranges that a variable is allowed to store. The maximum non zero value for FLOAT is 3.402823466E+38.
7. What is the maximum non zero values for DOUBLE?
a) ±1.7976931348623157E+307
b) ±1.7976931348623157E+308
c) ±1.7976931348623157E+306
d) ±1.7976931348623157E+305
Answer
Answer: b [Reason:] In MySQL, all the datatypes have their own ranges. Data types give an idea of the kind of values and the ranges that a variable is allowed to store. The maximum non zero value for DOUBLE is ±1.7976931348623157E+308.
8. By default, MySQL does not clip out of range numeric values to the nearest fit value.
a) True
b) False
Answer
Answer: b [Reason:] For the numeric or TIME columns, the values that are outside the legal range are clipped to the nearest endpoint of the range. The resulting value is stored. This is the method to handle defaults for numerics.
9. Illegal values converted to the appropriate ‘zero’ value for ________
a) Numeric
b) String
c) ENUM
d) TIME
Answer
Answer: d [Reason:] In MySQL, there are different ways to handle the illegal values for different datatypes for default. For date or time columns, illegal values are converted to the appropriate “zero” value for the type.
10. The column attribute provides unique numbers for identification is ________
a) AUTO_INCREMENT
b) UNSIGNED
c) IDENTIFY
d) DESCRIBE
Answer
Answer: a [Reason:] In MySQL, the mechanism for providing unique numbers is through the AUTO_INCREMENT column attribute. It enables the generation of sequential numbers automatically. This facilitates identification.
Database MCQ Set 3
1. In PHP, if $a represents an array with numeric indices, how is the first element accessed?
a) $a[1].
b) $a[0].
c) $a.1
d) $a.0
Answer
Answer: b [Reason:] If $a represents an array with numeric indices, its elements are accessed as $x[0], $x[1], and so on. In general terms, each element at the position i is accessed and used as $a[i – 1].
2. Arrays cannot have associative indices in PHP.
a) True
b) False
Answer
Answer: b [Reason:] The PHP arrays can even have both numeric and associative elements. For example, $x[1] and $x[“large”] can both be the elements of the same array. $x can be an object, whose elements are accessed by the arrow ‘->’ operated.
3. In PHP, which operator is used to access property of an object?
a) .
b) *
c) ->
d) @
Answer
Answer: c [Reason:] If $a represents an object, the properties it has can be accessed as $a->property-name. For instance, $a->white, $a->black, $a->blue, $a->red can be the properties of $a and accessed in this way.
4. PHP scripts are located in the web server document tree.
a) True
b) False
Answer
Answer: a [Reason:] The PHP scripts are different from DBI scripts since PHP scripts are located within the web server document tree while DBI scripts are located in a cgi-bin directory located outside of document tree.
5. DBI scripts are located in the directory ________
a) cgi-inc
b) cgi-bin
c) cgi-usr
d) cgi-perl
Answer
Answer: b [Reason:] DBI scripts are located in a cgi-bin directory located outside of document tree. The PHP scripts are different from DBI scripts since PHP scripts are located within the web server document tree.
6. A stored program associated with a schedule is ________
a) Trigger
b) Event
c) Stored function
d) Stored procedure
Answer
Answer: b [Reason:] The MySQL version 5.1.6 and above has an event scheduler. It enables to perform time activated database operations. An event is a stored program that is associated with a schedule.
7. The line used to turn on the event scheduler is ________
a) event_scheduler = ON
b) eventscheduler = ON
c) event_scheduler_ON
d) events_scheduler_ON
Answer
Answer: a [Reason:] The line ‘event_scheduler = ON’ is put in the option file that the server reads. The event scheduler does not run by default. It must be turned on if events are to used in the database.
8. What is the creation of a stored program similar to?
a) Trigger
b) Event
c) View
d) Table
Answer
Answer: c [Reason:] When a stored program is created, an object is created that is to be executed later. This also the case when a view is defined: It sets up a SELECT statement intended for later invocation.
9. When the security context enables carefully written stored programs to be set up that provide controlled access to tables for users, it is called ____
a) bad
b) good
c) illegal
d) fare
Answer
Answer: b [Reason:] The security context is good if it enables carefully written stored programs to be set up that provide controlled access to tables for users who are not able to access them directly.
10. What is the maximum number of indexes on MyISAM table?
a) 0
b) 1
c) 2
d) more than 1
Answer
Answer: d [Reason:] In MySQL, for a MyISAM table, there can be more than one indexes. The data rows of the MyISAM table are stored in a data file and the index values are stored in a separate index file.
Database MCQ Set 4
1. Which of these has higher priority?
writes, reads
a) writes
b) reads
c) same priority
d) machine dependent
Answer
Answer: a [Reason:] A client performing an operation that modifies a table is a writer and the client that performs a retrieval from the table is a reader. The writes have higher priority than reads.
2. How many of the following implement the default scheduling property of MySQL?
MyISAM, MERGE, MEMORY
a) 0
b) 1
c) 2
d) 3
Answer
Answer: d [Reason:] The MyISAM, MERGE and the MEMORY storage engines implement the default scheduling policy of MySQL with the help of the table locks. Whenever a client accesses a table a lock for it must be acquired first.
3. Which statement issues a lock on tables?
a) ISSUE LOCK
b) LOCK ISSUE
c) LOCK TABLES
d) ISSUE LOCKS
Answer
Answer: c [Reason:] Locks can be acquired and released explicitly by issuing LOCK TABLES and UNLOCK TABLES statements. Normally the server’s lock manager automatically acquires locks as necessary and releases them when they no longer are needed.
4. Reading from a table does not change it.
a) True
b) False
Answer
Answer: a [Reason:] Reading does not change the table. There is no reason one reader should prevent another from accessing the table. So a read lock enables other clients to read the table at the same time.
5. To how many of these does the LOW_PRIORITY modifier apply to?
DELETE, INSERT, LOAD DATA, REPLACE
a) 1
b) 2
c) 3
d) 4
Answer
Answer: d [Reason:] The LOW_PRIORITY statement modifier influences the default scheduling policy of MySQL. This keyword applies to all the four: DELETE, INSERT, LOAD DATA, REPLACE. It also applies to UPDATE.
6. The number of tables among the following for which HIGH_PRIORITY have an effect are _____
MyISAM, MEMORY, MERGE
a) 0
b) 1
c) 2
d) 3
Answer
Answer: d [Reason:] In MySQL, the LOW_PRIORITY and HIGH_PRIORITY modifiers have an effect only for those storage engines that use table locks. The storage engines MyISAM, MERGE and MEMORY use table locks.
7. The number of tables for which DELAYED works is _____
MyISAM, MEMORY, ARCHIVE, BLACKHOLE
a) 1
b) 2
c) 3
d) 4
Answer
Answer: d [Reason:] The ‘DELAYED’ statement modifier that influences the default scheduling policies of MySQL works for the following tables: MyISAM, MEMORY, ARCHIVE and as of MySQL 5.1.19, also for BLACKHOLE tables.
8. Find the odd one out in terms of scheduling policies.
a) MyISAM
b) InnoDB
c) MEMORY
d) MERGE
Answer
Answer: b [Reason:] The InnoDB storage engine implements locking at a different level. It has differing performance characteristics in terms of contention management. It uses row-level locks.
9. The use of table level locks is always useful in MyISAM tables.
a) True
b) False
Answer
Answer: b [Reason:] MyISAM is extremely fast for retrievals but the use of table level locks can be a problem in environments with mixed retrievals and updates if the retrievals are long running.
10. Which table is preferred when there are many updates?
a) MyISAM
b) InnoDB
c) MEMORY
d) MERGE
Answer
Answer: b [Reason:] The InnoDB tables can provide better performance when there are many updates. Locking is done at the row level rather than at the table level. So the extent of the table that is locked is smaller.
Database MCQ Set 5
1. To produce a stored function, which statement is used?
a) PRODUCE FUNCTION
b) CREATE FUNCTION
c) PRODUCE PROCEDURE
d) CREATE PROCEDURE
Answer
Answer: b [Reason:] The ‘CREATE FUNCTION’ statement is used to create a stored function in MySQL. The ‘CREATE PROCEDURE’ statement is used to create a stored procedure instead, from which values are not returned.
2. How many values can be returned from a given stored function?
a) 0
b) 1
c) 2
d) 3
Answer
Answer: b [Reason:] In MySQL, the stored function cannot return multiple values. Instead, multiple stored functions can be written and invoked from within a single statement however. They are different from stored procedures.
3. How many values can be returned from a stored procedure?
a) 0
b) 1
c) 2
d) 3
Answer
Answer: a [Reason:] In MySQL, unlike the stored functions, the stored procedures cannot return values. They can be used to perform calculations or produce the result sets passed back to the clients.
4. Suppose a stored function named PI() is written in the database ‘sampdb’. How would it be called?
a) PI()
b) sampdb.PI()
c) MySQL.PI()
d) db.PI()
Answer
Answer: b [Reason:] When a stored function is defined with the same name as a built in function, the function name should be qualified with the database name when it is invoked. The function ‘PI()’ is built in.
5. Which privilege must be given to the database to create a stored function or procedure?
a) CREATE ROUTINE
b) CREATE METHOD
c) CREATE FUNCTION
d) CREATE PROCEDURE
Answer
Answer: a [Reason:] The ‘CREATE ROUTINE’ privilege must be given for the database in order to create a stored function or procedure. Stored functions and procedures always belong to a particular database.
6. Which variable is set to zero when automatic privilege granting is not needed?
a) automatic_sp_privileges
b) automatic_ps_privileges
c) automatic_pg_privileges
d) automatic_gp_privileges
Answer
Answer: a [Reason:] The automatic_sp_privileges system variable is set to zero when the automatic privilege granting is not needed and revocation should not be allowed to occur. It is a crucial system variable.
7. Which procedure parameter enables the caller to pass in a value and get back a value?
a) IN
b) OUT
c) INOUT
d) GETINOUT
Answer
Answer: c [Reason:] In an IN parameter, the caller passes a value into the procedure. An OUT parameter is exactly the opposite. The ‘INOUT’ parameter enables the caller to pass in a value and also to get back a value.
8. The IN, OUT and INOUT keywords do not apply to stored functions.
a) True
b) False
Answer
Answer: a [Reason:] The IN, OUT and INOUT keywords do not apply to stored functions, triggers and events. Triggers and events do not have parameters at all. For the stored functions, all parameters are like IN parameters.
9. For the same input parameters, if the stored function returns the same result, it is called _______
a) deterministic
b) non deterministic
c) regular
d) monotonous
Answer
Answer: a [Reason:] For the same input parameters, if the stored function returns the same result, it is called a deterministic function. Otherwise, the stored function is called not deterministic.
10. What is abc in the following statement?
DECLARE abc HANDLER FOR def ghi;
a) action
b) condition value
c) statement
d) null
Answer
Answer: a [Reason:] The ‘DECLARE HANDLER’ statement is used to declare a handler. When a condition whose value matches def, MySQL will execute ghi and either continue or exit the current code block.