Saturday, March 29, 2008

FAQ - Database Testing ( 11 to 20 )

11. Which system table contains information on privileges granted and privileges
obtained?

USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD

12. Which system table contains information on constraints on all the tables created?

USER_CONSTRAINTS

13. What is the output of the following query SELECT TRUNC(1234.5678, -2) FROM DUAL;

1200

14. What is the use of DESC in SQL?

DESC has two purposes. It is used to describe a schema as well as to retrieve rows from table in descending order.
Explanation:
The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output
sorted on ENAME in descending order.

15. State True or False: EXISTS, SOME, ANY are operators in SQL?

True

16. There are two tables, Employee and Department. There are few records in employee table, for which, the department is not assigned. The output of the query should contain all the employees’ names and their corresponding departments, if the department is assigned otherwise employee names and null value in the place department name. What is the query?

What you want to use here is called a left outer join with Employee table on the left side. A left outer join as the name says picks up all the records from the left table and based on the joint column picks the matching records from the right table and in case there are no matching records in the right table, it shows null for the selected columns of the right table. eg in this query which uses the key-word LEFT OUTER JOIN. Syntax though varies across databases. In DB2/UDB it uses the key word LEFT OUTER JOIN, in case of Oracle the connector is Employee_table.Dept_id *= Dept_table.Dept_idSQL Server/Sybase : Employee_table.Dept_id(+) = Dept_table.Dept_id

17. What command is used to create a table by copying the structure of another table?

CREATE TABLE.. AS SELECT command
Explanation:

To copy only the structure, the WHERE clause of the SELECT command should contain a false statement as in the following.
CREATE TABLE NEWTABLE AS SELECT * FROM EXISTINGTABLE WHERE 1=2;
If the WHERE condition is true, then all the rows or rows satisfying the condition will be copied to the new table.

18. State True or False: !=, <>, ^= all denotes the same operation?

True

19. Which function is used to find the largest integer less than or equal to a specific value?

FLOOR

20. What does the following query do?
SELECT SAL + NVL (COMM, 0) FROM EMP;
This displays the total salary of all employees. The null values in the commission column will be replaced by 0 and added to salary.

1 comment:

Anonymous said...

What a great web log. I spend hours on the net reading blogs, about tons of various subjects. I have to first of all give praise to whoever created your theme and second of all to you for writing what i can only describe as an fabulous article. I honestly believe there is a skill to writing articles that only very few posses and honestly you got it. The combining of demonstrative and upper-class content is by all odds super rare with the astronomic amount of blogs on the cyberspace.