0% found this document useful (0 votes)
244 views

DBMS Questions: Ramesh 1 Ramesh

DBMS stands for Database Management System. It is a collection of programs that enables users to create and maintain a database. It provides functions like defining, constructing, and manipulating databases for various applications. The database and DBMS software together form the database system. DBMS provides advantages like reducing redundancy, restricting unauthorized access, enforcing integrity constraints, and providing backup and recovery.

Uploaded by

Kalyan Majji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
244 views

DBMS Questions: Ramesh 1 Ramesh

DBMS stands for Database Management System. It is a collection of programs that enables users to create and maintain a database. It provides functions like defining, constructing, and manipulating databases for various applications. The database and DBMS software together form the database system. DBMS provides advantages like reducing redundancy, restricting unauthorized access, enforcing integrity constraints, and providing backup and recovery.

Uploaded by

Kalyan Majji
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 86

DBMS Questions

1. What is DBMS?
A database is a logically coherent collection of data with some inherent meaning, representing some
aspect of real world and which is designed, built and populated with data for a specific purpose.

2. It is a collection What is database?


of programs that enables user to create and maintain a database. In other words it is general-purpose
software that provides the users with the processes of defining, constructing and manipulating the database
for various applications.

3. What is a Database system?


The database and DBMS software together is called as Database system.

4. Advantages of DBMS?
Redundancy is controlled.
Unauthorised access is restricted.
Providing multiple user interfaces.
Enforcing integrity constraints.
Providing backup and recovery.

5. Disadvantage in File Processing System?


Data redundancy & inconsistency.
Difficult in accessing data.
Data isolation.
Data integrity.
Concurrent access is not possible.
Security Problems.

6. Describe the three levels of data abstraction?


The are three levels of abstraction:
Physical level: The lowest level of abstraction describes how data are stored.
Logical level: The next higher level of abstraction, describes what data are stored in database and what
relationship among those data.
View level: The highest level of abstraction describes only part of entire database.
7. Define the "integrity rules"
There are two Integrity rules.
Entity Integrity: States that “Primary key cannot have NULL value”
Referential Integrity: States that “Foreign Key can be either a NULL value or should be
Primary Key value of other relation.

8. What is extension and intension?


Extension -
It is the number of tuples present in a table at any instance. This is time dependent.
Intension -
It is a constant value that gives the name, structure of table and the constraints laid on it.

9. What is System R? What are its two major subsystems?


System R was designed and developed over a period of 1974-79 at IBM San Jose Research Center. It
is a prototype and its purpose was to demonstrate that it is possible to build a Relational System that can be

Ramesh 1 Ramesh
DBMS Questions
used in a real life environment to solve real life problems, with performance at least comparable to that of
existing system.
Its two subsystems are
Research Storage
System Relational Data System.

10. How is the data structure of System R different from the relational structure?
Unlike Relational systems in System R
Domains are not supported
Enforcement of candidate key uniqueness is optional
Enforcement of entity integrity is optional
Referential integrity is not enforced

11. What is Data Independence?


Data independence means that “the application is independent of the storage structure and access
strategy of data”. In other words, The ability to modify the schema definition in one level should not affect the
schema definition in the next higher level.
Two types of Data Independence:
Physical Data Independence: Modification in physical level should not affect the logical level.
Logical Data Independence: Modification in logical level should affect the view level.
NOTE: Logical Data Independence is more difficult to achieve

12. What is a view? How it is related to data independence?


A view may be thought of as a virtual table, that is, a table that does not really exist in its own right
but is instead derived from one or more underlying base table. In other words, there is no stored file that
direct represents the view instead a definition of view is stored in data dictionary.
Growth and restructuring of base tables is not reflected in views. Thus the view can insulate users
from the effects of restructuring and growth in the database. Hence accounts for logical data independence.

13. What is Data Model?


A collection of conceptual tools for describing data, data relationships data semantics and
constraints.

14. What is E-R model?


This data model is based on real world that consists of basic objects called entities and of relationship
among these objects. Entities are described in a database by a set of attributes.

15. What is Object Oriented model?


This model is based on collection of objects. An object contains values stored in instance variables
with in the object. An object also contains bodies of code that operate on the object. These bodies of code
are called methods. Objects that contain same types of values and the same methods are grouped together
into classes.

16. What is an Entity?


It is a 'thing' in the real world with an independent existence.

17. What is an Entity type?


It is a collection (set) of entities that have same attributes.

Ramesh 2 Ramesh
DBMS Questions

18. What is an Entity set?


It is a collection of all entities of particular entity type in the database.

19. What is an Extension of entity type?


The collections of entities of a particular entity type are grouped together into an entity set.

20. What is Weak Entity set?


An entity set may not have sufficient attributes to form a primary key, and its primary key
compromises of its partial key and primary key of its parent entity, then it is said to be Weak Entity set.

21. What is an attribute?


It is a particular property, which describes the entity.

22. What is a Relation Schema and a Relation?


A relation Schema denoted by R(A1, A2, …, An) is made up of the relation name R and the list of
attributes Ai that it contains. A relation is defined as a set of tuples. Let r be the relation which contains set
tuples (t1, t2, t3, ..., tn). Each tuple is an ordered list of n-values t=(v1,v2, ..., vn).

23. What is degree of a Relation?


It is the number of attribute of its relation schema.

24. What is Relationship?


It is an association among two or more entities.

25. What is Relationship set?


The collection (or set) of similar relationships.

26. What is Relationship type?


Relationship type defines a set of associations or a relationship set among a given set of entity types.

27. What is degree of Relationship type?


It is the number of entity type participating.

25. What is DDL (Data Definition Language)?


A data base schema is specifies by a set of definitions expressed by a special language called DDL.

26. What is VDL (View Definition Language)?


It specifies user views and their mappings to the conceptual schema.

27. What is SDL (Storage Definition Language)?


This language is to specify the internal schema. This language may specify the mapping between two
schemas.

28. What is Data Storage - Definition Language?


The storage structures and access methods used by database system are specified by a set of
definition in a special type of DDL called data storage-definition language.

Ramesh 3 Ramesh
DBMS Questions
29. What is DML (Data Manipulation Language)?
This language that enable user to access or manipulate data as organised by appropriate data model.
Procedural DML or Low level: DML requires a user to specify what data are needed and how to get
those data.
Non-Procedural DML or High level: DML requires a user to specify what data are needed without
specifying how to get those data.

31. What is DML Compiler?


It translates DML statements in a query language into low-level instruction that the query evaluation
engine can understand.

32. What is Query evaluation engine?


It executes low-level instruction generated by compiler.

33. What is DDL Interpreter?


It interprets DDL statements and record them in tables containing metadata.

34. What is Record-at-a-time?


The Low level or Procedural DML can specify and retrieve each record from a set of records. This
retrieve of a record is said to be Record-at-a-time.

35. What is Set-at-a-time or Set-oriented?


The High level or Non-procedural DML can specify and retrieve many records in a single DML
statement. This retrieve of a record is said to be Set-at-a-time or Set-oriented.

36. What is Relational Algebra?


It is procedural query language. It consists of a set of operations that take one or two relations as
input and produce a new relation.

37. What is Relational Calculus?


It is an applied predicate calculus specifically tailored for relational databases proposed by E.F. Codd.
E.g. of languages based on it are DSL ALPHA, QUEL.

38. How does Tuple-oriented relational calculus differ from domain-oriented relational calculus
The tuple-oriented calculus uses a tuple variables i.e., variable whose only permitted values are tuples
of that relation. E.g. QUEL
The domain-oriented calculus has domain variables i.e., variables that range over the underlying domains
instead of over relation. E.g. ILL, DEDUCE.

39. What is normalization?


It is a process of analysing the given relation schemas based on their Functional Dependencies (FDs)
and primary key to achieve the properties
Minimizing redundancy
Minimizing insertion, deletion and update anomalies.

40. What is Functional Dependency?


A Functional dependency is denoted by X Y between two sets of attributes X and Y that are
subsets of R specifies a constraint on the possible tuple that can form a relation state r of R. The constraint is

Ramesh 4 Ramesh
DBMS Questions
for any two tuples t1 and t2 in r if t1[X] = t2[X] then they have t1[Y] = t2[Y]. This means the value of X
component of a tuple uniquely determines the value of component Y.

41. When is a functional dependency F said to be minimal?


Every dependency in F has a single attribute for its right hand side.
We cannot replace any dependency X A in F with a dependency Y A where Y is a proper subset of X
and still have a set of dependency that is equivalent to F.
We cannot remove any dependency from F and still have set of dependency that is equivalent to F.

42. What is Multivalued dependency?


Multivalued dependency denoted by X Y specified on relation schema R, where X and Y are
both subsets of R, specifies the following constraint on any relation r of R: if two tuples t1 and t2 exist in r
such that t1[X] = t2[X] then t3 and t4 should also exist in r with the following properties
t3[x] = t4[X] = t1[X] = t2[X]
t3[Y] = t1[Y] and t4[Y] = t2[Y]
t3[Z] = t2[Z] and t4[Z] = t1[Z]
where [Z = (R-(X U Y)) ]

43. What is Lossless join property?


It guarantees that the spurious tuple generation does not occur with respect to relation schemas after
decomposition.

44. What is 1 NF (Normal Form)?


The domain of attribute must include only atomic (simple, indivisible) values.

45. What is Fully Functional dependency?


It is based on concept of full functional dependency. A functional dependency X Y is full
functional dependency if removal of any attribute A from X means that the dependency does not hold any
more.

46. What is 2NF?


A relation schema R is in 2NF if it is in 1NF and every non-prime attribute A in R is fully
functionally dependent on primary key.

47. What is 3NF?


A relation schema R is in 3NF if it is in 2NF and for every FD X A either of the following is true
X is a Super-key of R.
A is a prime attribute of R.
In other words, if every non prime attribute is non-transitively dependent on primary key.

48. What is BCNF (Boyce-Codd Normal Form)?


A relation schema R is in BCNF if it is in 3NF and satisfies an additional constraint that for every FD
X A, X must be a candidate key.

49. What is 4NF?


A relation schema R is said to be in 4NF if for every Multivalued dependency X Y that
holds over R, one of following is true
X is subset or equal to (or) XY = R.

Ramesh 5 Ramesh
DBMS Questions
X is a super key.

50. What is 5NF?


A Relation schema R is said to be 5NF if for every join dependency {R1, R2, ..., Rn} that holds R,
one the following is true
Ri = R for some i.
The join dependency is implied by the set of FD, over R in which the left side is key of R.
51. What is Domain-Key Normal Form?
A relation is said to be in DKNF if all constraints and dependencies that should hold on the the
constraint can be enforced by simply enforcing the domain constraint and key constraint on the
relation.

52. What are partial, alternate,, artificial, compound and natural key?
Partial Key:
It is a set of attributes that can uniquely identify weak entities and that are related to same owner
entity. It is sometime called as Discriminator.
Alternate Key:
All Candidate Keys excluding the Primary Key are known as Alternate Keys.
Artificial Key:
If no obvious key, either stand alone or compound is available, then the last resort is to
simply create a key, by assigning a unique number to each record or occurrence. Then this is known as
developing an artificial key.
Compound Key:
If no single data element uniquely identifies occurrences within a construct, then combining
multiple elements to create a unique identifier for the construct is known as creating a compound key.
Natural Key:
When one of the data elements stored within a construct is utilized as the primary key, then it
is called the natural key.

53. What is indexing and what are the different kinds of indexing?
Indexing is a technique for determining how quickly specific data can be found.
Types:
Binary search style indexing
B-Tree indexing
Inverted list indexing
Memory resident table
Table indexing

54. What is system catalog or catalog relation? How is better known as?
A RDBMS maintains a description of all the data that it contains, information about every relation
and index that it contains. This information is stored in a collection of relations maintained by the system
called metadata. It is also called data dictionary.

55. What is meant by query optimization?


The phase that identifies an efficient execution plan for evaluating a query that has the least estimated
cost is referred to as query optimization.

56. What is join dependency and inclusion dependency?

Ramesh 6 Ramesh
DBMS Questions
Join Dependency:
A Join dependency is generalization of Multivalued dependency.A JD {R1, R2, ...,
Rn} is said to hold over a relation R if R1, R2, R3, ..., Rn is a lossless-join decomposition of R . There is no
set of sound and complete inference rules for JD.
Inclusion Dependency:
An Inclusion Dependency is a statement of the form that some columns of a relation are
contained in other columns. A foreign key constraint is an example of inclusion dependency.

57. What is durability in DBMS?


Once the DBMS informs the user that a transaction has successfully completed, its effects should
persist even if the system crashes before all its changes are reflected on disk. This property is called
durability.

58. What do you mean by atomicity and aggregation?


Atomicity:
Either all actions are carried out or none are. Users should not have to worry about the effect
of incomplete transactions. DBMS ensures this by undoing the actions of incomplete transactions.
Aggregation:
A concept which is used to model a relationship between a collection of entities and
relationships. It is used when we need to express a relationship among relationships.

59. What is a Phantom Deadlock?


In distributed deadlock detection, the delay in propagating local information might cause the
deadlock detection algorithms to identify deadlocks that do not really exist. Such situations are called
phantom deadlocks and they lead to unnecessary aborts.

60. What is a checkpoint and When does it occur?


A Checkpoint is like a snapshot of the DBMS state. By taking checkpoints, the DBMS can reduce the
amount of work to be done during restart in the event of subsequent crashes.

61. What are the different phases of transaction?


Different phases are
Analysis phase
Redo Phase
Undo phase

62. What do you mean by flat file database?


It is a database in which there are no programs or user access languages. It has no cross-file
capabilities but is user-friendly and provides user-interface management.

63. What is "transparent DBMS"?


It is one, which keeps its Physical Structure hidden from user.

64. Brief theory of Network, Hierarchical schemas and their properties


Network schema uses a graph data structure to organize records example for such a database
management system is CTCG while a hierarchical schema uses a tree data structure example for such a
system is IMS.

Ramesh 7 Ramesh
DBMS Questions
65. What is a query?
A query with respect to DBMS relates to user commands that are used to interact with a data base.
The query language can be classified into data definition language and data manipulation language.

66. What do you mean by Correlated subquery?


Subqueries, or nested queries, are used to bring back a set of rows to be used by the parent query.
Depending on how the subquery is written, it can be executed once for the parent query or it can be executed
once for each row returned by the parent query. If the subquery is executed for each row of the parent, this is
called a correlated subquery.
A correlated subquery can be easily identified if it contains any references to the parent subquery
columns in its WHERE clause. Columns from the subquery cannot be referenced anywhere else in the parent
query. The following example demonstrates a non-correlated subquery.
E.g. Select * From CUST Where '10/03/1990' IN (Select ODATE From ORDER Where CUST.CNUM
= ORDER.CNUM)

67. What are the primitive operations common to all record management systems?
Addition, deletion and modification.

68. Name the buffer in which all the commands that are typed in are stored
‘Edit’ Buffer

69. What are the unary operations in Relational Algebra?


PROJECTION and SELECTION.

70. Are the resulting relations of PRODUCT and JOIN operation the same?
No.
PRODUCT: Concatenation of every row in one relation with every row in another.
JOIN: Concatenation of rows from one relation and related rows from another.

71. What is RDBMS KERNEL?


Two important pieces of RDBMS architecture are the kernel, which is the software, and the data
dictionary, which consists of the system-level data structures used by the kernel to manage the database
You might think of an RDBMS as an operating system (or set of subsystems), designed specifically
for controlling data access; its primary functions are storing, retrieving, and securing data. An RDBMS
maintains its own list of authorized users and their associated privileges; manages memory caches and
paging; controls locking for concurrent resource usage; dispatches and schedules user requests; and manages
space usage within its table-space structures
.
72. Name the sub-systems of a RDBMS
I/O, Security, Language Processing, Process Control, Storage Management, Logging and Recovery,
Distribution Control, Transaction Control, Memory Management, Lock Management

73. Which part of the RDBMS takes care of the data dictionary? How
Data dictionary is a set of tables and database objects that is stored in a special area of the database
and maintained exclusively by the kernel.

74. What is the job of the information stored in data-dictionary?

Ramesh 8 Ramesh
DBMS Questions
The information in the data dictionary validates the existence of the objects, provides access to them,
and maps the actual physical storage location.

75. Not only RDBMS takes care of locating data it also


determines an optimal access path to store or retrieve the data

76. How do you communicate with an RDBMS?


You communicate with an RDBMS using Structured Query Language (SQL)

77. Define SQL and state the differences between SQL and other conventional programming Languages
SQL is a nonprocedural language that is designed specifically for data access operations on
normalized relational database structures. The primary difference between SQL and other conventional
programming languages is that SQL statements specify what data operations should be performed rather than
how to perform them.

78. Name the three major set of files on disk that compose a database in Oracle
There are three major sets of files on disk that compose a database. All the files are binary. These are
Database files
Control files
Redo logs
The most important of these are the database files where the actual data resides. The control files and
the redo logs support the functioning of the architecture itself.
All three sets of files must be present, open, and available to Oracle for any data on the database to be
useable. Without these files, you cannot access the database, and the database administrator might have to
recover some or all of the database using a backup, if there is one.

79. What is an Oracle Instance?


The Oracle system processes, also known as Oracle background processes, provide functions for the
user processes—functions that would otherwise be done by the user processes themselves
Oracle database-wide system memory is known as the SGA, the system global area or shared global
area. The data and control structures in the SGA are shareable, and all the Oracle background processes and
user processes can use them.

Ramesh 9 Ramesh
DBMS Questions

The combination of the SGA and the Oracle background


processes is known as an Oracle instance

80. What are the four Oracle system processes that must always be up and running for the database to be
useable
The four Oracle system processes that must always be up and running for the database to be useable
include DBWR (Database Writer), LGWR (Log Writer), SMON (System Monitor), and PMON (Process
Monitor).

