Sql Aptitude Very neat collection

Q. What command is used to create a table by copying the structure of
another table?
Answer :
  
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.
 
Q. What will be the output of the
following query?
SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN
!!','!'), '!'),
'AN', '**'),'*','TROUBLE') FROM DUAL;
  
TROUBLETHETROUBLE
 
Q. What will be the output of the following
query?
SELECT  DECODE(TRANSLATE('A','1234567890','1111111111'),
'1','YES', 'NO' );
Answer :    NO.
Explanation : 
The query checks whether a
given string is a numerical digit.

Q. 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 & added to salary.

Q. What is the difference between TRUNCATE
& 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 & not with TRUNCATE.

No comments:

Post a Comment