SQL Interview Questions1
1.TRUNCATE TABLE EMP;
DELETE FROM EMP;
Will the outputs of the above two commands differ?
Both will result in deleting all the rows in the table EMP.
2. What is the difference between TRUNCATE and DELETE commands?
TRUNCATE is a DDL command whereas DELETE is a DML command. Hence DELETE operation can be rolled back, but TRUNCATE operation cannot be rolled back. WHERE clause can be used with DELETE and not with TRUNCATE.
3. 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.
4. What will be the output of the following query?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM(’!! ATHEN !!’,’!’), ‘!’), ‘AN’, ‘**’),’*’,’TROUBLE’) FROM DUAL;
TROUBLETHETROUBLE
5.What will be the output of the following query?
SELECT DECODE(TRANSLATE(’A’,’1234567890?,’1111111111?), ‘1?,’YES’, ‘NO’ );
NO
Explanation :
The query checks whether a given string is a numerical digit.
6. 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.
7. Which date function is used to find the difference between two dates?
MONTHS_BETWEEN
8. Why does the following command give a compilation error?
DROP TABLE &TABLE_NAME;
Variable names should start with an alphabet. Here the table name starts with an ‘&’ symbol.
9. What is the advantage of specifying WITH GRANT OPTION in the GRANT command?
The privilege receiver can further grant the privileges he/she has obtained from the owner to any other user.
10. What is the use of the DROP option in the ALTER TABLE command?
It is used to drop constraints specified on the table.
11. What is the value of ‘comm’ and ‘sal’ after executing the following query if the initial value of ‘sal’ is 10000? UPDATE EMP SET SAL = SAL + 1000, COMM = SAL*0.1;
sal = 11000, comm = 1000
12. 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.
13. What is the use of CASCADE CONSTRAINTS?
When this clause is used with the DROP command, a parent table can be dropped even when a child table exists.
14.Which function is used to find the largest integer less than or equal to a specific value?
FLOOR
15. What is the output of the following query? SELECT TRUNC(1234.5678,-2) FROM DUAL;
1200
Last 5 posts in SQL Interview Questions1
Related Posts
You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.












Leave a Reply