81. What are database files, control files and log files. How many of these files should a database have at
least? Why?
Database Files
The database files hold the actual data and are typically the largest in size. Depending on their
sizes, the tables (and other objects) for all the user accounts can go in one database file—but that's not an
ideal situation because it does not make the database structure very flexible for controlling access to storage
for different users, putting the database on different disk drives, or backing up and restoring just part of the
database.
You must have at least one database file but usually, more than one files are used. In terms of
accessing and using the data in the tables and other objects, the number (or location) of the files is
immaterial.
The database files are fixed in size and never grow bigger than the size at which they were
created
Control Files
The control files and redo logs support the rest of the architecture. Any database must have at
least one control file, although you typically have more than one to guard against loss. The control file
records the name of the database, the date and time it was created, the location of the database and redo logs,
and the synchronization information to ensure that all three sets of files are always in step. Every time you
add a new database or redo log file to the database, the information is recorded in the control files.
Redo Logs
Any database must have at least two redo logs. These are the journals for the database; the
redo logs record all changes to the user objects or system objects. If any type of failure occurs, the changes
recorded in the redo logs can be used to bring the database to a consistent state without losing any committed

Ramesh 10 Ramesh
DBMS Questions
transactions. In the case of non-data loss failure, Oracle can apply the information in the redo logs
automatically without intervention from the DBA.
The redo log files are fixed in size and never grow dynamically from the size at which they
were created.

82. What is ROWID?


The ROWID is a unique database-wide physical address for every row on every table. Once assigned
(when the row is first inserted into the database), it never changes until the row is deleted or the table is
dropped.
The ROWID consists of the following three components, the combination of which uniquely
identifies the physical storage location of the row.
Oracle database file number, which contains the block with the rows
Oracle block address, which contains the row
The row within the block (because each block can hold many rows)
The ROWID is used internally in indexes as a quick means of retrieving rows with a particular key
value. Application developers also use it in SQL statements as a quick way to access a row once they know
the ROWID

83. What is Oracle Block? Can two Oracle Blocks have the same address?
Oracle "formats" the database files into a number of Oracle blocks when they are first created—
making it easier for the RDBMS software to manage the files and easier to read data into the memory areas.
The block size should be a multiple of the operating system block size. Regardless of the block size,
the entire block is not available for holding data; Oracle takes up some space to manage the contents of the
block. This block header has a minimum size, but it can grow.
These Oracle blocks are the smallest unit of storage. Increasing the Oracle block size can improve
performance, but it should be done only when the database is first created.
Each Oracle block is numbered sequentially for each database file starting at 1. Two blocks can have
the same block address if they are in different database files.

84. What is database Trigger?


A database trigger is a PL/SQL block that can defined to automatically execute for insert, update, and
delete statements against a table. The trigger can e defined to execute once for the entire statement or once
for every row that is inserted, updated, or deleted. For any one table, there are twelve events for which you
can define database triggers. A database trigger can call database procedures that are also written in PL/SQL.

85. Name two utilities that Oracle provides, which are use for backup and recovery.
Along with the RDBMS software, Oracle provides two utilities that you can use to back up and
restore the database. These utilities are Export and Import.
The Export utility dumps the definitions and data for the specified part of the database to an operating
system binary file. The Import utility reads the file produced by an export, recreates the definitions of objects,
and inserts the data
If Export and Import are used as a means of backing up and recovering the database, all the changes
made to the database cannot be recovered since the export was performed. The best you can do is recover the
database to the time when the export was last performed.

86. What are stored-procedures? And what are the advantages of using them.

Ramesh 11 Ramesh
DBMS Questions
Stored procedures are database objects that perform a user defined operation. A stored procedure can
have a set of compound SQL statements. A stored procedure executes the SQL commands and returns the
result to the client. Stored procedures are used to reduce network traffic.

87. How are exceptions handled in PL/SQL? Give some of the internal exceptions' name
PL/SQL exception handling is a mechanism for dealing with run-time errors encountered during
procedure execution. Use of this mechanism enables execution to continue if the error is not severe enough to
cause procedure termination.
The exception handler must be defined within a subprogram specification. Errors cause the program
to raise an exception with a transfer of control to the exception-handler block. After the exception handler
executes, control returns to the block in which the handler was defined. If there are no more executable
statements in the block, control returns to the caller.
User-Defined Exceptions
PL/SQL enables the user to define exception handlers in the declarations area of subprogram
specifications. User accomplishes this by naming an exception as in the following example:
ot_failure EXCEPTION;
In this case, the exception name is ot_failure. Code associated with this handler is written in the
EXCEPTION specification area as follows:
EXCEPTION
when OT_FAILURE then
out_status_code := g_out_status_code;
out_msg := g_out_msg;
The following is an example of a subprogram exception:
EXCEPTION
when NO_DATA_FOUND then
g_out_status_code := 'FAIL';
RAISE ot_failure;
Within this exception is the RAISE statement that transfers control back to the ot_failure exception handler.
This technique of raising the exception is used to invoke all user-defined exceptions.
System-Defined Exceptions
Exceptions internal to PL/SQL are raised automatically upon error. NO_DATA_FOUND is a
system-defined exception. Table below gives a complete list of internal exceptions.

PL/SQL internal exceptions.

Exception Name Oracle Error


CURSOR_ALREADY_OPEN ORA-06511
DUP_VAL_ON_INDEX ORA-00001
INVALID_CURSOR ORA-01001
INVALID_NUMBER ORA-01722
LOGIN_DENIED ORA-01017
NO_DATA_FOUND ORA-01403
NOT_LOGGED_ON ORA-01012
PROGRAM_ERROR ORA-06501
STORAGE_ERROR ORA-06500
TIMEOUT_ON_RESOURCE ORA-00051
TOO_MANY_ROWS ORA-01422
TRANSACTION_BACKED_OUT ORA-00061

Ramesh 12 Ramesh
DBMS Questions
VALUE_ERROR ORA-06502
ZERO_DIVIDE ORA-01476

In addition to this list of exceptions, there is a catch-all exception named OTHERS that traps all errors
for which specific error handling has not been established.

88. Does PL/SQL support "overloading"? Explain


The concept of overloading in PL/SQL relates to the idea that you can define procedures and
functions with the same name. PL/SQL does not look only at the referenced name, however, to resolve a
procedure or function call. The count and data types of formal parameters are also considered.
PL/SQL also attempts to resolve any procedure or function calls in locally defined packages before
looking at globally defined packages or internal functions. To further ensure calling the proper procedure,
you can use the dot notation. Prefacing a procedure or function name with the package name fully qualifies
any procedure or function reference.

89. Tables derived from the ERD


a) Are totally unnormalised
b) Are always in 1NF
c) Can be further denormalised
d) May have multi-valued attributes

(b) Are always in 1NF

90. Spurious tuples may occur due to


i. Bad normalization
ii. Theta joins
iii. Updating tables from join
a) i & ii b) ii & iii
c) i & iii d) ii & iii

(a) i & iii because theta joins are joins made on keys that are not primary keys.

91. A B C is a set of attributes. The functional dependency is as follows


AB -> B
AC -> C
C -> B
a) is in 1NF
b) is in 2NF
c) is in 3NF
d) is in BCNF

(a) is in 1NF since (AC)+ = { A, B, C} hence AC is the primary key. Since C B is a FD


given, where neither C is a Key nor B is a prime attribute, this it is not in 3NF. Further B is not functionally
dependent on key AC thus it is not in 2NF. Thus the given FDs is in 1NF.

92. In mapping of ERD to DFD


a) entities in ERD should correspond to an existing entity/store in DFD
b) entity in DFD is converted to attributes of an entity in ERD

Ramesh 13 Ramesh
DBMS Questions
c) relations in ERD has 1 to 1 correspondence to processes in DFD
d) relationships in ERD has 1 to 1 correspondence to flows in DFD

(a) entities in ERD should correspond to an existing entity/store in DFD

93. A dominant entity is the entity


a) on the N side in a 1 : N relationship
b) on the 1 side in a 1 : N relationship
c) on either side in a 1 : 1 relationship
d) nothing to do with 1 : 1 or 1 : N relationship

(b) on the 1 side in a 1 : N relationship

94. Select 'NORTH', CUSTOMER From CUST_DTLS Where REGION = 'N' Order By
CUSTOMER Union Select 'EAST', CUSTOMER From CUST_DTLS Where REGION = 'E' Order By
CUSTOMER
The above is
a) Not an error
b) Error - the string in single quotes 'NORTH' and 'SOUTH'
c) Error - the string should be in double quotes
d) Error - ORDER BY clause

(d) Error - the ORDER BY clause. Since ORDER BY clause cannot be used in UNIONS

95. What is Storage Manager?


It is a program module that provides the interface between the low-level data stored in database,
application programs and queries submitted to the system.

96. What is Buffer Manager?


It is a program module, which is responsible for fetching data from disk storage into main memory
and deciding what data to be cache in memory.

97. What is Transaction Manager?


It is a program module, which ensures that database, remains in a consistent state despite system
failures and concurrent transaction execution proceeds without conflicting.

98. What is File Manager?


It is a program module, which manages the allocation of space on disk storage and data structure used
to represent information stored on a disk.

99. What is Authorization and Integrity manager?


It is the program module, which tests for the satisfaction of integrity constraint and checks the
authority of user to access data.

100. What are stand-alone procedures?


Procedures that are not part of a package are known as stand-alone because they independently
defined. A good example of a stand-alone procedure is one written in a SQL*Forms application. These types

Ramesh 14 Ramesh
DBMS Questions
of procedures are not available for reference from other Oracle tools. Another limitation of stand-alone
procedures is that they are compiled at run time, which slows execution.

101. What are cursors give different types of cursors.


PL/SQL uses cursors for all database information accesses statements. The language supports the
use two types of cursors
Implicit
Explicit

102. What is cold backup and hot backup (in case of Oracle)?
Cold Backup:
It is copying the three sets of files (database files, redo logs, and control file) when the
instance is shut down. This is a straight file copy, usually from the disk directly to tape. You must shut down
the instance to guarantee a consistent copy.
If a cold backup is performed, the only option available in the event of data file loss is
restoring all the files from the latest backup. All work performed on the database since the last backup is lost.
Hot Backup:
Some sites (such as worldwide airline reservations systems) cannot shut down the
database while making a backup copy of the files. The cold backup is not an available option.
So different means of backing up database must be used — the hot backup. Issue a SQL
command to indicate to Oracle, on a tablespace-by-tablespace basis, that the files of the tablespace are to
backed up. The users can continue to make full use of the files, including making changes to the data. Once
the user has indicated that he/she wants to back up the tablespace files, he/she can use the operating system to
copy those files to the desired backup destination.
The database must be running in ARCHIVELOG mode for the hot backup option.
If a data loss failure does occur, the lost database files can be restored using the hot
backup and the online and offline redo logs created since the backup was done. The database is restored to
the most consistent state without any loss of committed transactions.

103. What are Armstrong rules? How do we say that they are complete and/or sound
The well-known inference rules for FDs
Reflexive rule :
If Y is subset or equal to X then X Y.
Augmentation rule:
If X Y then XZ YZ.
Transitive rule:
If {X Y, Y Z} then X Z.
Decomposition rule :
If X YZ then X Y.
Union or Additive rule:
If {X Y, X Z} then X YZ.
Pseudo Transitive rule :
If {X Y, WY Z} then WX Z.
Of these the first three are known as Amstrong Rules. They are sound because it is enough if a set of
FDs satisfy these three. They are called complete because using these three rules we can generate the rest all
inference rules.

104. How can you find the minimal key of relational schema?

Ramesh 15 Ramesh
DBMS Questions
Minimal key is one which can identify each tuple of the given relation schema uniquely. For finding
the minimal key it is required to find the closure that is the set of all attributes that are dependent on any
given set of attributes under the given set of functional dependency.
Algo. I Determining X+, closure for X, given set of FDs F
1. Set X+ = X
2. Set Old X+ = X+
3. For each FD Y Z in F and if Y belongs to X+ then add Z to X+
4. Repeat steps 2 and 3 until Old X+ = X+

Algo.II Determining minimal K for relation schema R, given set of FDs F


1. Set K to R that is make K a set of all attributes in R
2. For each attribute A in K
a. Compute (K – A)+ with respect to F
b. If (K – A)+ = R then set K = (K – A)+

105. What do you understand by dependency preservation?


Given a relation R and a set of FDs F, dependency preservation states that the closure of the
union of the projection of F on each decomposed relation Ri is equal to the closure of F. i.e.,
((ΠR1(F)) U … U (ΠRn(F)))+ = F+
if decomposition is not dependency preserving, then some dependency is lost in the decomposition.

106. What is meant by Proactive, Retroactive and Simultaneous Update.


Proactive Update:
The updates that are applied to database before it becomes effective in real world .
Retroactive Update:
The updates that are applied to database after it becomes effective in real world .
Simulatneous Update:
The updates that are applied to database at the same time when it becomes effective in
real world .

107. What are the different types of JOIN operations?


Equi Join: This is the most common type of join which involves only equality comparisions.

Ramesh 16 Ramesh
DBMS Questions

SQL
1. Which is the subset of SQL commands used to manipulate Oracle Database structures, including tables?
Data Definition Language (DDL)

2. What operator performs pattern matching?


LIKE operator

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

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?

Ramesh 17 Ramesh
DBMS Questions
USER_CONSTRAINTS

14. TRUNCATE TABLE EMP;


DELETE FROM EMP;
Will the outputs of the above two commands differ?
Both will result in deleting all the rows in the table EMP.

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


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.

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 will be the output of the following query?


SELECT DECODE(TRANSLATE('A','1234567890','1111111111'), '1','YES', 'NO' );
Answer :
NO
Explanation :
The query checks whether a given string is a numerical digit.

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

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

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

22. What is the advantage of specifying WITH GRANT OPTION in the GRANT command?

Ramesh 18 Ramesh
DBMS Questions
The privilege receiver can further grant the privileges he/she has obtained from the owner to any
other user.

23. What is the use of the DROP option in the ALTER TABLE command?
It is used to drop constraints specified on the table.

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

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

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

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

28. What is the output of the following query?


SELECT TRUNC(1234.5678,-2) FROM DUAL;
1200

Ramesh 19 Ramesh
DBMS Questions
SQL – QUERIES

I. SCHEMAS

Table 1 : STUDIES

PNAME (VARCHAR), SPLACE (VARCHAR), COURSE (VARCHAR), CCOST (NUMBER)

Table 2 : SOFTWARE

PNAME (VARCHAR), TITLE (VARCHAR), DEVIN (VARCHAR), SCOST (NUMBER), DCOST


(NUMBER), SOLD (NUMBER)

Table 3 : PROGRAMMER

PNAME (VARCHAR), DOB (DATE), DOJ (DATE), SEX (CHAR), PROF1 (VARCHAR), PROF2
(VARCHAR), SAL (NUMBER)

LEGEND :

PNAME – Programmer Name, SPLACE – Study Place, CCOST – Course Cost, DEVIN – Developed in,
SCOST – Software Cost, DCOST – Development Cost, PROF1 – Proficiency 1

QUERIES :

1. Find out the selling cost average for packages developed in Oracle.
2. Display the names, ages and experience of all programmers.
3. Display the names of those who have done the PGDCA course.
4. What is the highest number of copies sold by a package?
5. Display the names and date of birth of all programmers born in April.
6. Display the lowest course fee.
7. How many programmers have done the DCA course.
8. How much revenue has been earned through the sale of packages developed in C.
9. Display the details of software developed by Rakesh.
10. How many programmers studied at Pentafour.
11. Display the details of packages whose sales crossed the 5000 mark.
12. Find out the number of copies which should be sold in order to recover the development cost of each
package.
13. Display the details of packages for which the development cost has been recovered.
14. What is the price of costliest software developed in VB?
15. How many packages were developed in Oracle ?
16. How many programmers studied at PRAGATHI?
17. How many programmers paid 10000 to 15000 for the course?
18. What is the average course fee?
19. Display the details of programmers knowing C.
20. How many programmers know either C or Pascal?
21. How many programmers don’t know C and C++?
22. How old is the oldest male programmer?

Ramesh 20 Ramesh
DBMS Questions
23. What is the average age of female programmers?
24. Calculate the experience in years for each programmer and display along with their names in
descending order.
25. Who are the programmers who celebrate their birthdays during the current month?
26. How many female programmers are there?
27. What are the languages known by the male programmers?
28. What is the average salary?
29. How many people draw 5000 to 7500?
30. Display the details of those who don’t know C, C++ or Pascal.
31. Display the costliest package developed by each programmer.
32. Produce the following output for all the male programmers
Programmer
Mr. Arvind – has 15 years of experience

Ramesh 21 Ramesh
DBMS Questions

KEYS:

1. SELECT AVG(SCOST) FROM SOFTWARE WHERE DEVIN = 'ORACLE';


