Sunteți pe pagina 1din 4

SQL FAQS

Q1. What is the difference between Exist and in Operator?


EXIST OPERATOR IN OPERATOR
Exist operator is used in correlated subquery.It This operator is used to test a list of values in
returns a Boolean value. a specified list.

Q2.Difference between Delete and truncate and drop?


DELETE TRUNCATE DROP
Delete is a DML statement It is a DDL command It is a DDL command
Delete deletes record by Truncate removes bulk of
record records at a time.
Need to explicit commit It is an auto commit It is an auto commit
Here data remove but table Here data remove but table Both data and structure
structure remained structure remained removed
We can roll back. We cant rollback. We cant roll back.

Q3. Can we drop the table if table is having the data?


YES, we can drop the table which has data.
Q4. I have executed the Delete command after that I have created table
whether deletions will be commit or not? If table is successfully created?
Yes, it gets committed automatically whenever a DDL statement is performed.
Q5. I have executed the Delete command after I have created table
whether deletions will be commit or not? If table is not created?
No, it will not commit.
Q6. What is Row ID? When it will be created? What is the format? What is
the difference between Row Id and Row num?
Row id is an exact physical address of row. When a new record is inserted into a database
table a unique row id will automatically generate.
It will have 18 digit formats.
First 6 digit stores table name.
Second 3 digits stores file name.
Third 6 digits shows position of block.
Fourth 3 digits shows position of rows.
Difference between row id and Row num:
ROW ID ROW NUM
When a new record is inserted into a database table a When a new record is selected from
unique row id will automatically generate by system. database then Row num is generated.
Row id is static, we cant change. Row num is dynamic, it can automatically
change.
Q7. Can we use Row Id in the where clause? If yes can we use like follows?
Where rowid = 12?
Yes, we can use row id in where clause. Row num will work for =, <.
No, it wont accept row num=12;
Q8. What is Decode operator and what is the syntax when you have used
in Oracle Apps?
Decode is a function which is used for alternative value.
It is same as IF-THEN-CLAUSE.
Syntax: select Decode (value1, value2, exist, not exist) from Emp;
Q9. What is NVL operator and what is the syntax when u have used in
Oracle Apps?
It is used to handle null values; it converts null value to actual value. it is a built in function.
NVL (expr1, expr2);
Expr1; source value
Expr2: target value
Q10. What are Join and types of joins and what is Outer Join?
Join is a query that combines rows from multiple tables, views or materialized views.
Types of Join:
i. Equi Join: it is a join condition thats executed with an equality operator. it combines
rows that have equivalenta condition.
ii. Non equi join: it is used to join table if value of one column of a table falls the range
of two columns of other table. It is called as between join.
iii. Outer join: it is used to retrieve all rows from one table but matching rows from other table.
Q11. What is Set Operator and what are the types what is the difference
between Set Operators and Joins?
Set operators are used to combine information of similar data types from one or more
queries.
Types of set operators:
I. Union
ii. Union all
iii. Intersect
iv. Minus.
Difference between set operator and join:
SET OPERATOR JOIN OPERATOR
Set operators are used to combine information Join is a query that combines rows from
of similar data types from one or more queries multiple tables, views or materialized views.
Q12. What is view? What is the advantage? What are the types of views we
have?
View is a database object. It contains logical data but structure is physical.
Advantages of view:
View is used for hiding the data, particular columns can be grouped into a view. Thats why
it is used for security purpose.
Types of view:
1. Simple view: if DML operations are performed on a single table
2. Complex view: if DML operations are performed on more than one table by using instead
of triggers.
3. Materialized view: it is a database object; it is a static view which holds data in it. Here
DML operations not allowed.
4. Force view: view without base table.
5. Read only view: view created with only Read only options.
Q13. When we cannot update the view?
In read only view we cant update the view and in complex view.
Q14. What is Materialized view and what is Snap Shot?
It is a static view which holds data. No modification can reflect in the base table.
It will get updated only through REFRESH.
Syntax: Create or replace materialized view chita_mv
Enable query Rewrite
Refresh on commit
As select * from EMP;
Snapshot:
It is a static picture of data.DML operations is not possible and performance is fast.
Q15. What is the difference between Materialized view and Snap shot?
MATERIALIZED VIEW SNAPSHOT
It is a static view which holds data. It is a static picture of data
We can update data through refresh. But in snapshot we cant perform DML operations

