Vous êtes sur la page 1sur 8

1. Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?

i.DML* stands for Date Manipulation LanguageExamples 1>update2>delete3>alter4>merge


ii.DDL statements.DML statements manipulate only data within the data structures already created by DDL
statements.

2. What operator performs pattern matching?

Like operator.

It is used with and_


means starts or ends with anything

Eg:

If we want to display name ends with jay


select name from employee where name like ' jay ';
Output: Name
------
Vijay
Ajay
Sanjay
sujay
_ is used with like for exact pattern matching
EX:select name from emp where name like'_ jay';
Output: name
-----
vijay
sujay

3. What operator tests column for the absence of data?

IS NULL operator

4. Which command executes the contents of a specified file?

START <filename> or @<filename>

5. What is the parameter substitution symbol used with INSERT INTO command?

&

6. Which command displays the SQL command in the SQL buffer, and then executes it?

Run command It's a SQL*PLUS Command

Synonym of RUN is R

Note:'/' will only execute the last sql statement stored in the buffer and will not
display it.
LIST LIS LI or L will list (Display) the sql statement stored in the buffer but will
not execute.
7. What are the wildcards used for pattern matching?

_ for single character substitution and % for multi-character substitution

8. State true or false. EXISTS, SOME, ANY are operators in SQL.

True

9. State true or false. !=, <>, ^= all denote the same operation.

True

10. 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

11. What command is used to get back the privileges offered by the GRANT command?

REVOKE

12. Which system tables contain information on privileges granted and privileges obtained?

USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD

13. Which system table contains information on constraints on all the tables created?

USER_CONSTRAINTS

Eg: to see constraints on a particular table like emp:

select constraint_name constraint_type table_name from user_constraints;

14. TRUNCATE TABLE EMP;,DELETE FROM EMP;, Will the outputs of the above two commands?

Both will result in deleting all the rows in the table EMP.

The difference is that the TRUNCATE call cannot be rolled back and all memory space for that
table is released back to the server. TRUNCATE is much faster than DELETE and in both cases
only the table data is removed, not the table structure.

15.What is the difference between TRUNCATE and DELETE commands?

a)

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.

b)
1. For truncate command trigger will not get fired but for Delete Command Trigger will get
fired.

2. Truncate Is the DDL command whereas Delete is the DML command

3.Once the truncate command is issued Transactions can't be rolled back whereas transactions can
be rolled back for Delete command.

16.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.

17.What will be the output of the following query?

SELECT REPLACE(TRANSLATE(LTRIM(RTRIM('!! ATHEN !!','!'), '!'), 'AN', '**'),'*','TROUBLE')


FROM DUAL;

TROUBLETHETROUBLE

18. 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.

19.Which date function is used to find the difference between two dates?

MONTHS_BETWEEN

20. 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.

21.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.

22. What is the use of the DROP option in the ALTER TABLE command?

It is used to drop constraints specified on the table.

23. 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

24. What is the use of DESC in SQL?

Answer :

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.

25. 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.

26. Which function is used to find the largest integer less than or equal to a specific value?

FLOOR

27. What is the output of the following query?

SELECT TRUNC(1234.5678,-2) FROM DUAL;

1200

28.What is the difference between Single row sub-Query and Scalar sub-Query?

Single row subqueries returns only one row of results.A single row sub query uses a single row
operator; the common operator is the equality operator( ).
A Scalar subquery returns exactly one column value from one row.Scalar subqueris can be ysed in
most places where you would use a column nae or expression such as inside a sigle row function
as an argument in insert order by clause where clause case expressions but not in group by or
having clause.
29. I have a table with duplicate names in it. Write me a query which returns only duplicate rows with
number of times they are repeated?

a)

select name count(name) occurences


from table1
group by name
having count(name)>1

b)

SELECT DISTINCT (column name) from TABLENAME

Used to return a dataset with unique entries for certain database table column

30.How do I write a cron which will run a SQL query and mail the results to a group?

Use DBMS_JOB for scheduling a cron job and DBMS_MAIL to send the results through email.

31.How to copy a SQL table?

to copy a table along with records:


create table <new table1> as
select *from <old tablename>;

if we want to copy only structure:


create table < new tablename>
select *from <old tablename> where <false condition>;

32. Is there any query which is use to find the case sensitivity in each records in database through visual
basic?

For case sensitive string comparison in SQL one has to use substring() and ascii() functions in the
following way.

1. Get first character of both strings using substring function as substring(str1 1 1)


2. Find ascii value of both characters and compare.
3. Put statements 1 and 2 in loop to advance to next character

For example if (ascii(substring(str1 @pos 1)) ascii(substring(str2 @pos 1)) then @pos @pos + 1 ....

33.Difference between Store Procedure and Trigger?

a)
Stored procedure and Trigger both will be in the database in precompiled formate which ready execute the
main difference between these two is

