Professional Documents
Culture Documents
types of DBMS,queries
what is a cursor
types of cursors
normalization
normal forms
what is an os
Types of joins ?
what is a trigger ?
DECLARE
CURSOR c1 IS SELECT ename FROM emp;
name1 emp.ename%TYPE;
name2 emp.ename%TYPE;
name3 emp.ename%TYPE;
BEGIN
OPEN c1;
FETCH c1 INTO name1; -- this fetches first row
FETCH c1 INTO name2; -- this fetches second row
FETCH c1 INTO name3; -- this fetches third row
...
CLOSE c1;
END;
what is SGA.
what is er-model.
how do you compare an entity with class or object.
how do you design a project.
what is testing
ORACLE
Doubts :
• WHAT R SYNONYMS AND SEQUENCES IN PL/SQL;
• how can you store a image in the database.
• what do you mean by where current of C1
• LONG RAW data type is used for storing BLOB's (binary large objects).( ie graphics and
images)
• what is soundex built in function
• what is to_number, to_char.
Integrity : the quality or state of being complete; unbroken condition; wholeness; entirety .
Consistency : agreement, holding firmly.
Constrain : to force into, or hold in, close bounds
Introduction to Oracle
Oracle is a comprehensive operating environment that packs the power of mainframe
relation database management system into user’s micro computer. It provides a set of functional
programs that user can use as tools to build structures and perform tasks. Because applications are
developed on oracle are completely portable to the other versions of the programmer can create a
complex application in a single user, environment and them move it to a multi user platform.Users
do not have to be an expert to appriciate Oracle but the better user understand the program,the
more productively and creatively he can use the tools it provides
WHY ORACLE ?
Oracle is an open system i.e. the database is accessing by different data access
languages like SQL, Visual Basic, Power Builders,Delphi,VC++,JAVA etc.
Oracle supports database upto gigabytes in size.
* Oracle supports large number of concurrent users.
* Oracle supports true client/server environment.if enable processing to be spilt between
database server and the client application programs.
* Oracle provides high levelof data security in terms of users, passwords privileges, and
permissions.
* Oracle database behaves same on all platform line Windows,Unix,Dos,Mainframes etc.
physical structure:
one or more data files, Two of more log files, One control file.
Logical structure:
Table spaces,
Segments, Extents, Data blocks.
The data files contain all user data in terms of tables, index, and views. The log files
contain the information to open and be recovered, of Undone after a transaction(Rollback).
The control file physical data, media information to open and manage data files .If the
control file is damaged the server will not be able to open are use the database even if the
database is undamaged.
What are the Back ground processes in Oracle and what are they. ?
There are basically 9 Processes but in a general system we need to mention the first five
background processes. They do the house keeping activities for the Oracle and are common in
any system.
a) Data Base Writer(DBWR) ::
Data Base Writer Writes Modified blocks from Database buffer cache to Data Files.This is
required since the data is not written whenever a transaction is commited.
b)LogWriter(LGWR) ::
LogWriter writes the redo log entries to disk. Redo Log data is generated in redo log buffer
of SGA. As transaction commits and log buffer fills, LGWR writes log entries into a online redo
log file.
c) System Monitor(SMON) ::
The System Monitor performs instance recovery at instance startup. This is useful for
recovery from system failure.
d)Process Monitor(PMON) ::
The Process Monitor peforms process recovery when user Process fails. Pmon Clears and
Frees resources that process was using.
e) CheckPoint(CKPT) ::
At Specified times, all modified database buffers in SGA are written to data files by
DBWR at Checkpoints and Updating all data files and control files of database to indicate the
most recent checkpoint.
f)Archieves(ARCH) ::
The Archiver copies online redo log files to archival storal when they are busy.
g) Recoveror(RECO) ::
The Recoveror is used to resolve the distributed transaction in network
h) Dispatcher (Dnnn) ::
The Dispatcher is useful in Multi Threaded Architecture
i) Lckn ::
We can have upto 10 lock processes for inter instance locking in parallel sql.
NORMALIZATION
Normalization is a process of simplifying the relationship between data elements in a
record. Through Normalization a collection of data in a record structure is replaced by successive
record structures that are simpler and more predictable and therefore more manageable. It is
process of reducing redundancy and eliminating the anomalies. (anamali means inconsistent state.)
There are totally Five Normal Forms(Rules) out of which, any database should necessarily satisfy
three of them, those Three Normal Forms are as follows:
First normal form is achieved when all repeating groups are removed so that a record is
of fixed length. A repeating group, the re-occurrence of a data item within a record, is actually
another relation. Hence, it is removed from the record and treated as an additional record structure,
or relation.
Second Normal form should be in first normal form and no partial dependency exists.
Means if we have a composite primary key(combination of 2 or more fields) then all the non keys
must depend on the composite primary key. no attribute should depend upon the part of key.(for
example if Rollno and SSno is a composite key, then no other field in that particular table should
be depedent upon either Rollno or ssno individually)
Third Normal form is achieved when Transitive Dependencies are removed from a record
design.
The general case is as follows :
A,B and C are three data items in a record. If C is functionally dependent on B (2nd N.F) and
B is functionally dependent on A Then C is functionally dependent on A Therefore, a Transitive
Dependency exists.
In data management, transitive dependency is a concern because data can inadvertently be
lost when the relationship is hidden. In the general case above, if A is deleted, then B and C are
deleted also, whether or not this is intended. This problem is eliminated by designing the record
for third normal form. Conversion to third normal form removes the transitive dependency by
splitting the relation into two separate relations.
BCNF must be 3NF and every determinant is a candidate key. Candidate key is other than
primary key, which uniquely identify each row in the table.
for example ssno is PK then rollno becomes Candidate key.
4NF and 5NF are depends on instance. we can not give a proper def.
bcz it all depends on joins.
“CODD’s 12 RULES" for a fully Relational DBMS
INTRODUCTION
According to Elmasri and Navathe (1994), Dr. E. F. Codd, the originator of the relational
data model, published a two-part article in ComputerWorld (Codd, 1985) that lists 12 rules for
how to determine whether a DBMS is relational and to what extent it is relational. These rules
provide a very useful yardstick for evaluating a relational system. Codd also mentions that,
according to these rules, no fully relational system is available yet. In particular, rules 6, 9, 10, 11,
and 12 are difficult to satisfy.
THE 12 RULES
On the basis of the above rules, there is no fully relational DBMS available today.
What are various privileges that a user can grant to another user ?
SELECT, CONNECT, RESOURCES
There is a string '120000 12 0 .125' ,how you will find the position of the decimal place ?
INSTR('120000 12 0 .125',1,'.')
output 13
There is a '%' sign in one field of a column. What will be the query to find it ?
'\' Should be used before '%'.
When you use WHERE clause and when you use HAVING clause ?
HAVING clause is used when you want to specify a condition for a group function and it is
written after GROUP BY clause
The WHERE clause is used when you want to specify a condition for columns, single row
functions except group functions and it is written before GROUP BY clause if it is used.
Suppose customer table is there having different columns like customer no, payments.What
will be the query to select top three max payments ?
SELECT customer_no, payments from customer C1 WHERE 3<=(SELECT COUNT(*) from
customer C2 WHERE C1.payment <= C2.payment)
What is a cursor ?
Oracle uses work area to execute SQL statements and store processing information PL/SQL
construct called a cursor lets you name a work area and access its stored information A cursor is a
mechanism used to fetch more than one row in a PL/SQL block.
Difference between an implicit & an explicit cursor ?
PL/SQL declares a cursor implicitly for all SQL data manipulation statements, including
quries that return only one row. However,queries that return more than one row you must declare
an explicit cursor or use a cursor FOR loop.
Explicit cursor is a cursor in which the cursor name is explicitly assigned to a SELECT
statement via the CURSOR...IS statement. An implicit cursor is used for all SQL statements
Declare, Open, Fetch, Close. An explicit cursors are used to process multirow SELECT statements
An implicit cursor is used to process INSERT, UPDATE, DELETE and single row SELECT.
.INTO statements.
What should be the return type for a cursor variable. Can we use a scalar data type as
return type ?
The return type for a cursor must be a record type.It can be declared explicitly as a user-defined or
%ROWTYPE can be used. eg TYPE t_studentsref IS REF
CURSOR RETURN students%ROWTYPE
Can cursor variables be stored in PL/SQL tables.If yes how.If not why?
No, a cursor variable points a row which cannot be stored in a two-dimensional PL/SQL table.
The prcompiler translates the embedded SQL and pl/sql ststements into calls to the precompiler
runtime library.The output must be compiled and linked with this library to creater an executable.
What is maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE
function?
1,000,000
What is index ?
INDEX is a general term for an ORACLE / SQL feature used primarily to speed execution an
impose UNIQUENESS upon certain data. INDEX provides a faster access method to one table’s
data than doing a full table scan.
There are several types of Indexes :
UNIQUE INDEX, COMPRESSED INDEX, CONCATENATED INDEX. An Index has an entry
for each value found in the table’s Indexed field(s) ( except those with a NULL value ) and
pointer(s) to the rows having that value.
What is a package ?
A PACKAGE is a PL/SQL object that groups PL/SQL types, variables, SQL cursors,
exceptions,procedures, and functions.Each package has a specification and a body. The
specification shows the object you can access when you use the package. The body fully defines
all the objects and can contain additional objects used only for the internal workings. You can
change the body (for example, by adding procedures to the packages) without invalidating any
object that uses the package.
What is Schema ?
A SCHEMA is a collection of objects.
SCHEMA objects are logical structures that directly refer to the database’s data.
SCHEMA objects include structures such as tables, views, synonyms, sequences, indexes,
clusters, stored procedures and data links.
1. What is a View ? Why is it required to define a View ?
A View is a database object that is a logical representation of a table. It is derived from a
table but has no storage space of its own and often may be used in the same manner as a table.
Advantage: 1. Security 2. Complex query can be replaced.
DBMS_OUTPUT package allows you to use 3 debugging functions within your package. You
must set ‘SERVER OUTPUT ON’ before executing the procedure object you will be debugging.
PUT - Puts multiple o/p’s on same line.
PUT_LINE - Puts each o/p on a separate line.
NEW_LINE - Used with PUT; Signals the END of current o/p line.
41. What is the DIFFERENCE between EXPLICIT CURSOR & IMPLICIT CURSOR ?
IMPLICIT CURSORS are automatically opened by issuing a SELECT statement. But the
EXPLICIT cursors are to be opened using OPEN, fetching is done using FETCH and closing
using CLOSE.
13. To group users based on common access permission one should use
(A) User Groups (B) Roles (C) Grants (D) None of the above
15. Which of the constraint can be defined at the table level as well as at the column level
(A) Unique (B) Not Null (C) Check (D) All the above
16. To change the default date format in a SQLPLUS Session you have to
(A) Set the new format in the DATE_FORMAT key in the windows Registry.
(B) Alter session to set NLS_DATE-FORMAT.
(C) Change the Config.ora File for the date base.
(D) Change the User Profile USER-DATE-FORMAT.
17. Which of the following is not necessarily an advantages of using a package rather than
independent stored procedure in data base.
(A) Better performance. (B) Optimized memory usage.
(C) Simplified Security implementation. (D) Encapsulation.
QUERIES
Where do we use distinct keyword ?
Distinct is used to avoid duplicating records…………………
DELETE
FROM table_name A
WHERE rowid>(SELECT min(rowid) from table_name B where
B.table_no=A.table_no);
DROP old_table
RENAME new_table TO old_table
DELETE FROM table_name A
WHERE rowid NOT IN (SELECT MAX(ROWID) FROM table_name
GROUP BY column_name)
• Should follow the Hungarian Style in naming the Database name (SQL server), Schema
name(Oracle), field/column name in the respective databases.
Example:
EmployeeName ------ Correct
EmpName, empname, emp_name ------ Incorrect
• If the Column/Table name exceeds more than 30 characters the developer can go for
abbreviated names, but it should be completely relevant to the work what the table is
doing.
For Example: The ProjectSpecificPreferencesDetails Table can be named ProjSpecPrefDetails,
which is meaningful and also satisfies the field/column’s length.
• Should use the concepts of Stored Procedures (SQL Server), Procedures (Oracle),
Functions, Triggers where ever necessary in the database design Try to avoid unnecessary
connections in the database server in a loop. Using Procedures,
Functions and Triggers solves this problem. Another alternative is to get the whole data
into the client and try to solve the problem in the client level only, instead of interacting
with the server for several times in a loop.
• Should follow the Normalization concepts properly. Try to achieve the Third Normal Form
for the data base which is designed, it is considered to be more efficient.(Normal Forms are
discussed below)
• No table in the database should be independent. Every table should be related with one or
the other table.
• Should follow the concept of index in the database. Multiple indexing is advisable if there
is an assumption of storing huge data. Retrieval of data will be faster if indexes are used.