2. SELECT PNAME,TRUNC(MONTHS_BETWEEN(SYSDATE,DOB)/12) "AGE",
TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12) "EXPERIENCE" FROM PROGRAMMER;
3. SELECT PNAME FROM STUDIES WHERE COURSE = 'PGDCA';
4. SELECT MAX(SOLD) FROM SOFTWARE;
5. SELECT PNAME, DOB FROM PROGRAMMER WHERE DOB LIKE '%APR%';
6. SELECT MIN(CCOST) FROM STUDIES;
7. SELECT COUNT(*) FROM STUDIES WHERE COURSE = 'DCA';
8. SELECT SUM(SCOST*SOLD-DCOST) FROM SOFTWARE GROUP BY DEVIN HAVING
DEVIN = 'C';
9. SELECT * FROM SOFTWARE WHERE PNAME = 'RAKESH';
10. SELECT * FROM STUDIES WHERE SPLACE = 'PENTAFOUR';
11. SELECT * FROM SOFTWARE WHERE SCOST*SOLD-DCOST > 5000;
12. SELECT CEIL(DCOST/SCOST) FROM SOFTWARE;
13. SELECT * FROM SOFTWARE WHERE SCOST*SOLD >= DCOST;
14. SELECT MAX(SCOST) FROM SOFTWARE GROUP BY DEVIN HAVING DEVIN = 'VB';
15. SELECT COUNT(*) FROM SOFTWARE WHERE DEVIN = 'ORACLE';
16. SELECT COUNT(*) FROM STUDIES WHERE SPLACE = 'PRAGATHI';
17. SELECT COUNT(*) FROM STUDIES WHERE CCOST BETWEEN 10000 AND 15000;
18. SELECT AVG(CCOST) FROM STUDIES;
19. SELECT * FROM PROGRAMMER WHERE PROF1 = 'C' OR PROF2 = 'C';
20. SELECT * FROM PROGRAMMER WHERE PROF1 IN ('C','PASCAL') OR PROF2 IN
('C','PASCAL');
21. SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN ('C','C++') AND PROF2 NOT IN
('C','C++');
22. SELECT TRUNC(MAX(MONTHS_BETWEEN(SYSDATE,DOB)/12)) FROM PROGRAMMER
WHERE SEX = 'M';
23. SELECT TRUNC(AVG(MONTHS_BETWEEN(SYSDATE,DOB)/12)) FROM PROGRAMMER
WHERE SEX = 'F';
24. SELECT PNAME, TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12) FROM PROGRAMMER
ORDER BY PNAME DESC;
25. SELECT PNAME FROM PROGRAMMER WHERE TO_CHAR(DOB,'MON') =
TO_CHAR(SYSDATE,'MON');
26. SELECT COUNT(*) FROM PROGRAMMER WHERE SEX = 'F';
27. SELECT DISTINCT(PROF1) FROM PROGRAMMER WHERE SEX = 'M';
28. SELECT AVG(SAL) FROM PROGRAMMER;
29. SELECT COUNT(*) FROM PROGRAMMER WHERE SAL BETWEEN 5000 AND 7500;
30. SELECT * FROM PROGRAMMER WHERE PROF1 NOT IN ('C','C++','PASCAL') AND PROF2
NOT IN ('C','C++','PASCAL');
31. SELECT PNAME,TITLE,SCOST FROM SOFTWARE WHERE SCOST IN (SELECT
MAX(SCOST) FROM SOFTWARE GROUP BY PNAME);
32.SELECT 'Mr.' || PNAME || ' - has ' || TRUNC(MONTHS_BETWEEN(SYSDATE,DOJ)/12) || ' years
of experience' “Programmer” FROM PROGRAMMER WHERE SEX = 'M' UNION SELECT 'Ms.' ||
PNAME || ' - has ' || TRUNC (MONTHS_BETWEEN (SYSDATE,DOJ)/12) || ' years of experience'
“Programmer” FROM PROGRAMMER WHERE SEX = 'F';

Ramesh 22 Ramesh
DBMS Questions

II . SCHEMA :
Table 1 : DEPT

DEPTNO (NOT NULL , NUMBER(2)), DNAME (VARCHAR2(14)),


LOC (VARCHAR2(13)

Table 2 : EMP

EMPNO (NOT NULL , NUMBER(4)), ENAME (VARCHAR2(10)),


JOB (VARCHAR2(9)), MGR (NUMBER(4)), HIREDATE (DATE),
SAL (NUMBER(7,2)), COMM (NUMBER(7,2)), DEPTNO (NUMBER(2))

MGR is the empno of the employee whom the employee reports to. DEPTNO is a foreign key.
QUERIES

1. List all the employees who have at least one person reporting to them.
2. List the employee details if and only if more than 10 employees are present in department no 10.
3. List the name of the employees with their immediate higher authority.
4. List all the employees who do not manage any one.
5. List the employee details whose salary is greater than the lowest salary of an employee belonging to
deptno 20.
6. List the details of the employee earning more than the highest paid manager.
7. List the highest salary paid for each job.
8. Find the most recently hired employee in each department.
9. In which year did most people join the company? Display the year and the number of employees.
10. Which department has the highest annual remuneration bill?
11. Write a query to display a ‘*’ against the row of the most recently hired employee.
12. Write a correlated sub-query to list out the employees who earn more than the average salary of their
department.
13. Find the nth maximum salary.
14. Select the duplicate records (Records, which are inserted, that already exist) in the EMP table.
15. Write a query to list the length of service of the employees (of the form n years and m months).

Ramesh 23 Ramesh
DBMS Questions
KEYS:

1. SELECT DISTINCT(A.ENAME) FROM EMP A, EMP B WHERE A.EMPNO = B.MGR; or SELECT


ENAME FROM EMP WHERE EMPNO IN (SELECT MGR FROM EMP);
2. SELECT * FROM EMP WHERE DEPTNO IN (SELECT DEPTNO FROM EMP GROUP BY
DEPTNO HAVING COUNT(EMPNO)>10 AND DEPTNO=10);
3. SELECT A.ENAME "EMPLOYEE", B.ENAME "REPORTS TO" FROM EMP A, EMP B WHERE
A.MGR=B.EMPNO;
4. SELECT * FROM EMP WHERE EMPNO IN ( SELECT EMPNO FROM EMP MINUS SELECT MGR
FROM EMP);
5. SELECT * FROM EMP WHERE SAL > ( SELECT MIN(SAL) FROM EMP GROUP BY DEPTNO
HAVING DEPTNO=20);
6. SELECT * FROM EMP WHERE SAL > ( SELECT MAX(SAL) FROM EMP GROUP BY JOB
HAVING JOB = 'MANAGER' );
7. SELECT JOB, MAX(SAL) FROM EMP GROUP BY JOB;
8. SELECT * FROM EMP WHERE (DEPTNO, HIREDATE) IN (SELECT DEPTNO, MAX(HIREDATE)
FROM EMP GROUP BY DEPTNO);
9. SELECT TO_CHAR(HIREDATE,'YYYY') "YEAR", COUNT(EMPNO) "NO. OF EMPLOYEES"
FROM EMP GROUP BY TO_CHAR(HIREDATE,'YYYY') HAVING COUNT(EMPNO) = (SELECT
MAX(COUNT(EMPNO)) FROM EMP GROUP BY TO_CHAR(HIREDATE,'YYYY'));
10. SELECT DEPTNO, LPAD(SUM(12*(SAL+NVL(COMM,0))),15) "COMPENSATION" FROM EMP
GROUP BY DEPTNO HAVING SUM( 12*(SAL+NVL(COMM,0))) = (SELECT
MAX(SUM(12*(SAL+NVL(COMM,0)))) FROM EMP GROUP BY DEPTNO);
11. SELECT ENAME, HIREDATE, LPAD('*',8) "RECENTLY HIRED" FROM EMP WHERE
HIREDATE = (SELECT MAX(HIREDATE) FROM EMP) UNION SELECT ENAME NAME,
HIREDATE, LPAD(' ',15) "RECENTLY HIRED" FROM EMP WHERE HIREDATE != (SELECT
MAX(HIREDATE) FROM EMP);
12. SELECT ENAME,SAL FROM EMP E WHERE SAL > (SELECT AVG(SAL) FROM EMP F WHERE
E.DEPTNO = F.DEPTNO);
13. SELECT ENAME, SAL FROM EMP A WHERE &N = (SELECT COUNT (DISTINCT(SAL)) FROM
EMP B WHERE A.SAL<=B.SAL);
14. SELECT * FROM EMP A WHERE A.EMPNO IN (SELECT EMPNO FROM EMP GROUP BY
EMPNO HAVING COUNT(EMPNO)>1) AND A.ROWID!=MIN (ROWID));
15. SELECT ENAME
"EMPLOYEE",TO_CHAR(TRUNC(MONTHS_BETWEEN(SYSDATE,HIREDATE)/12))||' YEARS '||
TO_CHAR(TRUNC(MOD(MONTHS_BETWEEN (SYSDATE, HIREDATE),12)))||' MONTHS '
"LENGTH OF SERVICE" FROM EMP;

Ramesh 24 Ramesh
DBMS Questions
Index Search Add FAQ Ask Question

Oracle PL/SQL FAQ


$Date: 17-Dec-2002 $
$Revision: 2.05 $
$Author: Frank Naudé $
Topics
• What is PL/SQL and what is it used for?
• Should one use PL/SQL or Java to code procedures and triggers?
• How can one see if somebody modified any code?
• How can one search PL/SQL code for a string/key value?
• How can one keep a history of PL/SQL code changes?
• How can I protect my PL/SQL source code?
• Can one print to the screen from PL/SQL?
• Can one read/write files from PL/SQL?
• Can one call DDL statements from PL/SQL?
• Can one use dynamic SQL statements from PL/SQL?
• What is the difference between %TYPE and %ROWTYPE?
• What is the result of comparing NULL with NULL?
• How does one get the value of a sequence into a PL/SQL variable?
• Can one execute an operating system command from PL/SQL?
• How does one loop through tables in PL/SQL?
• How often should one COMMIT in a PL/SQL loop? / What is the best commit strategy?
• I can SELECT from SQL*Plus but not from PL/SQL. What is wrong?
• What is a mutating and constraining table?
• Can one pass an object/table as an argument to a remote procedure?
• Is it better to put code in triggers or procedures? What is the difference?
• Is there a PL/SQL Engine in SQL*Plus?
• Is there a limit on the size of a PL/SQL block?
• Where can one find more info about PL/SQL?

Back to Oracle FAQ Index

What is PL/SQL and what is it used for?


PL/SQL is Oracle's Procedural Language extension to SQL. PL/SQL's language syntax, structure and data types are similar to
that of ADA. The PL/SQL language includes object oriented programming techniques such as encapsulation, function overloading,
information hiding (all but inheritance). PL/SQL is commonly used to write data-centric programs to manipulate data in an Oracle
database.
• Back to top of file

Should one use PL/SQL or Java to code procedures and triggers?


Internally the Oracle database supports two procedural languages, namely PL/SQL and Java. This leads to questions like "Which
of the two is the best?" and "Will Oracle ever desupport PL/SQL in favour of Java?".
Many Oracle applications are based on PL/SQL and it would be difficult of Oracle to ever desupport PL/SQL. In fact, all
indications are that PL/SQL still has a bright future ahead of it. Many enhancements are still being made to PL/SQL. For example,
Oracle 9iDB supports native compilation of Pl/SQL code to binaries.

Ramesh 25 Ramesh
DBMS Questions
PL/SQL and Java appeal to different people in different job roles. The following table briefly describes the difference between
these two language environments:

PL/SQL:
• Data centric and tightly integrated into the database
• Proprietary to Oracle and difficult to port to other database systems
• Data manipulation is slightly faster in PL/SQL than in Java
• Easier to use than Java (depending on your background)
Java:
• Open standard, not proprietary to Oracle
• Incurs some data conversion overhead between the Database and Java type systems
• Java is more difficult to use (depending on your background)
• Back to top of file

How can one see if somebody modified any code?


Code for stored procedures, functions and packages is stored in the Oracle Data Dictionary. One can detect code changes by
looking at the LAST_DDL_TIME column in the USER_OBJECTS dictionary view. Example:
SELECT OBJECT_NAME,
TO_CHAR(CREATED, 'DD-Mon-RR HH24:MI') CREATE_TIME,
TO_CHAR(LAST_DDL_TIME, 'DD-Mon-RR HH24:MI') MOD_TIME,
STATUS
FROM USER_OBJECTS
WHERE LAST_DDL_TIME > '&CHECK_FROM_DATE';
• Back to top of file

How can one search PL/SQL code for a string/ key value?
The following query is handy if you want to know where a certain table, field or expression is referenced in your PL/SQL source
code.
SELECT TYPE, NAME, LINE
FROM USER_SOURCE
WHERE UPPER(TEXT) LIKE '%&KEYWORD%';
• Back to top of file

How can one keep a history of PL/SQL code changes?


One can build a history of PL/SQL code changes by setting up an AFTER CREATE schema (or database) level trigger (available
from Oracle 8.1.7). This way one can easily revert to previous code should someone make any catastrophic changes. Look at this
example:
CREATE TABLE SOURCE_HIST -- Create history table
AS SELECT SYSDATE CHANGE_DATE, USER_SOURCE.*
FROM USER_SOURCE WHERE 1=2;

CREATE OR REPLACE TRIGGER change_hist -- Store code in hist table


AFTER CREATE ON SCOTT.SCHEMA -- Change SCOTT to your schema
name
DECLARE
BEGIN
if DICTIONARY_OBJ_TYPE in ('PROCEDURE', 'FUNCTION',
'PACKAGE', 'PACKAGE BODY', 'TYPE') then
-- Store old code in SOURCE_HIST table
INSERT INTO SOURCE_HIST
SELECT sysdate, user_source.* FROM USER_SOURCE
WHERE TYPE = DICTIONARY_OBJ_TYPE
AND NAME = DICTIONARY_OBJ_NAME;
end if;
EXCEPTION

Ramesh 26 Ramesh
DBMS Questions
WHEN OTHERS THEN
raise_application_error(-20000, SQLERRM);
END;
/
show errors
• Back to top of file

How can I protect my PL/SQL source code?


PL/SQL V2.2, available with Oracle7.2, implements a binary wrapper for PL/SQL programs to protect the source code.
This is done via a standalone utility that transforms the PL/SQL source code into portable binary object code (somewhat larger
than the original). This way you can distribute software without having to worry about exposing your proprietary algorithms and
methods. SQL*Plus and SQL*DBA will still understand and know how to execute such scripts. Just be careful, there is no
"decode" command available.

The syntax is:


wrap iname=myscript.sql oname=xxxx.plb
• Back to top of file

Can one print to the screen from PL/SQL?


One can use the DBMS_OUTPUT package to write information to an output buffer. This buffer can be displayed on the screen
from SQL*Plus if you issue the SET SERVEROUTPUT ON; command. For example:
set serveroutput on
begin
dbms_output.put_line('Look Ma, I can print from PL/SQL!!!');
end;
/
DBMS_OUTPUT is useful for debugging PL/SQL programs. However, if you print too much, the output buffer will overflow. In
that case, set the buffer size to a larger value, eg.: set serveroutput on size 200000

If you forget to set serveroutput on type SET SERVEROUTPUT ON once you remember, and then EXEC NULL;. If you haven't
cleared the DBMS_OUTPUT buffer with the disable or enable procedure, SQL*Plus will display the entire contents of the buffer
when it executes this dummy PL/SQL block.
• Back to top of file

Can one read/write files from PL/SQL?


