Вы находитесь на странице: 1из 10

Question: What are the wildcards used for pattern matching.

Answer: _ for single character substitution and % for multi-character substituti


on.

Question: How can I hide a particular table name of our schema?


Answer: you can hide the table name by creating synonyms.

e.g) you can create a synonym y for table x

create synonym y for x;

Question: When we give SELECT * FROM EMP; How does oracle respond:
Answer: When u give SELECT * FROM EMP;

the server check all the data in the EMP file and it displays the data of the EM
P file

Question: What is the use of CASCADE CONSTRAINTS?


Answer: When this clause is used with the DROP command, a parent table can be dr
opped even when a child table exists.

Question: There are 2 tables, Employee and Department. There are few records in
employee table, for which, the department is not assigned. The output of the que
ry should contain all th 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?
Answer: What you want to use here is called a left outer join with Employee tabl
e 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 fro
m 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. E.g. in this query wh
ich 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 i
s Employee_table.Dept_id *= Dept_table.Dept_id

SQL Server/Sybase :

Employee_table.Dept_id(+) = Dept_table.Dept_id

Question: on index
why u need indexing? Where that is stored
and what u mean by schema object?
For what purpose we are using view
Answer: We can?t create an Index on Index. Index is stored in user_index table.
Every object that has been created on Schema is Schema Object like Table, View e
tc. If we want to share the particular data to various users we have to use the
virtual table for the Base table...So that is a view.

Question: How to store directory structure in a database?


Answer: We can do it by the following command: create or replace directory as 'c
: \tmp'
Question: Why does the following command give a compilation error?
DROP TABLE &TABLE_NAME;
Answer: Variable names should start with an alphabet. Here the table name starts
with an '&' symbol.

Question: Difference between VARCHAR and VARCHAR2?


Answer: Varchar means fixed length character data (size) i.e., min size-1 and ma
x-2000

Varchar2 means variable length character data i.e., min-1 to max-4000

Question: Which command displays the SQL command in the SQL buffer, and then exe
cutes it

Answer: You set the LIST or L command to get the recent one from SQL Buffer

Question: Which system table contains information on constraints on all the tabl
es created?
Answer: USER_CONSTRAINTS.

Question: How do I write a program which will run a SQL query and mail the resul
ts to a group?
Answer: Use DBMS_JOB for scheduling a program job and DBMS_MAIL to send the resu
lts through email.

Question: There is an Eno. & gender in a table. Eno. has primary key and gender
has a check constraints for the values 'M' and 'F'.
While inserting the data into the table M was misspelled as F and F as M.
What is the update?
Answer: update set gender=

case where gender='F' Then 'M'

where gender='M' Then 'F'

Question: What the difference between UNION and UNIONALL?


Answer: union will return the distinct rows in two select s, while union all ret
urn all rows.

Question: How can we backup the sql files & what is SAP?
Answer: You can backup the sql files through backup utilities or some backup com
mand in sql. SAP is ERP software for the organization to integrate the software.

Question: What is the difference between TRUNCATE and DELETE commands?


Answer: 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.

Question: State true or false. !=, <>, ^= all denote the same operation.
Answer: True.

Question: State true or false. EXISTS, SOME, ANY are operators in SQL.
Answer: True.

Question: What will be the output of the following query?


