Most Asked SQL Interview Questions and Answers
Which command executes the contents of a specified file?
START or @.
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.
Which command displays the SQL command in the SQL buffer, and then executes it?
What command is used to get back the privileges offered by the GRANT command?
Which date function is used to find the difference between two dates?
What operator performs pattern matching?
What is the use of the DROP option in the ALTER TABLE command?
It is used to drop constraints specified on the table.
What operator tests column for the absence of data?
IS NULL operator.
What are the privileges that can be granted on a table by a user to others?
Insert, update, delete, select, references, index, execute, alter, all.
Which function is used to find the largest integer less than or equal to a specific value?
FLOOR function is used.
Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?
Data Definition Language (DDL).
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.
The query SELECT * FROM EMP ORDER BY ENAME DESC will display the output sorted on ENAME
in descending order.
What command is used to create a table by copying the structure of another table?
CREATE TABLE .. AS SELECT command
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.
What is the output of the following query SELECT TRUNC(1234.5678,-2) FROM DUAL;?
What are the wildcards used for pattern matching.?
_ for single character substitution and % for multi-character substitution.
What is the parameter substitution symbol used with INSERT INTO command?
& is the parameter substitution symbol used with INSERT INTO command.
What’s an SQL injection?
SQL Injection is when form data contains an SQL escape sequence and injects a new SQL query to be run.
What is difference between TRUNCATE & DELETE
TRUNCATE commits after deleting entire table i.e., cannot be rolled back. Database triggers do not fire on TRUNCATE
DELETE allows the filtered deletion. Deleted records can be rolled back or committed. Database triggers fire on DELETE.
What is a join? Explain the different types of joins?
Join is a query, which retrieves related columns or rows from multiple tables.
– Joining the table with itself. Equi Join
– Joining two tables by equating two common columns. Non-Equi Join
– Joining two tables by equating two common columns. Outer Join
– Joining two tables in such a way that query can also retrieve rows that do not have corresponding join value in the other table.
What is the sub-query?
Sub-query is a query whose return values are used in filtering conditions of the main query.
What is correlated sub-query?
Correlated sub-query is a sub-query, which has reference to the main query.
Explain CONNECT BY PRIOR?
Retrieves rows in hierarchical order eg.
select empno, ename from emp where.
Difference between SUBSTR and INSTR?
INSTR (String1, String2 (n, (m)),
INSTR returns the position of the m-th occurrence of the string 2 in string1. The search begins from nth position of string1.
SUBSTR (String1 n, m)
SUBSTR returns a character string of size m in string1, starting from n-th position of string1.
Explain UNION, MINUS, UNION ALL and INTERSECT?
– returns all distinct rows selected by both queries.
– returns all distinct rows selected by the first query but not by the second.
– returns all distinct rows selected by either query
– returns all rows selected by either query, including all duplicates.
What is ROWID?
ROWID is a pseudo column attached to each row of a table. It is 18 characters long, blockno, rownumber are the components of ROWID.
What is the fastest way of accessing a row in a table?