Included in Oracle 7.3 is an UTL_FILE package that can read and write operating system files. The directory you intend writing to
has to be in your INIT.ORA file (see UTL_FILE_DIR=... parameter). Before Oracle 7.3 the only means of writing a file was to use
DBMS_OUTPUT with the SQL*Plus SPOOL command.
Copy this example to get started:
DECLARE
fileHandler UTL_FILE.FILE_TYPE;
BEGIN
fileHandler := UTL_FILE.FOPEN('/tmp', 'myfile', 'w');
UTL_FILE.PUTF(fileHandler, 'Look ma, I''m writing to a file!!!\n');
UTL_FILE.FCLOSE(fileHandler);
EXCEPTION
WHEN utl_file.invalid_path THEN
raise_application_error(-20000, 'ERROR: Invalid path for file or path not
in INIT.ORA.');
END;
/
• Back to top of file

Ramesh 27 Ramesh
DBMS Questions
Can one call DDL statements from PL/SQL?
One can call DDL statements like CREATE, DROP, TRUNCATE, etc. from PL/SQL by using the "EXECUTE IMMEDATE"
statement. Users running Oracle versions below 8i can look at the DBMS_SQL package (see FAQ about Dynamic SQL).
begin
EXECUTE IMMEDIATE 'CREATE TABLE X(A DATE)';
end;
NOTE: The DDL statement in quotes should not be terminated with a semicolon.
• Back to top of file

Can one use dynamic SQL statements from PL/SQL?


Starting from Oracle8i one can use the "EXECUTE IMMEDIATE" statement to execute dynamic SQL and PL/SQL statements
(statements created at run-time). Look at these examples. Note that statements are NOT terminated by semicolons:
EXECUTE IMMEDIATE 'CREATE TABLE x (a NUMBER)';

-- Using bind variables...


sql_stmt := 'INSERT INTO dept VALUES (:1, :2, :3)';
EXECUTE IMMEDIATE sql_stmt USING dept_id, dept_name, location;

-- Returning a cursor...
sql_stmt := 'SELECT * FROM emp WHERE empno = :id';
EXECUTE IMMEDIATE sql_stmt INTO emp_rec USING emp_id;
One can also use the older DBMS_SQL package (V2.1 and above) to execute dynamic statements. Look at these examples:
CREATE OR REPLACE PROCEDURE DYNSQL AS
cur integer;
rc integer;
BEGIN
cur := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cur, 'CREATE TABLE X (Y DATE)', DBMS_SQL.NATIVE);
rc := DBMS_SQL.EXECUTE(cur);
DBMS_SQL.CLOSE_CURSOR(cur);
END;
/
More complex DBMS_SQL example using bind variables:
CREATE OR REPLACE PROCEDURE DEPARTMENTS(NO IN DEPT.DEPTNO%TYPE) AS
v_cursor integer;
v_dname char(20);
v_rows integer;
BEGIN
v_cursor := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(v_cursor, 'select dname from dept where deptno > :x',
DBMS_SQL.V7);
DBMS_SQL.BIND_VARIABLE(v_cursor, ':x', no);
DBMS_SQL.DEFINE_COLUMN_CHAR(v_cursor, 1, v_dname, 20);
v_rows := DBMS_SQL.EXECUTE(v_cursor);
loop
if DBMS_SQL.FETCH_ROWS(v_cursor) = 0 then
exit;
end if;
DBMS_SQL.COLUMN_VALUE_CHAR(v_cursor, 1, v_dname);
DBMS_OUTPUT.PUT_LINE('Deptartment name: '||v_dname);
end loop;
DBMS_SQL.CLOSE_CURSOR(v_cursor);
EXCEPTION
when others then
DBMS_SQL.CLOSE_CURSOR(v_cursor);
raise_application_error(-20000, 'Unknown Exception Raised: '||sqlcode||'
'||sqlerrm);

Ramesh 28 Ramesh
DBMS Questions
END;
/
• Back to top of file

What is the difference between %TYPE and %ROWTYPE?


The %TYPE and %ROWTYPE constructs provide data independence, reduces maintenance costs, and allows programs to adapt as
the database changes to meet new business needs.
%ROWTYPE is used to declare a record with the same types as found in the specified database table, view or cursor. Example:
DECLARE
v_EmpRecord emp%ROWTYPE;
%TYPE is used to declare a field with the same type as that of a specified table's column. Example:
DECLARE
v_EmpNo emp.empno%TYPE;
• Back to top of file

What is the result of comparing NULL with NULL?


NULL is neither equal to NULL, nor it is not equal to NULL. Any comparison to NULL is evaluated to NULL. Look at this code
example to convince yourself.
declare
a number := NULL;
b number := NULL;
begin
if a=b then
dbms_output.put_line('True, NULL = NULL');
elsif a<>b then
dbms_output.put_line('False, NULL <> NULL');
else
dbms_output.put_line('Undefined NULL is neither = nor <> to NULL');
end if;
end;
• Back to top of file

How does one get the value of a sequence into a PL/SQL variable?
As you might know, one cannot use sequences directly from PL/SQL. Oracle (for some silly reason) prohibits this:
i := sq_sequence.NEXTVAL;
However, one can use embedded SQL statements to obtain sequence values:
select sq_sequence.NEXTVAL into :i from dual;
Thanks to Ronald van Woensel

• Back to top of file

Can one execute an operating system command from PL/SQL?


There is no direct way to execute operating system commands from PL/SQL in Oracle7. However, one can write an external
program (using one of the precompiler languages, OCI or Perl with Oracle access modules) to act as a listener on a database pipe
(SYS.DBMS_PIPE). Your PL/SQL program then put requests to run commands in the pipe, the listener picks it up and run the
requests. Results are passed back on a different database pipe. For an Pro*C example, see chapter 8 of the Oracle Application
Developers Guide.
In Oracle8 one can call external 3GL code in a dynamically linked library (DLL or shared object). One just write a library in C/
C++ to do whatever is required. Defining this C/C++ function to PL/SQL makes it executable. Look at this External Procedure
example.
• Back to top of file

Ramesh 29 Ramesh
DBMS Questions
How does one loop through tables in PL/SQL?
Look at the following nested loop code example.
DECLARE
CURSOR dept_cur IS
SELECT deptno
FROM dept
ORDER BY deptno;
-- Employee cursor all employees for a dept number
CURSOR emp_cur (v_dept_no DEPT.DEPTNO%TYPE) IS
SELECT ename
FROM emp
WHERE deptno = v_dept_no;
BEGIN
FOR dept_rec IN dept_cur LOOP
dbms_output.put_line('Employees in Department
'||TO_CHAR(dept_rec.deptno));
FOR emp_rec in emp_cur(dept_rec.deptno) LOOP
dbms_output.put_line('...Employee is '||emp_rec.ename);
END LOOP;
END LOOP;
END;
/
• Back to top of file

How often should one COMMIT in a PL/SQL loop? / What is the best commit
strategy?
Contrary to popular believe, one should COMMIT less frequently within a PL/SQL loop to prevent ORA-1555 (Snapshot too
old) errors. The higher the frequency of commit, the sooner the extents in the rollback segments will be cleared for new
transactions, causing ORA-1555 errors.
To fix this problem one can easily rewrite code like this:
FOR records IN my_cursor LOOP
...do some stuff...
COMMIT;
END LOOP;
... to ...
FOR records IN my_cursor LOOP
...do some stuff...
i := i+1;
IF mod(i, 10000) THEN -- Commit every 10000 records
COMMIT;
END IF;
END LOOP;
If you still get ORA-1555 errors, contact your DBA to increase the rollback segments.
NOTE: Although fetching across COMMITs work with Oracle, is not supported by the ANSI standard.
• Back to top of file

I can SELECT from SQL*Plus but not from PL/SQL. What is wrong?
PL/SQL respect object privileges given directly to the user, but does not observe privileges given through roles. The consequence
is that a SQL statement can work in SQL*Plus, but will give an error in PL/SQL. Choose one of the following solutions:
• Grant direct access on the tables to your user. Do not use roles!
• GRANT select ON scott.emp TO my_user;

• Define your procedures with invoker rights (Oracle 8i and higher);

Ramesh 30 Ramesh
DBMS Questions
• Move all the tables to one user/schema.
• Back to top of file

What is a mutating and constraining table?


"Mutating" means "changing". A mutating table is a table that is currently being modified by an update, delete, or insert statement.
When a trigger tries to reference a table that is in state of flux (being changed), it is considered "mutating" and raises an error since
Oracle should not return data that has not yet reached its final state.
Another way this error can occur is if the trigger has statements to change the primary, foreign or unique key columns of the table
off which it fires. If you must have triggers on tables that have referential constraints, the workaround is to enforce the referential
integrity through triggers as well.

There are several restrictions in Oracle regarding triggers:

• A row-level trigger cannot query or modify a mutating table. (Of course, NEW and OLD still can be accessed by the
trigger) .

• A statement-level trigger cannot query or modify a mutating table if the trigger is fired as the result of a CASCADE
delete.

• Etc.
• Back to top of file

Can one pass an object/table as an argument to a remote procedure?


The only way the same object type can be referenced between two databases is via a database link. Note that it is not enough to just
use the same type definitions. Look at this example:
-- Database A: receives a PL/SQL table from database B
CREATE OR REPLACE PROCEDURE pcalled(TabX DBMS_SQL.VARCHAR2S) IS
BEGIN
-- do something with TabX from database B
null;
END;
/

-- Database B: sends a PL/SQL table to database A


CREATE OR REPLACE PROCEDURE pcalling IS
TabX DBMS_SQL.VARCHAR2S@DBLINK2;
BEGIN
pcalled@DBLINK2(TabX);
END;
/
• Back to top of file

Is it better to put code in triggers or procedures? What is the difference?


In earlier releases of Oracle it was better to put as much code as possible in procedures rather than triggers. At that stage
procedures executed faster than triggers as triggers had to be re-compiled every time before executed (unless cached). In more
recent releases both triggers and procedures are compiled when created (stored p-code) and one can add as much code as one likes
in either procedures or triggers.
• Back to top of file

Is there a PL/SQL Engine in SQL*Plus?


No. Unlike Oracle Forms, SQL*Plus does not have an embedded PL/SQL engine. Thus, all your PL/SQL code is sent directly to
the database engine for execution. This makes it much more efficient as SQL statements are not stripped off and sent to the
database individually.
• Back to top of file

Ramesh 31 Ramesh
DBMS Questions

Is there a limit on the size of a PL/SQL block?


Yes, the max size is not an explicit byte limit, but related to the parse tree that is created when you compile the code. You can run
the following select statement to query the size of an existing package or procedure:
SQL> select * from dba_object_size where name = 'procedure_name';
• Back to top of file

Where can one find more info about PL/SQL?


• Oracle FAQ: PL/SQL code examples

• Oracle FAQ: PL/SQL Books

• PLNet.org - An open source repository for PL/SQL developers

• RevealNet PL/SQL Pipeline - A free community for Oracle developers worldwide

• The PL/SQL Cellar - Free Oracle PL/SQL scripts including a bitwise operations package and message digest algorithms

• PLSolutions.com - PL/Solutions provides consulting and training services for the Oracle PL/SQL language and PL/Vision

Ramesh 32 Ramesh
DBMS Questions
How to change UserID and Password in Oracle.
what are differenct types of joins. explain outer join.
How to print output in Oracle.
what is a data control component.
why do we use DBMS ?
what are logical objects in RDBMS (tables & views).
what do you know about IDL?
can we maintain mirror data in different databases.
Data Integrity constraint is
(a)to ensure the presence of primary key
What is indexing in databases?
What is atomicity?

What is DBMS and RDBMS ?

types of DBMS,queries

Difference between Unique and primary

what is a cursor

types of cursors

normalization

normal forms

whis is the best normal form

what is an os

what exactly os consists ?

Types of joins ?

what is a trigger ?

can we create a table in oracle which is not in first normal


form
difference between dbms and rdbms
sql queries
types of indexing

Ramesh 33 Ramesh
DBMS Questions

DML,DDL, SQL querry,primary key, whts a null

diff btw DDL,DML, whts parallel DML,

whts normalisation explain with example till 3NF


6>need for normalisation

differnce btw oracle 8.0,8i,9i


what are pseudocolumns? given example.
(CURRVAl,LEVEL,NEXTVAL,ROWID,ROWNUM)
what are synonyms ? example.
( an alias name to the table , which is used for location
transperancy.)

CREATE SYNONYM emp2 FOR emp@newyork;

SELECT ename, job INTO my_ename, my_job


FROM emp2
WHERE empno = my_empno;

what are snapshots.


what is indexing. what are its advantages.
what is cluster. advantages.
how do you add primary key to the table already existing.
what is table space.
what partitioning. how many types of partitions.
what is mutating table.
When a table is in state of transition it is said to be
mutating.
eg :: If a row has been deleted then the table is said to be
mutating and no operations can be done on the table except
select.

what is the keyword type.


what is 'exists'.
what is a cursor. what are the types.

two types of cursors: implicit and explicit. PL/SQL declares a


cursor implicitly for all
SQL data manipulation statements, including queries that
return only one row. However,

Ramesh 34 Ramesh
DBMS Questions
for queries that return more than one row, you must declare an
explicit cursor or use
a cursor FOR loop.

three commands to control the cursor: OPEN, FETCH, and CLOSE.

initialize the cursor with the OPEN statement, which


identifies the active set.

Then, you use the FETCH statement to retrieve the first row.
You can execute FETCH repeatedly until all rows have been
retrieved.

release the cursor with the CLOSE statement.

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;

four attributes of cursor : %NOTFOUND, %FOUND, %ROWCOUNT, and


%ISOPEN

what is SGA.

The SGA is a shared memory region allocated by the Oracle that


contains Data and control information for one Oracle Instance.
It consists of Database Buffer Cache and Redo log Buffer.

how do you override function/procedures in oracle.


what is raise_application_error.
what are datafiles.
what are the default table spaces.

Ramesh 35 Ramesh
DBMS Questions
what are the background processes in oracle.
what are control files.
what are the minimum privilege for the user to connect
database.
what is a role. why do you create it.
Software Engineering
~~~~~~~~~~~~~~~~~~~~
what is waterfall model, prototype model etc.
what is testing. what is unit testing, integration testing
etc.
what are the stages in software project.
(study,analysis,design,development,testing,implementation)
what is done in each stage of the SDLC.
what is the output of analysis stage.

what is er-model.
how do you compare an entity with class or object.
how do you design a project.

Procedure of any model

testing procedure of software

Models-Spiral, Prototyping, Estimation models

Software Configuration Management process is -

Capability Maturity Model( 5 stages)

Flow chart details

Software Development Life Cycle


where is development ?

Why do we go for Testing ?

Types of Testing ?

Software Life Cycle ?

what is testing

Ramesh 36 Ramesh
DBMS Questions
Funtional point model

difference between black box and white box

what is quality and various quality certifications

what is spiral lifecycle model

Cohesion and coupling

Ramesh 37 Ramesh
DBMS Questions

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

Relational Database Management system


A Relational Database Management System (RDBMS) can perform a wide range of
tasks. It acts as a transparent interface between the physical storage and the logical presentation of data.It
provides a set of more or less flexible and sofesticated tools for handling information.
Users can use the tools to
• Define a Database
• Query the Database
• Add,Edit and Delete data.
• Modify the structure of the Database.
• Communicate with in the Networks.
• Exports and Imports the data.
• Security.

Oracle the Right Tool


To keep track of records is often the best reason to consider
buying a software package.Choosing a proven product increase the chance that we will get a
system capable of meeting all our needs .Oracle has had many years in the relational market
to often on the large,Complex applications. Although Oracle demands greater expertise on

Ramesh 38 Ramesh
DBMS Questions
the part of the application developed,an application developed oracle will be able to keep
pace with growth and change in the world at large.
Oracle Gives You Security and Control
Oracle has several features that ensure the integrity of the data base. If an interruption occurs in
processing, a Rollback can reset the database to a point before the disaster. If a restore is necessary, Oracle
has a Roll forward command for recreating your database to its mast resent save point.
Oracle provides user with several functions for securing data. Grant and Revoke commands limit
access to information down to the row and column levels. Views are valuable feature for limiting access to
the primary tables in the database.

The Oracle Environment


Oracle is a modular system that consists of the Oracle database and several functional
programs. Oracle’s tools do four major things of work.
1. Database Management.
2. Data access and Manipulation.
3. Programming
4. Connectivity.

Database Management Tools


This (is usually known as RDBMS by oracle) includes the core programs for Oracle’s database
management system, the Oracle database with its associated tables and views, which are stores information
related to every fact of the database system.User name, user access rights, table attribute, storage information
and auditing data for disaster recovery are stored in the data dictionary.

The Database Administrator


The person responsible for a Database is called the DatabaseAdministrator(DBA).The DBA has a
special set of previleges and has complete over the database.Any system with more than one user should
have a DBA.The function of DBA include.
Creating primary database storage structures.
Modifying the structure of the database.
Backing up and restoring the database.
Monitoring database performance and efficiency.
Transfering data between database and external files.
Manipulating the phisical location of the database.

THE END USER


End user have less complex but equally important tasks.They must be able to
• Query the database.
• Generate printed output.
• Share data with or secure data from others.
• Use non-export methods to update the database.
• Define applications from a user point of view.

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.

Ramesh 39 Ramesh
DBMS Questions
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.

Structure of Oracle Database:

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.

Ramesh 40 Ramesh
DBMS Questions
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.)

Normalization is carried out for four reasons:


• To Structure the data so that any pertinent relationships between entities can be represented.
• To permit simple retrieval of data in response to query and report requests.
• To simplify the maintenance of the data through updates, insertions, and deletion
• To reduce the need to restructure or reorganize data when new application requirements arise.
• Normalization can improve the quality of design for an application.

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

Ramesh 41 Ramesh
DBMS Questions
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

Rule 1: The Information Rule


All information in a relational database is represented explicitly at the logical level in exactly one way
by values in tables.
All data is represented in the form of relations/tables (with rows and columns)Simple Consistent and
versatile

Rule 2: Guaranteed Access Rule


Each and every datum (atomic value) in a relational database is guaranteed to be logically accessible
by resorting to a table name, primary key value, and column name. All Data is uniquely identified and
accessible via this identity.

Rule 3: Systematic Treatment of Null Values


Null values (distinct from empty character string or a string of blank characters and distinct from zero
or any other number) are supported in the fully relational DBMS for representing missing information in a
systematic way, independent of data type.

Rule 4: Dynamic On-line Catalog based on the Relational Model


The database description is represented at the logical level in the same way as ordinary data, so
authorized users can apply the same relational language to its interrogation as they apply to regular data.

Rule 5: Comprehensive Data Sublanguage Rule


A relational system may support several languages and various modes of terminal use (for example,
the fill-in-blanks mode). However, there must be at least one language whose statements are expressible, per
some well-defined syntax, as character strings and whose ability to support all of the following is
comprehensible: data definition, view definition, data manipulation (interactive and by program), integrity
constraints, and transaction boundaries (begin, commit, and rollback).

Rule 6: View Updating Rule


All views that are theoretically updateable are also updateable by the system.
Views are virtual tables. They appear to behave as conventional tables except that they are built dynamically
when the query is run. This means that a view is always up to date. It is not always theoretically possible to
update views. One problem exists when a view relates to part of a table not including a candidate key. This
means that potential updates would violate the entity integrity rule.

Rule 7: High-level Insert, Update, and Delete


The capability of handling a base relation or a derived relation as a single operand applies not only to
the retrieval of data but also to the insertion, update, and deletion of data. i.e. The user should be allowed to
Delete, Update a set of tuples (rather than row by row)

Ramesh 42 Ramesh
DBMS Questions

Rule 8: Physical Data Independence


Application programs and terminal activities remain logically unimpaired whenever any changes are
made in either storage representation or access methods. i.e. Users and programs are not dependent on the
physical structure of the database.

Rule 9: Logical Data Independence


Application programs and terminal activities remain logically unimpaired when information-
preserving changes of any kind that theoretically permit unimpairment are made to the base tables. Users and
Programs are independent of the logical structure of the database, i.e. the logical structure of the data can
evolve with minimal impact on the programs.

Rule 10: Integrity Independence


Integrity constraints specific to a particular relational database must be definable in the relational data
sublanguage and storable in the catalog, not in the application programs. A minimum of the following two
integrity constraints must be supported:
1. Entity integrity: No component of a primary key is allowed to have a null value.
2. Referential integrity: For each distinct non-null foreign key value in a relational database, there must
exist a matching primary key value from the same domain.

Rule 11: Distribution Independence


A relational DBMS has distribution independence. Distribution independence implies that users
should not have to be aware of whether a database is distributed. Applications should still work in a
distributed database (DDB).

Rule 12: Nonsubversion Rule


If a relational system has a low-level (single-record-at-a-time) language, that low-level language
cannot be used to subvert or bypass the integrity rules or constraints expressed in the higher-level (multiple-
records-at-a-time) relational language.
If there is a record at a time interface (e.g. via 3GL), Security and integrity of the database must no be
violated. There should be no backdoor to bypass the security imposed by the DBMS.

On the basis of the above rules, there is no fully relational DBMS available today.

Ramesh 43 Ramesh
DBMS Questions

Questions and Answers :

What is Pseudo Colomn ?


USER, UID, SYSDATE, ROWNUM, ROWID, NULL, AND LEVEL

How to Display output in PL/SQL ?


we first set serveroutput on at SQL Prompt. and then in sql programming we specify as
dbms_output.put_line(‘hdjhd’ || ‘sakdha’);
No Displays are allowed in PL/SQL programming with select statement

Write about Commands and Keywords ?


Alter : ALTER TABLE EMP ADD ………. , MODIFY ………. ;
for a in 1..10 loop ……….. end loop;
loop exit when a<1 ……………… end loop;
while ….. loop……………..end loop;
Data Types : number, integer, varchar2, char, date, Boolean;
goto procedure name;…………..<<procedure name>>…………..
exit, rollback, commit, savepoint.
References: This keyword is used to refer two similar fields of different tables.

What are different built in functions ?


CONCATENATE, INITCAP, LENGTH, LOWER, UPPER, LPAD, RPAD, LTRIM (removes the
character specified left side of word), RTRIM, SUBSTR (displays values from specified location onwards),
TRANSLATE (for single character), REPLACE (for more than one character ),CHR ( prints character of
given ASCII value), ASCII (value of given character ).
ABS, CEIL, FLOOR, SQRT, POWER, SIGN, TRUNC, ROUND, EXP, MOD, LOG, LN,
GREATEST, LEAST, SYSDATE, ADD_MONTHS, MONTHS_BETWEEN.

what are emp.sal%type and emp%rowtype ?


First one is to assign a variable of type sal only.
Second is to assign a complete row of type emp table.

What are constraints ?


Constraint Clause : This will constrain a single column or a group of columns in a table. and are
used for maintaining integrity of the database.
Different Constraints are : candidate keys, primary keys, foreign keys, check conditions.
Can specify as a part of column definition, or at the end of the table (if more than one column).
Check Constraint : for validations to fields.
Naming Constraint (table constraints): Can name the constraint else system will name it
by default.

Different types of joins ?


Equi join : where emp.deptno = dept.deptno;
Non Equi join : where e.sal >= g.losal;
Outer join :***********e.deptno(+)=d.deptno;

Ramesh 44 Ramesh
DBMS Questions

Different types of Keys ?


Foreign Key : This is a referential integrity constraint and specifies the values of primary key in
other table. and is mentioned as :
DEPTNO number(2) REFERENCES DEPT(DEPTNO);
The clause ON DELETE CASCADE added to REFERENCES clause tells Oracle to delete the dependent
rows when we delete the row in the parent table.
Unique Key : If declared, then does not accept duplicate and also NULL values. And can have many
Unique key fields.
Primary Key : Similar to Unique key but, also maintains an index on primary key and also used to
connect two tables.

Write about cursors ?


Implicit (SQL is implicit by default ) and Explicit cursors.
EXIT WHEN C1%NOTFOUND, IF C1%FOUND THEN, IF C1%ISOPEN THEN,
FOR LOOP in CURSOR will :
1) open the cursor.
2) fetches the records from cursor one by one.
3) keeps the track of number of records in the cursor.
Super Dynamism in Cursors is obtained by passing the values as parameters( ie pass by value) ie.,
for x in c1(a,b)
Multiple Cursors : These are nothing but nested cursors………..
In Implicit Cursors there is no need of declaration of cursors, by default system will create a cursor
whenever a query is written…and the conditions are like if SQL%NOTFOUND
if SQL%ROWCOUNT > 2 will keep a count of the number of records updated.
SQL is a keyword and cannot be used to name as a cursor name explicitly.