to execute the stored procedure programe need to type execute statement where as to execute trigger
programer no need type execute statement trigger will fire automatically when an event(like insert delete)
on the table

b)

Information related to Stored procedure you can see in USER_SOURCE USER_OBJECTS(current user)
tables.

Information related to triggers stored in USER_SOURCE USER_TRIGGERS (current user) Tables.

Stored procedure can't be inactive but trigger can be Inactive.

34. Cursor Syntax brief history?

To retrieve data with SQL one row at a time you need to use cursor processing.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 done in several steps:1. Define the rows you want to retrieve.
This is called declaring the cursor.2. Open the cursor. This activates the cursor and loads the data.
Note that declaring the cursor doesn't load data opening the cursor does.3. Fetch the data into
variables.4. Close the cursor.

35.Explain normalization with examples?

a)

Normalization is a process of eleminating the redundancy and increasing the integrity.

b)

1NF: If any tables have a many to many relationship this must be broken out using a JOIN table.
For example Customers can have many Suppliers and Suppliers can supply to many Customers.
This is known as a many to many relationship. You would need to create a JOIN table that would
have a primary key made up of a foreign key reference to the Customers table and a foreign key
reference to the suppliers table. Therefore the SuppliersPerCustomer table would be {SupplierID
CustomerID}. Now the Suppliers table will have a 1 to many relationship with the
SuppliersPerCustomer table and the Customers table will also have a 1 to many relationship with
the SuppliersPerCustomer table.

2NF: The database must meet all the requirements of the 1NF.

In addition records should not depend on anything other than a table's primary key (a primary key
can be made up of more than one field only if absolutely necessary like in a JOIN table).

Example:

A customers address is needed by the Customers table but also by the Orders and Invoices tables.
Instead of storing the customer's address as a separate entry in each of these tables store it in one
place either in the Customers table or in a separate Addresses table.

3NF : The database must meet all the requirements of the 1NF and 2NF.

A relational table is in third normal form (3NF) if it is already in 2NF and every non-key column
is non transitively dependent upon its primary key.

The Customer table contains information such as address city postcode imagine it also contained a
column called shipping cost. The value of shipping cost changes in relation to which city the
products are being delivered to and therefore is not directly dependent on the customer even
though the cost might not change per customer but it is dependent on the city that the customer is
in. Therefore we would need to create another separate table to hold the information about cities
and shipping costs.

36. How to find out the database name from SQL*PLUS command prompt?

SELECT INSTANCE_NAME from V$INSTANCE;

37. How can we backup the sql files & what is SAP?

Use Export and Import tools for backups and restore resp.
you can use exp and imp as well

38.Whats the back end processes when we type "Select * from Table"?

First it will look into the System Global Area (SGA) weather the query is been exectued earlier.

If it exist it would retrive the same output present in memory.

If not the query we typed is complied and the resulting parse tree and excution plan is been stored
in SGA. Then query gets executed and output is given to the application.

39. What is the difference between SQL and SQL Server?

a)

SQLServer is an RDBMS just like oracle DB2 from Microsoft

whereas

Structured Query Language (SQL) pronounced sequel is a language that provides an interface to
relational database systems. It was developed by IBM in the 1970s 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

b)

SQL - Structured Query Language - is an open vendor-independent


standardised language for accessing and manipulating data stored in
relational databases. The standards are defined by ANSI.
SQL Server is one of many products that supports and implements the SQL language.

If I write SELECT SomeField FROM SomeTable that's a SQL statement. Of course by itself
simply typed into a text editor it doesn't do anything. It must be executed by a database engine that
understands how to translate the SQL statement into the low-level commands required to retrieve
the data from the proprietary database format. SQL Server is one such database engine.

40. What is table space?

a)
Tablespace is an logical storage structure at the highest level that stores all the data in datafiles.

b)
Table-space is a physical concept.it has pages where the records of the database is stored with a
logical perception of tables.so tablespace contains tables.

c)
A logical portion of a database used in allocating storage for table data and table indexes.

A tablespace is a logical structure that contains segments. Rollback data and index are the three
types of segments created inside a tablespace. Each segment is made up of extents and the extents
are comprised of data blocks.

The system tablespace contains the data dictionary for the Oracle database.

41.What is difference between Co-related sub query and nested sub query?

Co-related sub query is one in which inner query is evaluated only once and from that result outer
query is evaluated.

Nested query is one in which Inner query is evaluated for multiple times for gatting one row of
that outer query.

ex. Query used with IN() clause is Co-related query.


Query used with = operator is Nested query

Vous aimerez peut-être aussi