SELECT REPLACE (TRANSLATE (LTRIM (RTRIM ('!! ATHEN!!','!'), '!'), 'AN', '**'),'*
','TROUBLE') FROM DUAL;
Answer: TROUBLETHETROUBLE.

Question: What is the advantage to use trigger in your PL?


Answer: Triggers are fired implicitly on the tables/views on which they are crea
ted. There are various advantages of using a trigger. Some of them are:

- Suppose we need to validate a DML statement (insert/Update/Delete) that modifi


es a table then we can write a trigger on the table that gets fired implicitly w
henever DML statement is executed on that table.

- Another reason of using triggers can be for automatic updation of one or more
tables whenever a DML/DDL statement is executed for the table on which the trigg
er is created.

- Triggers can be used to enforce constraints. For eg: Any insert/update/ Delete
statements should not be allowed on a particular table after office hours. For

enforcing this constraint Triggers should be used.

- Triggers can be used to publish information about database events to subscribe


rs. Database event can be a system event like Database startup or shutdown or it
can be a user even like User login in or user logoff.

Question: How write a SQL statement to query the result set and display row as c
olumns and columns as row?
Answer: TRANSFORM Count (Roll_no) AS Count of Roll_no
SELECT Academic_Status
FROM tbl_enr_status
GROUP BY Academic_Status
PIVOT Curnt_status;

Question: Cursor Syntax brief history


Answer: To retrieve data with SQL one row at a time you need to use cursor proce
ssing. Not all relational databases support this, but many do. Here I show this
in Oracle with PL/SQL, which is Procedural Language SQL .Cursor processing is do
ne in several steps:1. Define the rows you want to retrieve. This is called decl
aring the cursor.2. Open the cursor. This activates the cursor and loads the dat
a. Note that declaring the cursor doesn't load data, opening the cursor does.3.
Fetch the data into variables.4. Close the cursor.

Question: What is the data type of the surrogate key?


Answer: Data type of the surrogate key is either integer or numeric or number

Question: How to write a sql statement to find the first occurrence of a non zer
o value?
Answer: There is a slight chance the column "a" has a value of 0 which is not nu
ll. In that case, you?ll loose the information. There is another way of searchin
g the first not null value of a column:

select column_name from table_name where column_name is not null and rownum<2;

Question: What is normalazation, types with e.g.\'s. _ with queries of all types
Answer: There are 5 normal forms. It is necessary for any database to be in the
third normal form to maintain referential integrity and non-redundancy.

First Normal Form: Every field of a table (row, col) must contain an atomic valu
e
Second Normal Form: All columns of a table must depend entirely on the primary k
ey column.
Third Normal Form: All columns of a table must depend on all columns of a compos
ite primary key.
Fourth Normal Form: A table must not contain two or more independent multi-value
d facts. This normal form is often avoided for maintenance reasons.
Fifth Normal Form: is about symmetric dependencies.
Each normal form assumes that the table is already in the earlier normal form.

Question: Given an unnormalized table with columns:


Answer: The query will be: delete from tabname where rowid not in (select max (r
owid) from tabname group by name) Here tabname is the table name.

Question: How to find second maximum value from a table?


Answer: select max (field1) from tname1 where field1= (select max (field1) from
tname1 where field1<(select max(field1) from tname1);

Field1- Salary field

Tname= Table name.

Question: What is the advantage of specifying WITH GRANT OPTION in the GRANT com
mand?
Answer: The privilege receiver can further grant the privileges he/she has obtai
ned from the owner to any other user.

Question: What is the main difference between the IN and EXISTS clause in sub qu
eries??
Answer: The main difference between the IN and EXISTS predicate in sub query is
the way in which the query gets executed.

IN -- The inner query is executed first and the list of values obtained as its r
esult is used by the outer query. The inner query is executed for only once.

EXISTS -- The first row from the outer query is selected, then the inner query i
s executed and, the outer query output uses this result for checking. This proce
ss of inner query execution repeats as many no .of times as there are outer quer
y rows. That is, if there are ten rows that can result from outer query, the inn
er query is executed that many no. of times.

Question: TRUNCATE TABLE EMP;


DELETE FROM EMP;
Will the outputs of the above two commands differ
Answer: The difference is that the TRUNCATE call cannot be rolled back and all m
emory space for that table is released back to the server. TRUNCATE is much fast
er than DELETE and in both cases only the table data is removed, not the table s
tructure.

Question: What is table space?


Answer: Table-space is a physical concept. It has pages where the records of the
database are stored with a logical perception of tables. So table space contain
s tables.

Question: How to find out the 10th highest salary in SQL query?

Answer: Table - Tbl_Test_Salary


Column - int_salary
select max (int_salary)
from Tbl_Test_Salary
where int_salary in
(select top 10 int_Salary from Tbl_Test_Salary order by int_salary)

Question: Which command executes the contents of a specified file?


Answer: START or @.

Question: What is the difference between SQL and SQL SERVER?


Answer: SQL Server is an RDBMS just like oracle, DB2 from Microsoft
whereas
Structured Query Language (SQL), pronounced "sequel", is a language that provide
s an interface to relational database systems. It was developed by IBM in the 19
70s for use in System R. SQL is a de facto standard, as well as an ISO and ANSI
standard. SQL is used to perform various operations on RDBMS.

Question: What is the difference between Single row sub-Query and Scalar Sub-Que
ry?
Answer: SINGLE ROW SUBQUERY RETURNS A VALUE WHICH IS USED BY WHERE CLAUSE, WHERE
AS SCALAR SUBQUERY IS A SELECT STATEMENT USED IN COLUMN LIST CAN BE THOUGHT OF A
S AN INLINE FUNCTION IN SELECT COLUMN LIST.

Question: What does the following query do?


Answer: SELECT SAL + NVL (COMM, 0) FROM EMP;

It gives the added value of sal and comm for each employee in the emp table.

NVL (null value) replaces null with 0.

Question: How to find second maximum value from a table?


Answer: select max (field1) from tname1 where field1= (select max (field1) from
tname1 where field1< (select max (field1) from tname1);
Field1- Salary field
Tname= Table name.

Question: I have a table with duplicate names in it. Write me a query which retu
rns only duplicate rows with number of times they are repeated.
Answer: SELECT COL1 FROM TAB1
WHERE COL1 IN
(SELECT MAX (COL1) FROM TAB1
GROUP BY COL1
HAVING COUNT (COL1) > 1)

Question: How to find out the database name from SQL*PLUS command prompt?
Answer: Select * from global_name;
This will give the data base name which u r currently connected to.....

Question: How to display duplicate rows in a table?


Answer: select * from emp

group by (empid)

having count (empid)>1

Question: 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;


Answer: sal = 11000, comm = 1000.

Question: 1) What is difference between Oracle and MS Access?


2) What are disadvantages in Oracle and MS Access?
2) What are features & advantages in Oracle and MS Access?
Answer: Oracle's features for distributed transactions, materialized views and r
eplication are not available with MS Access. These features enable Oracle to eff
iciently store data for multinational companies across the globe. Also these fea
tures increase scalability of applications based on Oracle.

Вам также может понравиться