Difference between group functions and single row functions ?


Group Function Single Row Function
A group function operates A single row function
on many rows returns one and result for one row.
returns single result.
Not allowed in Pl/sql procedural Allowed in Pl/Sql Procedural statements
eg SUM(),AVG,MIN,MAX etc eg UPPER,LOWER,CHR...

Difference between DECODE and TRANSLATE ?


DECODE is value by value TRANSLATE is character by
character replacement. replacement.
Ex SELECT DECODE('ABC','A',1,'B',2,'ABC',3) eg SELECT
from dual; o/p 3 TRANSLATE('ABCGH',
'ABCDEFGHIJ', 1234567899)
FROM DUAL; o/p 12378
(DECODE command is used to bring IF,THEN,ELSE logic to SQL.It tests for the IF values(s) and then
aplies THEN value(s) when true, the ELSE value(s) if not.)

Difference between TRUNCATE and DELETE ?


TRUNCATE deletes much faster than DELETE
Truncate Delete

Ramesh 45 Ramesh
DBMS Questions
It is a DDL statement It is a DML statement
It is a one way trip,cannot One can Rollback
ROLLBACK
Doesn't have selective features (where clause) Has
Doesn't fire database triggers Does
It requires disabling of referential Does not require
constraints.

What is a CO-RELATED SUBQUERY ?


A CO-RELATED SUBQUERY is one that has a correlation name as table or view designator in the FROM
clause of the outer query and the same correlation name as a qualifier of a search condition in the WHERE
clause of the subquery.
eg SELECT field1 from table1 X WHERE field2>(select avg(field2) from table1 Y
where field1=X.field1);
(The subquery in a correlated subquery is revaluated
for every row of the table or view named in the outer query.)
What are various joins used while writing SUBQUERIES ?
Self join-Its a join foreign key of a table references the same table.
Outer Join--Its a join condition used where One can query all the rows of one of the
tables in the join condition even though they don't satisfy the join condition.
Equi-join--Its a join condition that retrieves rows from one or more tables in which one
or more columns in one table are equal to one or more columns in the second table.

What are various constraints used in SQL ?


NULL, NOT NULL, CHECK, DEFAULT

What are different Oracle database objects ?


TABLES, VIEWS, INDEXES, SYNONYMS, SEQUENCES, TABLESPACES etc

What is difference between Rename and Alias ?


Rename is a permanent name given to a table or column whereas Alias is a temporary name given to
a table or column which do not exist once the SQL statement is executed.

What is a view ?
A view is stored procedure based on one or more tables, it’s a virtual table.

What are various privileges that a user can grant to another user ?
SELECT, CONNECT, RESOURCES

What is difference between UNIQUE and PRIMARY KEY constraints ?


A table can have only one PRIMARY KEY whereas there can be any number of UNIQUE keys. The
columns that compose PK are automatically define NOT NULL, whereas a column that compose a UNIQUE
is not automatically defined to be mandatory must also specify the column is NOT NULL.

Can a primary key contain more than one columns ?


Yes
How you will avoid duplicating records in a query ?
By using DISTINCT

Ramesh 46 Ramesh
DBMS Questions

What is difference between SQL and SQL*PLUS ?


SQL*PLUS is a command line tool where as SQL and PL/SQL language interface and reporting tool. Its
a command line tool that allows user to type SQL commands to be executed directly against an Oracle
database. SQL is a language used to query the relational database(DML,DCL,DDL). SQL*PLUS commands
are used to format query result, Set options, Edit SQL commands and PL/SQL.

Which datatype is used for storing graphics and images ?


LONG RAW data type is used for storing BLOB's (binary large objects).

How will you delete duplicating rows from a base table ?


DELETE FROM table_name A WHERE rowid>(SELECT min(rowid) from table_name B where
B.table_no=A.table_no);
CREATE TABLE new_table AS SELECT DISTINCT * FROM old_table;
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)

What is difference between SUBSTR and INSTR ?


SUBSTR returns a specified portion of a string eg SUBSTR('BCDEF',4) output BCDE
INSTR provides character position in which a pattern is found in a string.
eg INSTR('ABC-DC-F','-',2) output 7 (2nd occurence of '-')

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.

Which is more faster - IN or EXISTS ?


EXISTS is more faster than IN because EXISTS returns a Boolean value whereas IN returns a value.

What is a OUTER JOIN ?


Outer Join--Its a join condition used where you can query all the rows of one of the tables in the join
condition even though they don’t satisfy the join condition.

What is a pseudo column. Give some examples ?


It is a column that is not an actual column in the table.
eg USER, UID, SYSDATE, ROWNUM, ROWID, NULL, AND LEVEL.

Ramesh 47 Ramesh
DBMS Questions

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 the purpose of a cluster ?


Oracle does not allow a user to specifically locate tables, since that is a part of the function of the
RDBMS. However, for the purpose of increasing performance, oracle allows a developer to create a
CLUSTER. A CLUSTER provides a means for storing data from different tables together for faster retrieval
than if the table placement were left to the RDBMS.

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 are cursor attributes ?


%ROWCOUNT, %NOTFOUND, %FOUND, %ISOPEN

What is a cursor for loop ?


Cursor For Loop is a loop where oracle implicitly declares a loop variable, the loop index that of the
same record type as the cursor's record.

Difference between NO DATA FOUND and %NOTFOUND ?


NO DATA FOUND is an exception raised only for the SELECT....INTO statements when the where clause
of the querydoes not match any rows. When the where clause of the explicit cursor does not match any
rows the %NOTFOUND attribute is set to TRUE instead.

What a SELECT FOR UPDATE cursor represent ?


SELECT......FROM......FOR......UPDATE[OF column-reference][NOWAIT] The processing done in
a fetch loop modifies the rows that have been retrieved by the cursor.
A convenient way of modifying the rows is done by a method with two parts: the FOR UPDATE
clause in the cursor declaration, WHERE CURRENT OF CLAUSE in an UPDATE or declaration statement.

What 'WHERE CURRENT OF ' clause does in a cursor ?


LOOP SELECT num_credits INTO v_numcredits FROM classes WHERE dept=123 and course=101;
UPDATE students SET current_credits=current_credits+v_numcredits WHERE CURRENT OF X;
END LOOP
COMMIT;

Ramesh 48 Ramesh
DBMS Questions
END;

What is use of a cursor variable? How it is defined ?


A cursor variable is associated with different statements at run time, which can hold different values
at run time. Static cursors can only be associated with one run time query. A cursor variable is reference
type(like a pointer in C).
Declaring a cursor variable:
TYPE type_name IS REF CURSOR RETURN return_type type_name is the name of
the reference type,return_type is a record type indicating the types of the select list
that will eventually be returned by the cursor variable.

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

How you open and close a cursor variable.Why it is required ?


OPEN cursor variable FOR SELECT...Statement
CLOSE cursor variable In order to associate a cursor variable with a particular
SELECT statement OPEN syntax is used.In order to free the resources used
for the query CLOSE
statement is used.

How you were passing cursor variables in PL/SQL 2.2 ?


In PL/SQL 2.2 cursor variables cannot be declared in a package.This is because the storage for a cursor
variable has to be allocated using Pro*C or OCI with version 2.2,the only means of passing a cursor variable
to a PL/SQL block is via bind variable or a procedure parameter.

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.

Difference between procedure and function ?


Functions are named PL/SQL blocks that return a value and can be called with arguments procedure a
named block that can be called with parameter. A procedure all is a PL/SQL statement by itself, while a
Function call is called as part of an expression.

What are different modes of parameters used in functions and procedures ?


IN, OUT, INOUT.

What is difference between a formal and an actual parameter ?


The variables declared in the procedure and which are passed, as arguments are called actual, the
parameters in the procedure declaration. Actual parameters contain the values that are passed to a procedure
and receive results. Formal parameters are the placeholders for the values of actual parameters.

Can the default values be assigned to actual parameters ?


Yes

Can a function take OUT parameters. If not why ?

Ramesh 49 Ramesh
DBMS Questions
No. A function has to return a value, an OUT parameter cannot return a value.

What is syntax for dropping a procedure and a function ?


Drop Procedure procedure_name
Drop Function function_name

What are ORACLE PRECOMPILERS ?


Using ORACLE PRECOMPILERS ,SQL statements and PL/SQL blocks can be contained inside 3GL
programs written in C,C++,COBOL,PASCAL, FORTRAN,PL/1 AND ADA.
The Precompilers are known as Pro*C,Pro*Cobol,...
This form of PL/SQL is known as embedded pl/sql,the language in which pl/sql is embedded is known as the
host language.

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 OCI. What are its uses ?


Oracle Call Interface is a method of accesing database from a 3GL program. Uses--No precompiler is
required,PL/SQL blocks are executed like other DML statements.
The OCI library provides
-functions to parse SQL statemets
-bind input variables
-bind output variables
-execute statements
-fetch the results

Difference between database triggers and form triggers ?


a) Data base trigger(DBT) fires when a DML operation is performed on a data base table.Form trigger(FT)
Fires when user presses a key or navigates between fields on the screen
b) Can be row level or statement level No distinction between row level and statement level.
c) Can manipulate data stored in Oracle tables via SQL Can manipulate data in Oracle tables as well as
variables in forms.
d) Can be fired from any session executing the triggering DML statements. Can be fired only from the form
that define the trigger.
e) Can cause other database triggers to fire.Can cause other database triggers to fire,but not other form
triggers.

What is an UTL_FILE.What are different procedures and functions associated


with it ?
UTL_FILE is a package that adds the ability to read and write to operating system files Procedures
associated with it are FCLOSE, FCLOSE_ALL and 5 procedures to output data to a file PUT, PUT_LINE,
NEW_LINE, PUTF, FFLUSH.PUT, FFLUSH.PUT_LINE,FFLUSH.NEW_LINE. Functions associated with
it are FOPEN, ISOPEN.

Can you use a commit statement within a database trigger ?


No

What is maximum buffer size that can be specified using the DBMS_OUTPUT.ENABLE function?

Ramesh 50 Ramesh
DBMS Questions
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 Data Dictionary ?


The DATA DICTIONARY is a comprehensive set of tables and views owned by the DBA users SYS
and SYSTEM, which activates when ORACLE is initially installed, and is a cental source of information for
the ORACLE RDBMS itself and for all users of ORACLE. The tables are automatically maintained by
ORACLE, and holds a set of views and tables containing information about the database objects, users,
privileges, events, and use.

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.

2. Can we create a View without a table ?


Yes, Using the FORCE option in the CREATE VIEW syntax.
Ex: CREATE FORCE VIEW view_name as SELECT column name, columnname..
FROM table_name;

3. What is the difference between a SYNONYM and a VIEW ?


A SYNONYM is a name assigned to a table or view that may thereafter be used to refer it. If you
access to another user’s table, you may create a synonym for it and refer to it by the synonym alone, without
entering the user’s name as a qualifier.
Difference: A View can be based on MULTIPLE Tables whereas a SYNONYM is based on a single
object only.

Ramesh 51 Ramesh
DBMS Questions
4. What is SNAPSHOT ? What is a SNAPSHOT LOG ?
A SNAPSHOT is a means of creating a local copy of remote data. A snapshot can be used to
replicate all or part of a single table, or to replicate the result of a query against multiple tables. The refreshes
of the replicated data can be done automatically by the database ( at time intervals you specify ) or
manually.Snapshot Log is the table associated with the Master Table of the Snap shot.

5. What is a DATABASE trigger ? What is a DATABASE Procedure ?


A DATABASE TRIGGER is a stored procedure associated with a table that ORACLE7
automatically executes on one or more specified events (BEFORE or AFTER an INSERT,UPDATE or
DELETE) affecting the table. Triggers can execute for the table as a whole or for each affected row in the
table.
A PACKAGED PROCEDURE is a built-in PL/SQL procedure that is available in all forms. Each
packaged procedure executes a SQL*FORMS function, such as moving to a field or executing a query.
8. What is a CURSOR ?
A work area in memory where ORACLE stores the current SQL statement. For a query , the area in
memory also includes column headings and one row retrieved by the SELECT statement.

10. Can we pass a PARAMETER to CURSOR ? What is SQL%ROWCOUNT ?


We can pass parameter to CURSOR. Eg: OPEN CUSOR(‘VASAN’).
SQL%ROWCOUNT is used to count the number of rows returned by an SQL DML statement. It will return
zero if the DML statement doesn’t return any row.

15. Can we use a funtion inside an INSERT statement ?


Yes. Eg: INSERT INTO EMP(COMM ) VALUES ( SAL*0.05 ) WHERE DEPTNO = 20;

16. What is TRUNCATE table ?


TRUNCATE table is a DDL command used to remove all the rows from the specified table or cluster
instantly. Eg: TRUNCATE TABLE table_name;

17. What is ROWID ? What are its components ?


ROWID is the logical address of a row, and it is unique within the database.The ROWID is broken
into three sections: left,middle,, and right (corresponding to 00001F20,000C, AND 0001, just shown).
The numbering is in hexadecimal notation.
The left section is the block in the file, the middle is the row sequence number within the
block(numbering starts with 0, not 1), and the right is the file number within the database. Note that the file
numbers are uniquewithin the whole database. The tablespace they are in is not relevant to the ROWID.
ROWID can be selected, or used in a where clause, but cannot be changed by an insert, update, or
delete. However it can changeif the table it is in is exported and imported.

21. Name any ORACLE defined EXCEPTION ?


CURSOR_ALREADY_OPEN, NO_DATA_FOUND, INVALID_NUMBER.

22. Can we define our OWN EXCEPTION ? How to raise it ?


In the DECLARATION part define a variable of type exception. In the excecution part call the
exception using RAISE exception_name. In the exception part handle the exception using WHEN
exception_name.

23. What is a PRAGMA ?

Ramesh 52 Ramesh
DBMS Questions
It is a directive to the COMPILER, rather than a piece of executable code. Eventhough it appears in
the program, it is not executable. It gives instructions to the compiler.

24. Difference between CHAR and VARCHAR2 ?


CHAR(size) - It is a fixed length character data, size characters long. It is padded with BLANKS ON
RIGHT to the full length of size. DEFAULT - 1 bytes, MAXIMUM - 255 bytes.
VARCHAR2(size) - It is a varable length char string having a maximum of size bytes.
MAXIMUM - 2000 bytes.

25. What is a CURSOR FOR LOOP ?


The CURSOR FOR LOOP lets you implicitly OPEN a cursor, FETCH each row returned by the
query associated with the cursor and CLOSE the cursor when all rows have been processed.

26. What are the possible CONSTRAINTS defined on a TABLE ?


NOT NULL, UNIQUE KEY, PRIMARY KEY, FOREIGN KEY and CHECK constraints.

27. What is APPLICATION PARTITIONING ?


PL/SQL is the language used for both client-side Oracle forms applications and server-side database
triggers and stored procedures and there is a PL/SQl engine in both Oracle forms Runform and the Oracle7
Server.
This means that you can take advantage of application patitioning to execute application code on
either the client or the server.
Application partitioning allows you to optimize performance and resource usage by storing and
executing procedures either locally or at the server, which makes the most sense for your particular
application and configuration.

28. Difference between a STORED PROCEDURE and a STORED FUNCTION ?


Unlike procedures, FUNCTIONS returns a VALUE to the caller. This value is returned thro’ the
RETURN command/keyword within the function.
Functions don’t use the IN, OUT | IN OUT arguments, which are available for PROCEDURES.