Q16. What are the Inline views?


An inline view is a named sub query in the from clause of main query.
Q17. What is Synonym and what are the types and what is the advantage?
Synonym is a database object which is an alternative name for schema objects or views.
Types of synonym:
Public synonym: Created by database administrators. We should have create public synonym
privilege and be accessed by users.
Private synonym: Created by user, used by specific users which have permission not all.
Advantages of synonym: It will hide the object name.
Q18. What is index? Advantage of index? Types of indexes?
Index is a database object which acts as pointer locates the physical address of data
Advantage of index:
It is used by oracle server to speed up data retrieval.
Types of index:
i. Simple index: it is created with a single column.
ii. Bitmap index: row id associated with key value
iii. Composite index: if we define index on more than one column
iv. Partioned index: they contain partitions containing an entry for each value that appears in the
indexed column of a table.
V. function based index: when we create index on column with function.
Q19. What is the Bit mapped index advantage?
It contains row id with key value.
It improves the performance of SELECT statement.
Q20. What is sub-query and what is Co-Related Sub Query and difference
between those two?
Sub query:
Query within a query is called sub query.
Correlated sub query:
In the correlated sub query, a parent sub query will be executed first and based
on the output of the outer query the inner query will execute.

Difference between sub query and correlated sub query:


SUB QUERY CORELATED SUB QUERY
Sub query is query within a query. Here inner Parent sub query will be executed first and
will execute first based on outer query based on the output of the outer query the inner
query will execute.
Here the inner query will execute one time Here outer query will execute one time

Q21. What is the syntax for To Date function?


Syntax: To_date (char,fmt);
Q22. What is difference between Replace and Translate?
REPLACE() TRANSLATE()
It replaces word by word. It translates char by char.

Q23. What are the Pseudo columns we have?


Pseudo columns:
The column whichs not appear in table but physically present in table.
Types:
i. Currval
ii. Nextval
iii. Sysdate
iv. Level
v. Rownum
vi. Row id
Q24. How to execute DOS Commands form SQL Prompt?
Using host we can execute DOS commands from sql prompt.
Q25. How can we find out no of indexs we have created against a Table?
Select * from USER_IND_COLUMNS where table_name=table name;
Q26. How to get second max salary from the table?
SELECT MIN (SAL) FROM (SELECT SAL FROM EMP ORDER BY SAL DESC)
WHERE ROWNUM<3;
Q27. How to delete duplicate rows from the table?
DELETE FROM EMP B WHERE ROWID> (SELECT MIN(ROWID) FROM EMP A
WHERE
A.EMPNO=B.EMPNO AND
A.ENAME=B.ENAME AND
A.SAL=B.SAL AND
A.HIREDATE=B.HIREDATE);
Q28. What is Where Clause?
Where clause is used to filter the records based on a given condition.
Q29. What is having clause and what is the difference between these two
clauses?
Having clause:
Having clause is used to apply conditions on group by functions.
WHERE CLAUSE HAVING CLAUSE
Where clause is used to filter the records based Having clause is used to apply conditions on
on a given condition. group by functions.
It is applied for every record. It is applied for a group of records.
Q30. What are the constraints we have and how to declare?
i. Not null
ii. Check
iii. Unique
iv. Primary key
v. Foreign key
vi. Referential key
Q31. What are the constraints we have and how to declare?
Primary key is unique and not null constraints where as unique key accepts null value.
Q32.What is difference between primary key and Unique?
PRIMARY KEY UNIQUE KEY
Primary key is a combination of unique, not Unique key contains null value.
null and index
Q33. Can we compare two Null Values? Can we insert more than one null
value in the unique column?
Yes, we can compare two null values but result will be also null.
Q34. How to handle null values?
By using NVL functions we can handle null values.

S-ar putea să vă placă și