29. How to RUN PROCEDURES from SQL PROMPT ?


Use EXECUTE Procedure_name command.

30. How to TRAP ERRORS in procedures ?


Use SHOW_ERRORS. this will display all the errors associated with the most recently created
procedural object. This command will check the VIEW_ERRORS data dictionary for the ERRORS
associated with the most recent compilation attempt for that procedural object.
SHOW_ERRORS will display the LINE and COLUMN NO. for each error, as well as the text of the
error message.

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.

38. What is the DIFFERENCE between PRE-QUERY and POST-QUERY ?

Ramesh 53 Ramesh
DBMS Questions
PRE-QUERY fires ONLY ONCE during EXECUTE-QUERY or COUNT-QUERY processing, just
before Oracle Forms constructs and issues the SELECT statement to identify rows that match the query
criteria.
POST-QUERY fires each time for records placed on the blocks list of records.

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.

42. What is the difference between ROWID and ROWNUM ?


ROWID is the logical address of the row, whereas ROWNUM returns the sequence no. in which the
row was retrieved when first feched from a table.

43. What is the RESULT of the statement ?


SELECT EMPNO, NAME,SAL FROM EMP WHERE ROWNUM >2;
Result : 0, No rows will be selected.

44. How do you evaluate performance ?


Using SQL TRACE. It is an utility that can monitor and report on database performance when one or
more queries are run against the database.
It is used to gather statistics when running the query (i.e) reports on CPU time spent on the query, the
total no. of rows processed and statistics related to parsing and cache performance.

53. What is a DEAD LOCK ?


A DEAD lock is a rare situation in which two or more user processes of a database cannot complete
their tansactions.This occurs because each process is holding a resource that the other process requires (such
as a row in a table) in order to complete.

63. What does ‘GROUP BY’ statement do ?


GROUP BY statement causes a SELECT statement to produce ONE SUMMARY ROW for all
selected rows that have identical values in one or more specified column or expressions. Each expe\ressionin
the SELECT clause must be one of the following :
1] A CONSANT
2] A Function without parameters
3] A GROUP function like SUM , AVG.
4] Matched IDENTICALLY to a expression in the ‘GROUP BY’ clause.

75. Difference between SQL and PL/SQL ?


SQL is the ANSI industry standard language, used to manipulate information in a relational database.
PL/SQL is the procedural language extension to Oracle’s SQL language.
SQL PL/SQL
1. It is flexible, Powerful and easy to learn. 1. PL/SQL block can contain any no. of
SQL statements combined with the
2. It is a non-procedural language. It following :
a] Processes set of records rather than a] Flow of control statements such as
just one at a time and IF..THEN, ELSE, EXIT and GOTO.
b] Provides automatic navigation to the b] Repetition statements such as FOR ..
data. LOOP and WHILE .. LOOP.

Ramesh 54 Ramesh
DBMS Questions
c] Assignment statements such as X := Y +
3. It provides commands for avariety of Z
tasks including :
a] Querying data 2. PL/SQL allows you to logically group a
b] Creating,Updating and Replacing set of statements and send them to the
objects and Inserting, Updating RDBMS as a single block.
and Deleting rows.
4] All RDBMS supports SQL 3. Procedural capabilities.
Thus one can transfer the skills gained 4. Improved performance.
with SQL from one 5. Enhanced productivity
RDBMS to another. 6. Portability
Programs written in SQL are portable,
they can often be moved from one database 7. Integration with the RDBMS.
to another with little modification.
77. What is the purpose of OUTER JOIN ?
An OUTER JOIN returns all the rows returned by simple join as well as those rows from one table
that do not match any row from the other table. The symbol (+) represents the outer join.

78. Difference between EQUI JOIN and OUTER JOIN ?


EQUI JOIN returns rows from both the tables provided they both have the same column_name in the
where clause. The symbol (=) represents the EQUI JOIN.
For OUTER JOIN see previous answer.

79. Define NORMALIZATION ?


NORMALIZATION is the process of putting things right, making them normal. It is a part of
analysis necessary to understand a business, and build a useful application.
The normalization of data ensures
a] Minimization of duplication of data.
b] Providing flexibility to support different funtional requirements.
c] Enabling the model to be translated to database design.

STEPS INVOLVED IN NORMALIZATION


1] Ensure that all the ENTITIES are uniquely identified by a combination of attributes.
2] Remove repeated attributes or group of attributes, to place the entities in the first
normal form.
3] Remove attributes that are dependent on only part of the identifier.
4] Remove attributes that are dependent on attributes which are not part of the identifier.

85. What is the Purpose of ERASE command ?


ERASE removes an indicated Global variable & releases the memory associated with it

What is LookUp table ?


When a foreign key exists in a table, the foreign key's table is sometimes referred to as a lookup table.
The DEPARTMENT table in our example is a lookup table for the EMPLOYEE table. The value of an
employee's department can be looked up in the DEPARTMENT table.

Ramesh 55 Ramesh
DBMS Questions
MULTIPLE CHOICE QUESTIONS
11. The purpose of defining an index is
(A) Enhance Sorting Performance (B) Enhance Searching Performance
(C) Achieve Normalization (D) All of the above

12. A transaction does not necessarily need to be


(A) Consistent (B) Repeatable (C) Atomic (D) Isolated

13. To group users based on common access permission one should use
(A) User Groups (B) Roles (C) Grants (D) None of the above

14. PL/SQL uses which of the following


(A) No Binding (B) Early Binding (C) Late Binding (D) Deferred Binding

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.

18. Integrity constrains are not checked at the time of


(A) DCL Statements. (B) DML Statements.
(C) DDL Statements. (D) It is checked all the above cases.

19. Roll Back segment is not used in case of a


(A) DCL Statements. (B) DML Statements. (C) DDL Statements. (D) all of the above.

Ramesh 56 Ramesh
DBMS Questions

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);

CREATE TABLE new_table AS SELECT DISTINCT * FROM old_table;

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)

How you will avoid your query from using indexes ?

SELECT * FROM emp


Where emp_no+' '=12345;

i.e you have to concatenate the column name with


space within codes in the where condition.

SELECT /*+ FULL(a) */ ename, emp_no from emp


where emp_no=1234;
i.e using HINTS

Ramesh 57 Ramesh
DBMS Questions
Guidelines for developers working with Databases

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

• Avoid using UnderScores( _ ) while naming Columns and Tables.

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

• What is normalization? Explain different levels of normalization?


Normalization is the process of organizing data in a database. This includes creating tables and
establishing relationships between those tables according to rules designed both to protect the data and to
make the database more flexible by eliminating two factors: redundancy and inconsistent dependency.

Redundant data wastes disk space and creates maintenance problems. If data that exists in more than one
place must be changed, the data must be changed in exactly the same way in all locations. A customer
address change is much easier to implement if that data is stored only in the Customers table and
nowhere else in the database
First Normal Form
• Eliminate repeating groups in individual tables.
• Create a separate table for each set of related data.

Ramesh 58 Ramesh
DBMS Questions
• Identify each set of related data with a primary key.
Do not use multiple fields in a single table to store similar data. For example, to track an inventory item that
may come from two possible sources, an inventory record may contain fields for Vendor Code 1 and Vendor
Code 2.

But what happens when you add a third vendor? Adding a field is not the answer; it requires program and
table modifications and does not smoothly accommodate a dynamic number of vendors. Instead, place all
vendor information in a separate table called Vendors, then link inventory to vendors with an item number
key, or vendors to inventory with a vendor code key.
Second Normal Form
• Create separate tables for sets of values that apply to multiple records.
• Relate these tables with a foreign key.
Records should not depend on anything other than a table's primary key (a compound key, if necessary). For
example, consider a customer's address in an accounting system. The address is needed by the Customers
table, but also by the Orders, Shipping, Invoices, Accounts Receivable, and Collections 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.
Third Normal Form
• Eliminate fields that do not depend on the key.
Values in a record that are not part of that record's key do not belong in the table. In general, any time the
contents of a group of fields may apply to more than a single record in the table, consider placing those
fields in a separate table.

For example, in an Employee Recruitment table, a candidate's university name and address may be
included. But you need a complete list of universities for group mailings. If university information is
stored in the Candidates table, there is no way to list universities with no current candidates. Create a
separate Universities table and link it to the Candidates table with a university code key.
**********************************
Examples of Normalized Tables
**********************************

Normalization Examples:

Unnormalized table:

Student# Advisor Adv-Room Class1 Class2 Class3


-------------------------------------------------------
1022 Jones 412 101-07 143-01 159-02
4123 Smith 216 201-01 211-02 214-01

1. First Normal Form: NO REPEATING GROUPS

Tables should have only two dimensions. Since one student has several classes, these classes should
be listed in a separate table. Fields Class1, Class2, & Class3 in the above record are indications of
design trouble.

Ramesh 59 Ramesh
DBMS Questions
Spreadsheets often use the third dimension, but tables should not. Another way to look at this
problem: with a one-to-many relationship, do not put the one side and the many side in the same
table. Instead, create another table in first normal form by eliminating the repeating group (Class#), as
shown below:
Student# Advisor Adv-Room Class#
---------------------------------------
1022 Jones 412 101-07
1022 Jones 412 143-01
1022 Jones 412 159-02
4123 Smith 216 201-01
4123 Smith 216 211-02
4123 Smith 216 214-01

Second Normal Form: ELIMINATE REDUNDANT DATA

Note the multiple Class# values for each Student# value in the above table. Class# is not functionally
dependent on Student# (primary key), so this relationship is not in second normal form.

The following two tables demonstrate second normal form:


Students: Student# Advisor Adv-Room
------------------------------
1022 Jones 412
4123 Smith 216

Registration: Student# Class#


------------------
1022 101-07
1022 143-01
1022 159-02
4123 201-01
4123 211-02
4123 214-01

Third Normal Form: ELIMINATE DATA NOT DEPENDENT ON KEY

In the last example, Adv-Room (the advisor's office number) is functionally dependent on the Advisor
attribute. The solution is to move that attribute from the Students table to the Faculty table, as shown
below:
Students: Student# Advisor
-------------------
1022 Jones
4123 Smith

Faculty: Name Room Dept


--------------------

Jones 412 42
Smith 216 42

• What is denormalization and when would you go for it?

Ramesh 60 Ramesh
DBMS Questions
o As the name indicates, denormalization is the reverse process of normalization. It's the
controlled introduction of redundancy in to the database design. It helps improve the query
performance as the number of joins could be reduced.
• How do you implement one-to-one, one-to-many and many-to-many relationships while
designing tables?
o One-to-One relationship can be implemented as a single table and rarely as two tables with
primary and foreign key relationships. One-to-Many relationships are implemented by
splitting the data into two tables with primary key and foreign key relationships. Many-to-
Many relationships are implemented using a junction table with the keys from both the tables
forming the composite primary key of the junction table. It will be a good idea to read up a
database designing fundamentals text book.

• What's the difference between a primary key and a unique key?


o Both primary key and unique enforce uniqueness of the column on which they are defined.
But by default primary key creates a clustered index on the column, where are unique creates
a nonclustered index by default. Another major difference is that, primary key doesn't allow
NULLs, but unique key allows one NULL only.
• What are user defined datatypes and when you should go for them?
o User defined datatypes let you extend the base SQL Server datatypes by providing a
descriptive name, and format to the database. Take for example, in your database, there is a
column called Flight_Num which appears in many tables. In all these tables it should be
varchar(8). In this case you could create a user defined datatype called Flight_num_type of
varchar(8) and use it across all your tables. See sp_addtype, sp_droptype in books online.

• What is bit datatype and what's the information that can be stored inside a bit column?
o Bit datatype is used to store boolean information like 1 or 0 (true or false). Untill SQL Server
6.5 bit datatype could hold either a 1 or 0 and there was no support for NULL. But from SQL
Server 7.0 onwards, bit datatype can represent a third state, which is NULL.

• Define candidate key, alternate key, composite key.


o A candidate key is one that can identify each row of a table uniquely. Generally a candidate
key becomes the primary key of the table. If the table has more than one candidate key, one of
them will become the primary key, and the rest are called alternate keys. A key formed by
combining at least two or more columns is called composite key.
• What are defaults? Is there a column to which a default can't be bound?
o A default is a value that will be used by a column, if no value is supplied to that column while
inserting data. IDENTITY columns and timestamp columns can't have defaults bound to
them. See CREATE DEFAULT in books online.

• What is a transaction and what are ACID properties?


o A transaction is a logical unit of work in which, all the steps must be performed or none.
ACID stands for Atomicity, Consistency, Isolation, Durability. These are the properties of a

Ramesh 61 Ramesh
DBMS Questions
transaction. For more information and explanation of these properties, see SQL Server books
online or any RDBMS fundamentals text book. Explain different isolation levels An isolation
level determines the degree of isolation of data between concurrent transactions. The default
SQL Server isolation level is Read Committed. Here are the other isolation levels (in the
ascending order of isolation): Read Uncommitted, Read Committed, Repeatable Read,
Serializable. See SQL Server books online for an explanation of the isolation levels. Be sure
to read about SET TRANSACTION ISOLATION LEVEL, which lets you customize the
isolation level at the connection level. Read Committed - A transaction operating at the Read
Committed level cannot see changes made by other transactions until those transactions are
committed. At this level of isolation, dirty reads are not possible but nonrepeatable reads and
phantoms are possible. Read Uncommitted - A transaction operating at the Read
Uncommitted level can see uncommitted changes made by other transactions. At this level of
isolation, dirty reads, nonrepeatable reads, and phantoms are all possible. Repeatable Read - A
transaction operating at the Repeatable Read level is guaranteed not to see any changes made
by other transactions in values it has already read. At this level of isolation, dirty reads and
nonrepeatable reads are not possible but phantoms are possible. Serializable - A transaction
operating at the Serializable level guarantees that all concurrent transactions interact only in
ways that produce the same effect as if each transaction were entirely executed one after the
other. At this isolation level, dirty reads, nonrepeatable reads, and phantoms are not possible.

• CREATE INDEX myIndex ON myTable(myColumn)What type of Index will get created after
executing the above statement?
o Non-clustered index. Important thing to note: By default a clustered index gets created on the
primary key, unless specified otherwise.

• What's the maximum size of a row?


o 8060 bytes. Don't be surprised with questions like 'what is the maximum number of columns
per table'. 1024 columns per table. Check out SQL Server books online for the page titled:
"Maximum Capacity Specifications". Explain Active/Active and Active/Passive cluster
configurations Hopefully you have experience setting up cluster servers. But if you don't, at
least be familiar with the way clustering works and the two clusterning configurations
Active/Active and Active/Passive. SQL Server books online has enough information on this
topic and there is a good white paper available on Microsoft site. Explain the architecture of
SQL Server This is a very important question and you better be able to answer it if consider
yourself a DBA. SQL Server books online is the best place to read about SQL Server
architecture. Read up the chapter dedicated to SQL Server Architecture.
• What is lock escalation?
o Lock escalation is the process of converting a lot of low level locks (like row locks, page
locks) into higher level locks (like table locks). Every lock is a memory structure too many
locks would mean, more memory being occupied by locks. To prevent this from happening,
SQL Server escalates the many fine-grain locks to fewer coarse-grain locks. Lock escalation
threshold was definable in SQL Server 6.5, but from SQL Server 7.0 onwards it's dynamically
managed by SQL Server.

• What's the difference between DELETE TABLE and TRUNCATE TABLE commands?

Ramesh 62 Ramesh
DBMS Questions
o DELETE TABLE is a logged operation, so the deletion of each row gets logged in the
transaction log, which makes it slow. TRUNCATE TABLE also deletes all the rows in a
table, but it won't log the deletion of each row, instead it logs the deallocation of the data
pages of the table, which makes it faster. Of course, TRUNCATE TABLE can be rolled back.
TRUNCATE TABLE is functionally identical to DELETE statement with no WHERE clause:
both remove all rows in the table. But TRUNCATE TABLE is faster and uses fewer system
and transaction log resources than DELETE. The DELETE statement removes rows one at a
time and records an entry in the transaction log for each deleted row. TRUNCATE TABLE
removes the data by deallocating the data pages used to store the table's data, and only the
page deallocations are recorded in the transaction log. TRUNCATE TABLE removes all rows
from a table, but the table structure and its columns, constraints, indexes and so on remain.
The counter used by an identity for new rows is reset to the seed for the column. If you want
to retain the identity counter, use DELETE instead. If you want to remove table definition and
its data, use the DROP TABLE statement. You cannot use TRUNCATE TABLE on a table
referenced by a FOREIGN KEY constraint; instead, use DELETE statement without a
WHERE clause. Because TRUNCATE TABLE is not logged, it cannot activate a trigger.
TRUNCATE TABLE may not be used on tables participating in an indexed view

• Explain the storage models of OLAP


o Check out MOLAP, ROLAP and HOLAP in SQL Server books online for more infomation.

• What are the new features introduced in SQL Server 2000 (or the latest release of SQL Server
at the time of your interview)? What changed between the previous version of SQL Server and
the current version?
o This question is generally asked to see how current is your knowledge. Generally there is a
section in the beginning of the books online titled "What's New", which has all such
information. Of course, reading just that is not enough, you should have tried those things to
better answer the questions. Also check out the section titled "Backward Compatibility" in
books online which talks about the changes that have taken place in the new version.

• What are constraints? Explain different types of constraints.


o Constraints enable the RDBMS enforce the integrity of the database automatically, without
needing you to create triggers, rule or defaults. Types of constraints: NOT NULL, CHECK,
UNIQUE, PRIMARY KEY, FOREIGN KEY. For an explanation of these constraints see
books online for the pages titled: "Constraints" and "CREATE TABLE", "ALTER TABLE"

• What is an index? What are the types of indexes? How many clustered indexes can be created
on a table? I create a separate index on each column of a table. What are the advantages and
disadvantages of this approach?
o Indexes in SQL Server are similar to the indexes in books. They help SQL Server retrieve the
data quicker. Indexes are of two types. Clustered indexes and non-clustered indexes. When
you create a clustered index on a table, all the rows in the table are stored in the order of the
clustered index key. So, there can be only one clustered index per table. Non-clustered
indexes have their own storage separate from the table data storage. Non-clustered indexes are
stored as B-tree structures (so do clustered indexes), with the leaf level nodes having the index
key and it's row locater. The row located could be the RID or the Clustered index key,

Ramesh 63 Ramesh
DBMS Questions
depending up on the absence or presence of clustered index on the table. If you create an
index on each column of a table, it improves the query performance, as the query optimizer
can choose from all the existing indexes to come up with an efficient execution plan. At the
same time, data modification operations (such as INSERT, UPDATE, DELETE) will become
slow, as every time data changes in the table, all the indexes need to be updated. Another
disadvantage is that, indexes need disk space, the more indexes you have, more disk space is
used.

• What is RAID and what are different types of RAID configurations?


o RAID stands for Redundant Array of Inexpensive Disks, used to provide fault tolerance to
database servers. There are six RAID levels 0 through 5 offering different levels of
performance, fault tolerance. MSDN has some information about RAID levels and for
detailed information, check out the RAID advisory board's homepage

• What are the steps you will take to improve performance of a poor performing query?
o This is a very open ended question and there could be a lot of reasons behind the poor
performance of a query. But some general issues that you could talk about would be: No
indexes, table scans, missing or out of date statistics, blocking, excess recompilations of
stored procedures, procedures and triggers without SET NOCOUNT ON, poorly written query
with unnecessarily complicated joins, too much normalization, excess usage of cursors and
temporary tables. Some of the tools/ways that help you troubleshooting performance problems
are: SET SHOWPLAN_ALL ON, SET SHOWPLAN_TEXT ON, SET STATISTICS IO ON,
SQL Server Profiler, Windows NT /2000 Performance monitor, Graphical execution plan in
Query Analyzer. Download the white paper on performance tuning SQL Server from
Microsoft web site. Don't forget to check out sql-server-performance.com
• What are the steps you will take, if you are tasked with securing an SQL Server?
o Again this is another open ended question. Here are some things you could talk about:
Preferring NT authentication, using server, database and application roles to control access to
the data, securing the physical database files using NTFS permissions, using an unguessable
SA password, restricting physical access to the SQL Server, renaming the Administrator
account on the SQL Server computer, disabling the Guest account, enabling auditing, using
multiprotocol encryption, setting up SSL, setting up firewalls, isolating SQL Server from the
web server etc. Read the white paper on SQL Server security from Microsoft website. Also
check out My SQL Server security best practices

• What is a deadlock and what is a live lock? How will you go about resolving deadlocks?
o Deadlock is a situation when two processes, each having a lock on one piece of data, attempt
to acquire a lock on the other's piece. Each process would wait indefinitely for the other to
release the lock, unless one of the user processes is terminated. SQL Server detects deadlocks
and terminates one user's process. A livelock is one, where a request for an exclusive lock is
repeatedly denied because a series of overlapping shared locks keeps interfering. SQL Server
detects the situation after four denials and refuses further shared locks. A livelock also occurs
when read transactions monopolize a table or page, forcing a write transaction to wait
indefinitely. Check out SET DEADLOCK_PRIORITY and "Minimizing Deadlocks" in SQL
Server books online. Also check out the article Q169960 from Microsoft knowledge base.

Ramesh 64 Ramesh
DBMS Questions
• What is blocking and how would you troubleshoot it?
o Blocking happens when one connection from an application holds a lock and a second
connection requires a conflicting lock type. This forces the second connection to wait, blocked
on the first. Read up the following topics in SQL Server books online: Understanding and
avoiding blocking, Coding efficient transactions. Explain CREATE DATABASE syntax
Many of us are used to creating databases from the Enterprise Manager or by just issuing the
command: CREATE DATABAE MyDB.

• But what if you have to create a database with two filegroups, one on drive C and the other on
drive D with log on drive E with an initial size of 600 MB and with a growth factor of 15%?
o That's why being a DBA you should be familiar with the CREATE DATABASE syntax.
Check out SQL Server books online for more information.

• How to restart SQL Server in single user mode? How to start SQL Server in minimal
configuration mode?
o SQL Server can be started from command line, using the SQLSERVR.EXE. This EXE has
some very important parameters with which a DBA should be familiar with. –m is used for
starting SQL Server in single user mode and -f is used to start the SQL Server in minimal
configuration mode. Check out SQL Server books online for more parameters and their
explanations.

• As a part of your job, what are the DBCC commands that you commonly use for database
maintenance?
o DBCC CHECKDB, DBCC CHECKTABLE, DBCC CHECKCATALOG, DBCC
CHECKALLOC, DBCC SHOWCONTIG, DBCC SHRINKDATABASE, DBCC
SHRINKFILE etc. But there are a whole load of DBCC commands which are very useful for
DBAs. Check out SQL Server books online for more information.
• What are statistics, under what circumstances they go out of date, how do you update them?
o Statistics determine the selectivity of the indexes. If an indexed column has unique values
then the selectivity of that index is more, as opposed to an index with non-unique values.
Query optimizer uses these indexes in determining whether to choose an index or not while
executing a query. Some situations under which you should update statistics: 1) If there is
significant change in the key values in the index 2) If a large amount of data in an indexed
column has been added, changed, or removed (that is, if the distribution of key values has
changed), or the table has been truncated using the TRUNCATE TABLE statement and then
repopulated 3) Database is upgraded from a previous version. Look up SQL Server books
online for the following commands: UPDATE STATISTICS, STATS_DATE, DBCC
SHOW_STATISTICS, CREATE STATISTICS, DROP STATISTICS, sp_autostats,
sp_createstats, sp_updatestats

• What are the different ways of moving data/databases between servers and databases in SQL
Server?
o There are lots of options available, you have to choose your option depending upon your
requirements. Some of the options you have are: BACKUP/RESTORE, dettaching and

Ramesh 65 Ramesh
DBMS Questions
attaching databases, replication, DTS, BCP, logshipping, INSERT...SELECT,
SELECT...INTO, creating INSERT scripts to generate data.
• Explain different types of BACKUPs avaialabe in SQL Server? Given a particular scenario,
how would you go about choosing a backup plan?
o Types of backups you can create in SQL Sever 7.0+ are Full database backup, differential
database backup, transaction log backup, filegroup backup. Check out the BACKUP and
RESTORE commands in SQL Server books online. Be prepared to write the commands in
your interview. Books online also has information on detailed backup/restore architecture and
when one should go for a particular kind of backup.

• What is database replication? What are the different types of replication you can set up in SQL
Server?
o Replication is the process of copying/moving data between databases on the same or different
servers. SQL Server supports the following types of replication scenarios: · Snapshot
replication · Transactional replication (with immediate updating subscribers, with queued
updating subscribers) · Merge replication See SQL Server books online for indepth coverage
on replication. Be prepared to explain how different replication agents function, what are the
main system tables used in replication etc.
• How to determine the service pack currently installed on SQL Server?
o The global variable @@Version stores the build number of the sqlservr.exe, which is used to
determine the service pack installed. To know more about this process visit SQL Server
service packs and versions.

• What are cursors? Explain different types of cursors. What are the disadvantages of cursors?
How can you avoid cursors?
o Cursors allow row-by-row processing of the resultsets. Types of cursors: Static, Dynamic,
Forward-only, Keyset-driven. See books online for more information. Disadvantages of
cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as
a normal SELECT query makes only one roundtrip, however large the resultset is. Cursors are
also costly because they require more resources and temporary storage (results in more IO
operations). Further, there are restrictions on the SELECT statements that can be used with
some types of cursors. Most of the times, set based operations can be used instead of cursors.
Here is an example: If you have to give a flat hike to your employees using the following
criteria: Salary between 30000 and 40000 -- 5000 hike Salary between 40000 and 55000 --
7000 hike Salary between 55000 and 65000 -- 9000 hike. In this situation many developers
tend to use a cursor, determine each employee's salary and update his salary according to the
above formula. But the same can be achieved by multiple update statements or can be
combined in a single UPDATE statement as shown below:
o UPDATE tbl_emp SET salary = CASE WHEN salary BETWEEN 30000 AND 40000 THEN
salary + 5000 WHEN salary BETWEEN 40000 AND 55000 THEN salary + 7000 WHEN
salary BETWEEN 55000 AND 65000 THEN salary + 10000 END
o Another situation in which developers tend to use cursors: You need to call a stored procedure
when a column in a particular row meets certain condition. You don't have to use cursors for

Ramesh 66 Ramesh
DBMS Questions
this. This can be achieved using WHILE loop, as long as there is a unique key to identify each
row. For examples of using WHILE loop for row by row processing, check out the 'My code
library' section of my site or search for WHILE. Write down the general syntax for a SELECT
statements covering all the options. Here's the basic syntax: (Also checkout SELECT in books
online for advanced syntax).
o SELECT select_list [INTO new_table_] FROM table_source [WHERE search_condition]
[GROUP BY group_by_expression] [HAVING search_condition] [ORDER BY
order_expression [ASC | DESC] ]
• What is a join and explain different types of joins.
o Joins are used in queries to explain how different tables are related. Joins also let you select
data from a table depending upon data from another table. Types of joins: INNER JOINs,
OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER
JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS. For more information see pages
from books online titled: "Join Fundamentals" and "Using Joins".

• Can you have a nested transaction?


o Yes, very much. Check out BEGIN TRAN, COMMIT, ROLLBACK, SAVE TRAN and
@@TRANCOUNT

• What is an extended stored procedure? Can you instantiate a COM object by using T-SQL?
o An extended stored procedure is a function within a DLL (written in a programming language
like C, C++ using Open Data Services (ODS) API) that can be called from T-SQL, just the
way we call normal stored procedures using the EXEC statement. See books online to learn
how to create extended stored procedures and how to add them to SQL Server. Yes, you can
instantiate a COM (written in languages like VB, VC++) object from T-SQL by using
sp_OACreate stored procedure. Also see books online for sp_OAMethod, sp_OAGetProperty,
sp_OASetProperty, sp_OADestroy. For an example of creating a COM object in VB and
calling it from T-SQL, see 'My code library' section of this site.
• What is the system function to get the current user's user id?
o USER_ID(). Also check out other system functions like USER_NAME(), SYSTEM_USER,
SESSION_USER, CURRENT_USER, USER, SUSER_SID(), HOST_NAME().

• What are triggers? How many triggers you can have on a table? How to invoke a trigger on
demand?
o Triggers are special kind of stored procedures that get executed automatically when an
INSERT, UPDATE or DELETE operation takes place on a table. In SQL Server 6.5 you
could define only 3 triggers per table, one for INSERT, one for UPDATE and one for
DELETE. From SQL Server 7.0 onwards, this restriction is gone, and you could create
multiple triggers per each action. But in 7.0 there's no way to control the order in which the
triggers fire. In SQL Server 2000 you could specify which trigger fires first or fires last using
sp_settriggerorder. Triggers can't be invoked on demand. They get triggered only when an
associated action (INSERT, UPDATE, DELETE) happens on the table on which they are
defined. Triggers are generally used to implement business rules, auditing. Triggers can also

Ramesh 67 Ramesh
DBMS Questions
be used to extend the referential integrity checks, but wherever possible, use constraints for
this purpose, instead of triggers, as constraints are much faster. Till SQL Server 7.0, triggers
fire only after the data modification operation happens. So in a way, they are called post
triggers. But in SQL Server 2000 you could create pre triggers also. Search SQL Server 2000
books online for INSTEAD OF triggers. Also check out books online for 'inserted table',
'deleted table' and COLUMNS_UPDATED()

• There is a trigger defined for INSERT operations on a table, in an OLTP system. The trigger is
written to instantiate a COM object and pass the newly insterted rows to it for some custom
processing. What do you think of this implementation? Can this be implemented better?
o Instantiating COM objects is a time consuming process and since you are doing it from within
a trigger, it slows down the data insertion process. Same is the case with sending emails from
triggers. This scenario can be better implemented by logging all the necessary data into a
separate table, and have a job which periodically checks this table and does the needful.

• What is a self join? Explain it with an example.


o Self join is just like any other join, except that two instances of the same table will be joined
in the query. Here is an example: Employees table which contains rows for normal employees
as well as managers. So, to find out the managers of all the employees, you need a self join.
o CREATE TABLE emp ( empid int, mgrid int, empname char(10) )
o INSERT emp SELECT 1,2,'Vyas' INSERT emp SELECT 2,3,'Mohan' INSERT emp SELECT
3,NULL,'Shobha' INSERT emp SELECT 4,2,'Shridhar' INSERT emp SELECT 5,2,'Sourabh'
o SELECT t1.empname [Employee], t2.empname [Manager] FROM emp t1, emp t2 WHERE
t1.mgrid = t2.empid Here's an advanced query using a LEFT OUTER JOIN that even returns
the employees without managers (super bosses)
o SELECT t1.empname [Employee], COALESCE(t2.empname, 'No manager') [Manager]
FROM emp t1 LEFT OUTER JOIN emp t2 ON t1.mgrid = t2.empid

Ramesh 68 Ramesh
DBMS Questions

• Explain Third normalization form with an example?


• When you should use low fill factor?
• How you can minimize the deadlock situation
• How to choose between a Clustered Index and a Non-Clustered Index?
• Why there is a performance difference between two similar queries that uses UNION and UNION
ALL?
• Write a SQL Query to find first day of month?
• A user is a member of Public role and Sales role. Public role has the permission to select on all the
table, and Sales role, which doesnt have a select permission on some of the tables. Will that user be
able to select from all tables ?
• If a user doesnt have a permission on a table, but he has permission to a view created on it, will he be
able to view the data in table?
• Describe Application Role and explain a scenario when you will use it?
• Both a UNIQUE constraint and a PRIMARY KEY constraint enforce uniqueness, so when you
should use UNIQUE Constraint?
• What is the difference between the REPEATABLE READ and SERIALIZE isolation levels?
• Why one should not prefix user stored procedures with sp_?
• You have several tables, and they are joined together for querying. They have clustered indexes and
non clustered indexes. To optimize the performance how you will distribute the tables and their
indexes on different file Groups
• Which event (Check constraints, Foreign Key, Rule, trigger, Primary key check) will be performed
last for integrity check ?
• After removing a table from database, what other related objects have to be dropped explicitly ?
• How can you get an identity value inside a trigger, there are different ways to get identity value,
explain why you will prefer one on another.
• How to find out which stored procedure is recompiling
• How to stop stored procedures from recompiling?
• When should one use instead of Trigger?
• What is a derived table?
• What are primary keys and foreign keys?
• What is the difference between clustered and non-clustered indices?
...and why might you use a clustered index?
• What is an outer join?
• What are cartesian joins?
• How is referential integrity enforced in a SQL Server database?
• What are the inserted and deleted tables and what are they used for?
• What is the name of the SQL language used in SQL Server stored procedures?
• What is the purpose of having stored procedures in a database?
• Why might you create a stored procedure with the 'with recompile' option?
• What is a cursor?
• Within a cursor, how would you update fields on the row just fetched?
• What command would you use to inspect the users currently logged into a SQL Server database?
• What is the DBCC command used for?
• How would you find out whether a SQL query is using the indices you expect?

Ramesh 69 Ramesh
DBMS Questions
• How might you quantitatively measure an improvement made to a query?
• Why might the optimiser use a table scan when an index is available?
• How can you force the optimiser to use a particular index?

• What is an HTTP Module?


• How do u define security for an assembly
• Isolation level in SQL
• What are User Defined Types? and how do you use them?
• How do u trigger a COM from SQL?
• What is Transaction? Transaction isolation
• what are optimizer hints
• Microsoft SDLC

Ramesh 70 Ramesh
DBMS Questions
DBMS-1 Questions
1)____________is statement that is executed automatically by the system
as a side effect of a modification of a database.

A) Assertion

B) Trigger

C)cursor

D) None

Ans: B

2) A collection of conceptual tools for describing data, data relationships,


data semantics, consistency constraints is__________.

A) Data model

B) ER model

C) Object based model

D) None

Ans: A

3) The overall design of a database is called___________.

A) Database design

B) Instance

C) Schema

D) None

Ans: C

4) Every determinant is a key. This is____________.

A) 2NF

B) BCNF

C) 3NF

D) 1NF

Ans: B

5)__________is a set of one or more attributes, that taken collectively allows


us to identify uniquely an entity in entity set.

Ramesh 71 Ramesh
DBMS Questions
A) Super key

B) Candidate key

C) Primary key

D) None

Ans: A

6) The time of locks by which a data item can be locked are

A) Shared

B) Exclusive

C) Both

D) None

Ans: C

7)__________is the highest level of abstraction describes only that part of


the entire database.

A) Physical level

B) Logical level

C) View level

D) None

Ans: C

8)Part of a super key is__________

A) Candidate key

B) Primary key

C) Alternate key

D) None

Ans: C

9)_________refers to the disk mirroring.

A) RAID level 0

B) RAID level 1

C) RAID level 2

Ramesh 72 Ramesh
DBMS Questions
D) RAID level 3

Ans: B

10) The disadvantage of relational database design are:

A) Repetition of information

B) Inability to represent data

C) Only A

D) Both

Ans: D

11) There are _____different types of serializability

A) 1

B) 2

C) 3

D) None

Ans: A

12) A primary key with more than one attribute is called

A) Candidate key

B) Composite key

C) Alternate key

D) None

Ans: B

13) Tuple relational calculus is _______query language.

A) Procedural

B) Non procedural

C) Structured

D) None

Ans: B

14)_________express the number of entities to which another entity can be


associated via a relationship set

A) Cardinality ratio

B) Mapping cardinalities

Ramesh 73 Ramesh
DBMS Questions
C) Both

D) None

Ans: C

15) ________ is a particular property, which describes the entity.

Attribute
Entity
C) Object

D) None

Ans: A

16) ________ types of Data Independence are present.

A) 3

B) 2

C) 1

D) None

Ans: B

17)__________ is the time from when a read or write request is issued to when
data transfer begins.

A) Average seek time

B) Access time

C) Latency time

D) None

Ans: B

18) The property ‘Either all operations of the transaction are reflected
properly in the database’ refers to

A) Durability

B) Atomicity

Ramesh 74 Ramesh
DBMS Questions
C) Isolation

D) None

Ans: B

19) A transaction that completes it execution successfully is called ______.

A) Aborted

B) Committed

C) Partially commited

D) Failed

Ans: B

20) In a two phase locking protocol the phases are________.

A) Growing

B) Shrinking

C) Both

D) None
Ans: C
21.Given two union compatible relations R1(A,B) and R2(C,D)
what is the result of the operation R1 A=C AB=D R2 ?
a.R1 U R2 b. R1 ^ R2 c.R1 - R2 d.R1 * R2
Ans:B

22.The data dictionary tells the DBMS


a.What files are in the database b.What attributes are possessed by the data
c.What these files contain d.All of the above
Ans:D

23. The level of abstraction describes only part of the


entries database is called
a. Physical level b.Conceptual level c.View level d.Procedural level
Ans:C

24.Identify the false statement


a.Hierarchical model evolved from the base system
b.Hierarchical model is super set of network model
c.network model is a super set of Hierarchical model
d.Relational model is based on the mathematical model of relation
Ans:B

25.With regard to the expressive power of the formal relational


query languages which of the following statement is TRUE
a. Relational algebra is more powerful than relational calculus
b. Relational algebra is same power as relational calculus
c. Relational algebra is same powerful as safe relational calculus
d. None of these

Ramesh 75 Ramesh
DBMS Questions
Ans:C

26.Suppose the adjacency relation of vertices in a graph is represented


in a table Adj(x,y) which of the following queries can not be
expressedby a relational algebra expressions of constant length?
a.List of all vertices adjacent to a given matrix
b.List of all vertices which have self loops
c.List of all vertices which belong to cycle of less than three vertices.
d.List of all vertices reachable from a given vertex
Ans:D

27.Consider the schema R=(S T U V) and the dependencies S->T, T->U,


U->V and V-> S. Let (R1 and R2) be a decomposition such that
R1-> R2={}(null set). The decomposition is:
a.not in 2NF b.in 2 NF but not in 3 NF
c.In 3 NF but not in 2 NF d.In both the 2NF and 3NF
Ans:D

28.Given the functional dependencies x->w; x->y; y->Z and Z->pq


which of the following does not hold good?
a.x->Z b.W->Z c.X->WY d. None
Ans:B

29.Every determinant should be a candidate key is the definition of


---------- Normal form:
a. Project-join NF b.Second NF c.BCNF d.3NF
Ans:C

30.Blocking factor refers to


a.The number of blocks that can be accommodated in a sector
b.The number of records that can be accommodated in a block
c. The number of blocks into which the file is divided
d.The number of files that can fit into a single block
Ans:B

31.In Query-Ny-Example, the query formed from


the relations displayed by filling in the following.
a.SQL form b.Templates c.DML d.DDL
Ans:B

32.SQL is relationally?
a. complete language b.incomplete language
c.Cant handle certain relations d.Sound language
Ans:A

33.Given relations r(w,x) and s(y,z) the result of


Select distinct w,x from r, s is guaranteed to be the same as r, provided:
a.r has no duplicates and is non-empty
b.r and s have no duplicates
c.s has no duplicates and r is non empty
d.r and s have the same number of tuples
Ans:A

34.In SQL relations can contain null values, and comparisons with null values
are treated as unknown suppose all comparisons with a null value are
treated as false. Which of the following pairs is not equivalent?
a.x=5 not (not(x=5)) b.x=5 x>4 and x<6, where x is an integer
c.x!=5 and not(x=5) d. none
Ans:C

Ramesh 76 Ramesh
DBMS Questions
35.Relation R is decomposed using a set of functional dependencies F,
and relation S is decomposed using another set of functional
dependencies, G.One decomposition is definitely BCNF, the other is
definitely 3NF, but it is not know which is which. To make
guaranteed identification, which one of the following tests
should be used on the decompositions?
(Assume the closure of F and G are available)
a.Dependency-preservation b.Lossless-Join
c.BCNF definition d.3NF definition
Ans:B

36.From the following instance of a relation schema R(A,B,C), we can


conclude that
A B C
1 1 1
1 1 0
2 3 2
2 3 2

a.A functionally determines B and B functionally determines C


b.A functionally determines B and B does not functionally determine C
c.B does not functionally determine C
d.A does not functionally determines B and B does not functionally determine C
Ans:A

37.The level of abstraction describes only part of the entries database is called
a.Physical level b.Conceptual level c.View level d.Procedural level
Ans:C

38.The maximum height of a B+ tree of order n with k key value is


a.(n+k)/2 b. log nk c.log n/2 (k/2+1) d.Log k/2n
Ans:C

39.Which of the following are correct


a.Range queries are faster on B+ tress
b. B-trees are for storing data on disk and B+ tress are for main memory
c.B-trees are for primary indexes and b+ trees are for secondary indexes
d.The height of a B+ tress is independent of the number of records
Ans:A

40.The file organization techniques which includes an


index on every secondary field is :
a.Inverted organization b.Multi list Organization
c.Regular Organization d. Hierarchical organization
Ans:A

41.The database and DBMS software together is called as?


a.Database System b.Database Management System c.Data software d.none
Ans:A

42.The highest level of abstraction describes only part of entire database?.


a.Physical level b.Logical level c.View level d.None
Ans:C

43. The level of abstraction describes how data are stored.?

Ramesh 77 Ramesh
DBMS Questions
a.Physical level b.Logical level c.View level d.None
Ans:A

44.?The application is independent of the storage structure


and access strategy of data? is called ?
a.Data Independence b.Physical Data Independence
c.Logical Data Independence d.none
Ans:A

45.A collection of conceptual tools for describing data, data


relationships data semantics and constraints is called?
a.Data Model b.E-R model c.View d.none
Ans:A

46.The collection (set) of entities that have same attributes is called?


a.Entityset b.Entity c.Entity type d.none
Ans:C

47.What is an Extension of entity type?


a.collection of all entities of particular entity type in the database.
b.collections of entities of a particular entity type are grouped together
into an entity set.
c.collection (set) of entities that have same attributes.
d.It is a 'thing' in the real world with an independent existence.
Ans:B

48.The number of entity type participating is called?.


a.Relationship type b.Relationship set
c.degree of a Relation d.degree of Relationship type
Ans:D

49.A data base schema is specifies by a set of definitions


expressed by a special language called ?
a.View Definition Language b.Data Definition Language
c.Storage Definition Language d.none
Ans:B

50.The language that is to specify the internal schema is..?


a.View Definition Language b.Data Definition Language
c.Storage Definition Language d.none
Ans:C

51.Extend DML
a.Data Multiple Language b.Data Manipulation Language
c.Data Multiplex Language d.Data Model Language
Ans:B

52.Which of the following executes low-level instruction


generated by compiler.. ?
a.DML Compiler b.DDL Interpreter
c.Query evaluation engine d. Non-Procedural DML
Ans:C

53.The process of analysing the given relation schemas based


on their Functional Dependencies (FDs) and primary key
to achieve the properties is..?
a.normalization b.Functional Dependency
c.Multivalued dependency d.none
Ans:A

Ramesh 78 Ramesh
DBMS Questions
54.The domain of attribute must include only atomic
(simple, indivisible) values in
a.1 NF b.2 NF c.3 NF d.4NF
Ans:A

55.What is BCNF (Boyce-Codd Normal Form)?


a.relation schema R is in BCNF if it is in 1NF and satisfies
an additional constraint that for every FD X A, X must
be a candidate key
b.relation schema R is in BCNF if it is in 2NF and satisfies an
additional constraint that for every FD X A, X must
be a candidate key
c.relation schema R is in BCNF if it is in 4NF and satisfies an
additional constraint that for every FD X A, X
must be a candidate key
d.relation schema R is in BCNF if it is in 3NF and satisfies an
additional constraint that for every FD X A, X
must be a candidate key
Ans:D

56.Advantages of DBMS?
a.Redundancy is controlled b.Enforcing integrity constraints.
c.Data isolation. d.Both Redundancy is controlled & Enforces integrity constraints
Ans:D

57.The number of tuples present in a table at any instance is called?


a.Intension b.Extension
c.Both Intension & Extension d.Neither Intension nor Extension
Ans:B

58.Which Data Independence is more difficult to achieve?


a.Physical Data Independence b.Logical Data Independence
c.Both Physical Data Independence & Logical Data Independence
d.can't say exactly
Ans:B

59.DML requires a user to specify what data are needed


without specifying how to get those data is...?
a.High level DML b.Non-Procedural DML
c.Procedural DML d.Both High level DML & Non-Procedural DML
Ans:D

60.DML requires a user to specify what data are needed


and how to get those data.
a.High level DML b.Non-Procedural DML
c.Procedural DML d.Both High level DML & Non-Procedural DML
Ans:C

DBMS-2 Questions
1) What is a query?

Exp: A query with respect to DBMS relates to user commands that are used
to interact with a data base. The query language can be classified into data
definition language and data manipulation language..

Ramesh 79 Ramesh
DBMS Questions

2)What do you mean by Correlated subquery?

Exp: :Subqueries, or nested queries, are used to bring back a set of rows to
be used by the parent query. Depending on how the subquery is written, it can be
executed once for the parent query or it can be executed once for each row returned
by the parent query. If the subquery is executed for each row of the parent, this
is called a correlated subquery.A correlated subquery can be easily identified if
it contains any references to the parent subquery columns in its WHERE clause.
Columns from the subquery cannot be referenced anywhere else in the parent query.
The following example demonstrates a non-correlated subquery.

Eg. Select * From CUST Where '10/03/1990'


IN (Select ODATE From ORDER Where CUST.CNUM = ORDER.CNUM).

3)What are the different phases of transaction?

Ans :

1. Analysis phase
2. Redo Phase
3. Undo phase

4)What are the primitive operations common to all record management systems?

Ans :Addition, deletion and modification..

5)Name the buffer in which all the commands that are typed in are stored.?

Ans :‘Edit’ Buffer.

6)What are the unary operations in Relational Algebra?

Ans :PROJECTION and SELECTION..

7)Are the resulting relations of PRODUCT and JOIN operation the same?

Ans :No.

Exp:PRODUCT: Concatenation of every row in one relation with every row in another.
JOIN: Concatenation of rows from one relation and related rows from another..

8)Name the sub-systems of a RDBMS?

Ans :I/O, Security, Language Processing, Process Control, Storage Management,


Logging and Recovery, Distribution Control, Transaction Control, Memory Management,

Ramesh 80 Ramesh
DBMS Questions
Lock Management.

9)What is RDBMS KERNEL?

Ans :Two important pieces of RDBMS architecture are the kernel, which is the s
oftware, and the data dictionary, which consists of the system-level data structures
used by the kernel to manage the database. You might think of an RDBMS as an operating
system (or set of subsystems), designed specifically for controlling data access;
its primary functions are storing, retrieving, and securing data. An RDBMS maintains
its own list of authorized users and their associated privileges; manages memory
caches and paging; controls locking for concurrent resource usage; dispatches and
schedules user requests; and manages space usage within its table-space structures.

10)Which part of the RDBMS takes care of the data dictionary?

Ans :Data dictionary is a set of tables and database objects that is stored in a
special area of the database and maintained exclusively by the kernel..

11)What is the job of the information stored in data-dictionary?

Ans :The information in the data dictionary validates the existence of the objects,
provides access to them, and maps the actual physical storage location

12)How do you communicate with an RDBMS?

Ans :You communicate with an RDBMS using Structured Query Language (SQL).

13)Define SQL and state the differences between SQL and other conventional programming
Languages ?

Ans :SQL is a nonprocedural language that is designed specifically for data access
operations on normalized relational database structures. The primary difference between
SQL and other conventional programming languages is that SQL statements specify what
data operations should be performed rather than how to perform them. .

14)Name the three major set of files on disk that compose a database in Oracle?

Ans:There are three major sets of files on disk that compose a database. All the
files are binary.
1. Database files
2. Control files
3. Redo logs
Exp:The most important of these are the database files where the actual data resides.
The control files and the redo logs support the functioning of the architecture
itself. All three sets of files must be present, open, and available to Oracle for
any data on the database to be useable. Without these files, you cannot access the
database, and the database administrator might have to recover some or all of the
database using a backup, if there is one..

Ramesh 81 Ramesh
DBMS Questions
15)What are the four Oracle system processes that must always be up and running
for the database to be useable ?

Ans :The four Oracle system processes that must always be up and running for the
database to be useable include
1. DBWR (Database Writer)
2. LGWR (Log Writer)
3. SMON (System Monitor)
4. PMON (Process Monitor).

16)What is database Trigger?

Ans :A database trigger is a PL/SQL block that can defined to automatically execute
for insert, update, and delete statements against a table. The trigger can e defined
to execute once for the entire statement or once for every row that is inserted,
updated, or deleted. For any one table, there are twelve events for which you can
define database triggers. A database trigger can call database procedures that
are also written in PL/SQL. .

17)Name two utilities that Oracle provides, which are use for backup and recovery.

Ans :1. The Export utility dumps the definitions and data for the specified part
of the database to an operating system binary file.
2. The Import utility reads the file produced by an export, recreates the
definitions of objects, and inserts the data.

18)What are stored-procedures?

Exp::Stored procedures are database objects that perform a user defined operation.
A stored procedure can have a set of compound SQL statements. A stored procedure
executes the SQL commands and returns the result to the client. Stored procedures
are used to reduce network traffic..

19)Why do Spurious tuples occur ?

Ans :Bad normalization & Updating tables from join because theta joins are joins
made on keys that are not primary keys..

20)What is Storage Manager?

Ans :It is a program module that provides the interface between the low-level
data stored in database, application programs and queries submitted to the system.

21)What is Buffer Manager?

Ans :It is a program module, which is responsible for fetching data from disk
storage into main memory and deciding what data to be cache in memory. .

Ramesh 82 Ramesh
DBMS Questions
22) What is Transaction Manager?

Ans :It is a program module, which ensures that database, remains in a consistent
state despite system failures and concurrent transaction execution proceeds
without conflicting

23)What is File Manager?

Ans :It is a program module, which manages the allocation of space on disk
storage and data structure used to represent information stored on a disk.

24)What is Authorization and Integrity manager?

Ans :It is the program module, which tests for the satisfaction of integrity
constraint and checks the authority of user to access data..

25)What are stand-alone procedures?

Exp::Procedures that are not part of a package are known as stand-alone because
they independently defined. A good example of a stand-alone procedure is one
written in a SQL*Forms application. These types of procedures are not available
for reference from other Oracle tools. Another limitation of stand-alone procedures
is that they are compiled at run time, which slows execution..

26)What are cursors give different types of cursors.?

Ans :PL/SQL uses cursors for all database information accesses statements.
The language supports the use two types of cursors
1. Implicit
2. Explicit.

27)What do you understand by dependency preservation?

Ans :Given a relation R and a set of FDs F, dependency preservation states that
the closure of the union of the projection of F on each decomposed relation Ri is
equal to the closure of F. i.e., ((?R1(F)) U … U (?Rn(F)))+ = F+ if decomposition
is not dependency preserving, then some dependency is lost in the decomposition..

28)What is meant by Proactive, Retroactive and Simultaneous Update?

Exp:Proactive Update: The updates that are applied to database before it becomes
effective in real world .
Retroactive Update: The updates that are applied to database after it becomes
effective in real world .
Simulatneous Update: The updates that are applied to database at the same time
when it becomes effective in real world ..

29)What operator performs pattern matching?

Ramesh 83 Ramesh
DBMS Questions
Ans :LIKE operator.

30)What operator tests column for the absence of data?

Ans :IS NULL operator.

31)Which command executes the contents of a specified file?

Ans :START or @.

32)What is the parameter substitution symbol used with INSERT INTO command?

Ans :&.

33)Which command displays the SQL command in the SQL buffer, and then executes it?

Ans :RUN.

34)What are the wildcards used for pattern matching?

Ans :_ for single character substitution and % for multi-character substitution.

35)State true or false. EXISTS, SOME, ANY are operators in SQL.?

Ans :True.

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

Ans :True.

37)What are the privileges that can be granted on a table by a user to others?

Ans :Insert, update, delete, select, references, index, execute, alter, all.

38)What command is used to get back the privileges offered by the GRANT command?

Ans :REVOKE.

39)Which system tables contain information on privileges granted and privileges


obtained?

Ans :USER_TAB_PRIVS_MADE, USER_TAB_PRIVS_RECD.

Ramesh 84 Ramesh
DBMS Questions

40) What is the difference between TRUNCATE and DELETE commands?

Ans :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

41) What command is used to create a table by copying the structure of another table?

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

42) What will be the output of the following query?


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

Ans :TROUBLETHETROUBLE

43) What will be the output of the following query?


SELECT DECODE(TRANSLATE('A','1234567890','1111111111'), '1','YES', 'NO' );?

Ans :NO
Explanation : The query checks whether a given string is a numerical digit..

44) What does the following query do? SELECT SAL + NVL(COMM,0) FROM EMP;?

Ans :This displays the total salary of all employees. The null values in the
commission column will be replaced by 0 and added to salary..

45) Which date function is used to find the difference between two dates?

Ans :MONTHS_BETWEEN.

46) Why does the following command give a compilation error? DROP TABLE &TABLE_NAME

Ans :Variable names should start with an alphabet. Here the table name starts
with an '&' symbol

47) What is the advantage of specifying WITH GRANT OPTION in the GRANT command?

Ans :The privilege receiver can further grant the privileges he/she has obtained
from the owner to any other user

48) What is the use of the DROP option in the ALTER TABLE command?

Ans :It is used to drop constraints specified on the table..

Ramesh 85 Ramesh
DBMS Questions

49) What is the use of DESC in SQL?

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

50) What is the use of CASCADE CONSTRAINTS?

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

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

Ans :FLOOR.

52) What is the output of the following query? SELECT TRUNC(1234.5678,-2) FROM DUAL;

Ans :1200.

Ramesh 86 Ramesh

You might also like