introduction to rdbms and oracle 8i snapshots · • introduction to dbms • database • the 12...
Post on 22-Jul-2020
25 Views
Preview:
TRANSCRIPT
Notes 4 Session 4
Customs Receipt Online Audit 1
Introduction to RDBMS and Oracle 8i
Snapshots
• Models Approaches to Data Management
• Database Management - An Evolutionary Phenomenon
• Introduction to DBMS
• Database
• The 12 Rules (Codd's Rule) for an RDBMS
Database Design
Data Modeling
Entity Relationship Diagram Dependent Entities
Subsets and Supersets
Degree of Relationship
Normalization
• Relational Database Management System (RDBMS)
• Features of Oracle 8i
• Oracle 8i as an Object Oriented Database Management System (OODBMS)
• Oracle Server and Oracle Database
• Network Computing Architecture (NCA)
• CORBA
• Oracle Products
Notes 4 Session 4
Customs Receipt Online Audit 2
Objectives After studying this chapter, one should be able to:
• Understand the features of a Object Oriented Database Management (OODBMS)
• Design Databases
• Draw E-R Diagrams
• Normalize Data Structures
• Understand Oracle Server and Oracle Database
• Understand Oracle 8i as an Object Oriented Database Management System (OODBMS)
• Understand Network Computing Architecture (NCA) Approaches to Data Management
• Manual methods of Data Management of Data and Information
• Convenient and efficient retrieval Updating Operations • Limitation of Manual Data Management
• Physical Volume of Data
• Human Processing of Data
• Technological Advancement in Data Management
• Using Computers to speed up processing of Data
• Advancement of Processing Power
• Using time-sharing for multiple users
• High-speed storage devices
• Centralized to distributed databases
• Centralized to distributed Processing (Client/Server)
Notes 4 Session 4
Customs Receipt Online Audit 3
Excellent Book keeping strategies existed before the computer age, on the
management of data, including convenient and efficient retrieval and update operations.
Due to the limitations associated with the physical handling of documents and human
processing, a look in retrospect suggests that data and information generated through
data were only marginally used in daily decision-making, even in progressive
organizations.
The application of computers speeds up the data processing activities and adds
some flexibility to the management of data and the information generated from it.
Widespread and easy access to time sharing systems advances in logical and physical
access methods, matched by steep increase in the density and volume of disk storage
devices, led gradually to a reassessment of the role of data in management decision
making.
This transition was facilitated by the induction of database technology into the
organizations. The emerging discipline of distributed database management is able to
eliminate the constraints of geographic distribution of decision nodes.
Database Management: An Evolutionary Phenomenon
• The evolution of database management was accompanied and promoted by:
• Advances in computing: Hardware, OS and Networking
• Drawbacks of the prevalent approach to Data Management
Data redundancy Risk to data integrity Data isolation Difficult access to data Unsatisfactory security measures Poor support of parallel access of
data
Earlier, organizations followed the fragmented approach to data processing by
Notes 4 Session 4
Customs Receipt Online Audit 4
designing files to specifically suit different application systems. Since the different
functional units (departments) in an organization have large amounts of data to share,
this approach, inevitably leads to some major disadvantages as discussed below.
Data Redundancy- Since the files and application programs are written over a long
period of time, data in the files is likely to get repeated. This may also lead to
inconsistency i.e., the various copies of the same data may contain different
information. Data redundancy could also occur due to duplication of data at
different locations - the need for the same data at physically different locations.
Risk to data integrity-The data values stored, must satisfy certain integrity
constraints. These constraints can be enforced in the system, by adding appropriate
code in the application programs. The problem is compounded when constraints
involve several data items from different files.
Data isolation-Since data is scattered in various files, and files may be in different
formats, it is difficult to write new application programs to retrieve the appropriate
data.
Difficult access to data- whenever there is a new request that was not anticipated
earlier, there are two possible solutions. Either extract the records manually by
mentioning the indexes, access methods, or have the system programmer write the
necessary application again with minor changes. This leads to the repeated task of
programmers for daily requirements.
Unsatisfactory security measures-Every user of the system should be allowed to
view only that part of the data that is relevant to his department. Since application
programs are added to the system in an ad hoc manner, it is difficult to enforce such
integrity constraints.
Notes 4 Session 4
Customs Receipt Online Audit 5
Concurrent access-Many systems allow multiple users to update the data
simultaneously to improve the overall performance of the system and obtain a faster
response. But in such an environment interaction of concurrent updates may result
in inconsistent data. Since the application programs, which have not been previously
coordinated, are used to access data, supervision is very difficult to provide.
Database management addressed all these problems, though at the price of
increased overheads and costs.
However, with the advancement of technology and the all-round development
made in Hardware, Software, Networking and Operating Systems, the drawbacks of
Data Management have been eliminated to a great extent.
Notes 4 Session 4
Customs Receipt Online Audit 6
Introduction to DBMS
A Programmer's Productivity Tool
o Good User interface
o Powerful Database Structure
o Advancement of Data Manipulations
o Use of 4 GL Tools
A discipline towards data independence
o Logical Data Independence
o Physical Data Independence
Data View
o External View
o Conceptual View
o Internal View
Concept of a DBMS
A database is a collection of interrelated data from which some information can
be extracted. The collection of data must be logically coherent with some inherent
meaning. A database is designed and built for a specific purpose, keeping in mind the
needs of the applications that are going to use it and the end users of those applications.
It is managed by a software package known as a Database Management System
(DBMS).
A DBMS is a general-purpose software system that enables users to define and
manipulate databases. It provides an environment, wherein, data can be stored and
retrieved from databases easily and most efficiently. The DBMS is the software used to
Notes 4 Session 4
Customs Receipt Online Audit 7
create and maintain the database.
Database Models
Hierarchical
Network
Relational Hierarchical Model
This model was introduced in the Information Management System (IMS)
developed by IBM in 1968. This model is like a hierarchical tree structure, used to
construct a hierarchy of records in the form of nodes and branches. The data elements
present in the structure have a Parent-Child relationship. Closely related information
in the parent-child structure is stored together as a logical unit. A parent unit may have
many child units, but a child is restricted to have only one parent. This leads to the
repetition of same child record for different parents.
The drawbacks of this model are:
The hierarchical structure is not flexible enough to represent all the relationship
proportions, which occur in the real world.
It cannot demonstrate the over all data model for the enterprise because of the non-
availability of actual data at the time of designing the data model.
It cannot represent the Many-to-Many relationship.
The Hierarchical model is used only when the concerned data has a clearly
hierarchical character with a single root, for example the D08 directory structure.
Network Model
It is an improvement on the hierarchical model. Here multiple parent-child
relationships are used. Rapid and easy access to data is possible in this model due to
Notes 4 Session 4
Customs Receipt Online Audit 8
multiple access paths to the data elements.
Fig. 1.2
Fig. 1.2 shows a network view for the suppliers-and-parts database. In this view,
as in the hierarchical approach, data is represented by records and links. However, a
network is a more general structure than a hierarchy because a given record occurrence
may have any number of immediate superiors and dependents - we can have more than
one, unlike hierarchical. The network approach thus allows us to model a many to many
correspondence. In addition to the record types representing the suppliers and parts
themselves, we introduce a third type of record, which we will call the connector.
A connector occurrence, represents the association (shipment) between one
supplier and one part, and contains data describing the association. All connector
occurrences for a given supplier or part are placed on a chain starting at and returning to
that supplier or part. Each connector thus has exactly two chains, one supplier and one
part chain. For example Fig. 1.2 shows that supplier 802 supplies 250 of part P02 and
100 of part P01; similarly it shows that part P01 is supplied in a quantity of 150 by
supplier 801 and quantity of 300 by supplier 803. Note that the correspondence
between, say, one supplier and the associated connector records is one-to-many, which
shows that hierarchies may easily be represented in a network system.
Transaction is maintained using pointers and tracing the pointers is the drawback of this
Notes 4 Session 4
Customs Receipt Online Audit 9
design.
Relational Model
Data is organized in terms of rows and columns in a table known as relations
The position of a row in a table is of no importance
The intersection of a row and column must give a single value and not a set of
values
All values appearing in the columns are derived from the underlying schema
Row must be unique
Column Names must be unique
All column values are atomic
In relational database, there are no hard-coded relationships defined between tables.
A relationship can be specified at any time using any column name.
The publication of the paper "A Relational Model of Data for Large Shared
Databases" by E.F. Codd in June 1970 in the "Communication of ACM” set a trend for
vigorous and extensive investigation into a theoretical frame work to support further
work in the area of Data Modeling. The end result is the Relational Database
Management Systems (RDBMS).
In RDBMS, the data is organized in tables consisting of rows and columns. Supplier
Supplier Supplier Supplier City Code Name Status Supplier
S01 Ram 15 Calcutta S02 Shyam 20 Chennai S03 Amit 25 HyderabadS04 Rajesh 15 Mumbai
Notes 4 Session 4
Customs Receipt Online Audit 10
Parts
PCode PartName Weight CityP01 Screw 8 Calcutta P02 Nut 16 Chennai P03 Bolt 20 Hyderabad P04 Nut 16 Mumbai
Shipment
Scode Pcode Qty S01 P01 150 S01 P02 200 S02 P03 250 S02 P04 100 S03 P01 300
Consider the tables shown in the sample database. In table SHIPMENT, each
supplier status has a unique supplier code which uniquely identifies the entire row of the
table and exactly one name, and city. Likewise each part has a unique PCode and
exactly one name, size and city and at any given time no more than one shipment exists
for a given supplier/part combination.
The term 'Relation' is used to describe these tables, which is a more precise way
of defining than the traditional data processing term "file" or "table". Rows of such
tables are referred to as tuples, again a more precise definition than rows or records and
columns are referred to as attributes. A domain is a set of values from which actual
values appearing in a given column are drawn. For example, the values appearing in the
part column of both parts and shipment tables are drawn from the underlying domain of
all valid part numbers. This domain itself may not be explicitly recorded but will be
defined in the appropriate schema and will have a name of its own. We can see that the
related supplier and parts have a domain in common; so do parts and shipment; so do
supplier and shipment.
Notes 4 Session 4
Customs Receipt Online Audit 11
Another important concept in relation database is that relationships between
tables are not hard-coded in the structure of the data. There is no pointer in the data to
relate one table to another. The relationship between two or more sets of data can be
specified at the development time rather than when the tables are first created. This
greatly improves the flexibility of the database management system.
In relational data structure is that association between tuples are represented
solely by data values in columns drawn from a common domain. The fact that supplier
S03 and P02 are located in the same city is represented by the appearance of the same
value in the city column for the two tuples.
Properties of Relational Database A relational database management system (RDBMS) has the following properties:
Represents data in the form of tables.
Does not hard-code relationships between tables.
Does not require the user to understand its physical implementation Provides
information about its content and structure in system table
Supports the concept of NULL values.
The 12 Rules for an RDBMS (Codd's Rule)
Information Representation
Guaranteed Access
Systematic Treatment of Null Values
Database Description Rule
Comprehensive Data Sub-Language
View Updating
High-Level Update, Insert, Delete
Physical Data Independence
Logical Data Independence
Notes 4 Session 4
Customs Receipt Online Audit 12
The Distribution Rule
Non-Subversion
Integrity Rule E.F. Codd formulated 12 rules for RDBMS in 1970. In addition to the 12 rules, there exists a rule, called rule zero, which states: A relational system must be able to manage databases entirely through its relational capabilities. Any DBMS that advises users to the some non-relational methods to achieve acceptable performance should be interpreted as an apology by the vendor".
Information Representation
In the relational model all the information is explicitly and logically represented
by the data values in the tables. This means that even such information as table, view,
column names etc. should be contained somewhere as a table form. This makes it
necessary for the provision of an active data dictionary that, itself is relational in nature.
Some systems implement their dictionary information systems in a file structure.
However, these systems cannot be called truly relational in nature because of their lack
of ability to store metadata (data about data) in an integrated relational form.
Guaranteed Access
This rule refers to the fact that the table can be taken as a storage structure and at
the intersection of each column and row there will necessarily be only one value of data
(or null). Every value of data must be logically addressable by using a combination of
table name, primary key value and column name.
Systematic Treatment of Null Values
In database management systems null values are supported for the representation
of missing and inapplicable information. This support for null values must be consistent
throughout the DBMS, and independent of data types (for example, a null value in char
field must mean the same as in an integer field).
Notes 4 Session 4
Customs Receipt Online Audit 13
In some systems for instance, a character is used to represent missing or
inapplicable data. This has been allocated from the domain of characters pertinent to a
particular value.
Database Description Rule
A description of the database is stored and maintained in the form of tables as is
done while defining the data. This allows the users with appropriate authority to query
such information in the same ways and using the same languages as they would any
other data in the database. This implies that a data dictionary should be present within
the RDBMS that is constructed of tables and/or views that can be examined using the
SQL.
Comprehensive Data Sub language
The RDBMS must be completely manageable through its own extension of
SQL, although some systems still support SQL-like-language (e.g., Ingress supports
Ouel). SQL should support Data Definition, Views, Data Manipulation, Integrity
Constraints, Authorization, and Transaction Boundary.
View Updating
It is a myth that all views that can be updated in theory can also be updated by
the system itself. Though it is possible to create views with all sorts of aggregates and
virtual columns, it is obviously not possible to update through some of them. The
possible complexity of a view cannot be assessed in logical terms, simply because a
view can be defined in terms of both tables and other views. However, there exists a set
of rules that, when applied to a view, can be used easily to determine its level of logical
complexity. It is only realistic and practical to apply these rules to those views that are
defined as simple by such criteria.
Notes 4 Session 4
Customs Receipt Online Audit 14
High-Level Update, Insert, Delete
An RDBMS must do more than just be able to retrieve relational data sets. It has
to be capable of inserting, updating and deleting data as a relational set. A database
cannot be called relational, if it uses a single-record-at-time procedural technique when
it comes to manipulating the data.
Physical Data Independence
User access to database, via monitors or application programs, must remain
logically consistent even when changes to the storage representation, or access methods
to the data are changed. Application must be limited to interfacing with the logical layer
to enable the enforcement of this rule. However a lot of care has to be taken in a case
like this. Programmers may not check for the primary key uniqueness in his application,
because he knows it is enforced by a unique index. A removal of such an index might
be catastrophic, but it does not constitute breaking of this rule.
Logical Data Independence
Application programs must be independent of the changes made to the base
tables. This rule allows many types of database design changes to be made dynamically,
without the users being aware of them. A single table should be divisible into one or
more other tables, provided it preserves all the original data (non-loss), and maintains
the primary key in each and every fragment table.
The Distribution Rule
An RDBMS must have distribution independence. This is one of the most
attractive aspects of the RDBMS. Database systems built on the relational framework
are well suited to today's Client / Server database design.
Notes 4 Session 4
Customs Receipt Online Audit 15
Non-Subversion
If an RDBMS supports a lower level language that permits for example, row-at-
a-time processing, then this language must not be able to bypass any integrity rules or
constraints of the relational language. Thus, an RDBMS must be governed by relational
rules as its primary laws.
Integrity Rule
Integrity constraints specific to a particular relational database must be definable
in the relational data sub-languages and storable in the catalogue, not in the application
programs.
An RDBMS product has to satisfy at least six of the 12 rules of Codd to be accepted as a full-fledged RDBMS.
Database Design
Requirement Formulation and Analysis
Collection and Documentation of Requirement
Analysis of Requirement Conceptual Design
Data Modeling
First Level E-R Modeling
Second Level Normalization
E-R Modeling
Physical Design and Implementation
Requirements Formulation and Analysis
The primary input to the database design process is the organization's statement
Notes 4 Session 4
Customs Receipt Online Audit 16
of requirements. Poor definition of these requirements is a major cause of poor database
design, resulting in databases of limited scope and utilities which are unable to adapt to
change.
Requirement analysis is the process of identifying and documenting the data the
user requires in the database to meet present and future information needs. During this
phase, the analyst studies data flows and decision making processes in the organization
and works with the users.
The objective of this phase is to answer the following questions:
What are user-views of the data (present and future)?
What data elements (or attributes) are required in these user-views?
What are the entities and their primary keys?
What are the operational requirements regarding Security, Integrity and Response
time?
Conceptual Design
The major step in conceptual design is to identify the entities and relationships
that reflect the organization's data, 'naturally'. The objective of this step is to specify the
conceptual structure of the data and is often referred to as data modeling. The E-R
model, with an emphasis on the top-down approach, will be discussed as an information
model to develop a conceptual structure, later in this chapter.
Data Modeling Describes relationships between data objects
First Level - Entity-Relationship Diagrams
Second Level - Normalization
Notes 4 Session 4
Customs Receipt Online Audit 17
The relationships between the collections of data in a system may be graphically
represented using data modeling. If the relationships are complex, data modeling
provides a simplified approach to the structured design of the system. It helps determine
the data objects in the system, the composition of each, and the relationships that exist
between them.
Data Modeling is achieved in two levels - the first level builds the conceptual
model of the data, using E-R Modeling. The second level organizes this model better,
by removing redundancies, through a process called Normalization. The Normalized
model is then converted into the Physical Database.
Entity
An entity is any object, place, person, concept, activity about which an
enterprise records data. It is an object, which can have instances or occurrences. Each
instance should be capable of being uniquely identified. Each entity has certain
properties, or Attributes associated with it and operations applicable to it. An entity is
represented by a rectangle in the E-R Model.
Categories of objects under which an entity is identified:
Entity type and entity instance are two important terms related to entities. An
entity type is a set of things, which share common properties. For e.g., STUDENT,
COURSE etc. An entity type is usually denoted in upper case. An entity instance is a
specific individual thing. For e.g., "Mohit", "Physics". An entity instance is usually
Notes 4 Session 4
Customs Receipt Online Audit 18
denoted in lower case.
Attributes
Attributes are data elements that describe an entity. If the attribute of an entity
has more attributes that describe it, then it is not an attribute of that entity, but another
entity. Attributes can either be listed next to the entities, or placed in circles and
attached to the entities.
Similarly, Attributes can also describe properties of Relations. Example:
Entity Attributes Customer Name, Address, Status Book ISBN, Title, Author, Price
Order Order Number, Order Date, Placed by
Identifier is one or more attributes of an Entity or Relation, whose value
uniquely identifies the entities or relationships. The identifier attributes are underlined
in the diagram.
Example:
PERSON: Person ID Name DOB
PROJECT: PROJECT ID START_DATE BUDGET Relationship
This is an association between entities. It is represented by a diamond in the E-R
diagram. For e.g., there is a relationship between student and course. This relationship
represents the fact that a student enrolls in a course. This relationship could be named as
Notes 4 Session 4
Customs Receipt Online Audit 19
enrolls in. Relationships can also have properties or Attributes associated with it. The
attributes may be listed next to the relation, as mentioned earlier.
Entity Attributes Student ID, Name, Address, DOB
Course Course Code, Duration, Start Date, Room No.
A relationship may associate an entity with itself. For example, in a company,
one employee may marry another employee. Hence the following relationship can be
possible.
Several relationships may exist between the same entities. For example
Dependent Entities Depend on the existence of a parent entity
Also known as weak entities
Have composite identifiers, one from parent and another of its own
There are two types of entities, dependent and independent. An entity whose
existence depends on the existence of another entity is called a dependent entity.
Consider the entity type OFFERING. A course with same code can be offered in
different semesters and different campuses. The existence of OFFERING depends on
the existence of entity type COURSE. The dependent entity is depicted in the E-R
Notes 4 Session 4
Customs Receipt Online Audit 20
diagram by a rectangular box with a second line drawn across the top.
Dependent entities have composite identifiers. The identifier consists of the
identifier of the parent entity, together with another attribute that uniquely identifies the
dependent entity with the parent.
Example: PROJECT-ID DATE-STARTED
PROJECT-ID TASK-NO BUDGET
The figure depicts entities PROJECTS and TASKS. A task obviously cannot be
present without the existence of a related Project. The entity Task is thus modeled as a
Dependent Entity of the Project Entity. The dependence is shown by the arrow from
PROJECTS to TASKS.
Thus the identifier of TASKS is composed of the attributes, PROJECT-ID
(which identifies the project) and TASK-NO (which identifies the particular task in the
project). Every task in a project may be assigned a Budget, which becomes an attribute
of the Task.
An independent entity does not depend on any other entity for existence. For e.g. STUDENT Subsets and Supersets
Derived from parent entities called supersets
Formed when occurrences of the superset are treated in different ways
Modeled by rectangular boxes, with a second line on the left hand side of the
Notes 4 Session 4
Customs Receipt Online Audit 21
box
Common attributes among subsets are attributes of the Superset
Attributes pertaining to each subset, become attributes of that subset
Identifier of a subset is the identifier of the Superset
A subset is derived from another entity, which is called superset. For example,
consider the entity EMPLOYEE. There are two types of employees - salaried
employees and wage earning employees. In this example, EMPLOYEE is the superset,
and the SALARIED and WAGE-EARNING employees are the subset. Subsets have
certain attributes of their own, which are unique to them. They also share some
attributes with the other subsets.
The common attributes become attributes of the parent entity set, whereas
attributes pertaining to the subset alone are shown as attributes of that subset. For
example, "name', "address" are common attributes of subset SALARIED and WAGE.
So they become attributes of the parent entity set EMPLOYEE.
WAGE-EARNING employees will have some attributes, like "overtime", "daily
wages" that do not belong to the subset SALARIED. The subset SALARIED has some
attributes like HRA, BASIC, ALLOWANCE that do not belong to the subset WAGE-
EARNING.
Notes 4 Session 4
Customs Receipt Online Audit 22
A sub entity or subset is always dependent on the super entity or superset for its
existence. The attributes of superset apply to al/ of its subsets. The converse is not true.
Degree of Relationship
One to One (1:1)
One to Many (1: N)
Many to Many (M: N)
The Degree of a Relationship indicates the link between two entities for a
specified occurrence of each. The degree of a relationship is also called Cardinality.
One to One Relationship: (1: 1) One Order Requisition raises one purchase order.
One purchase order is raised by one order requisition.
For one occurrence of the first entity, there can be at most one related occurrence of the
second entity, and vice-versa.
One to Many Relationships: (1: N)
One employee works in at most one department. One Department can have many employees.
For every occurrence of the first entity, there can exist many related occurrences of the
second entity and for every occurrence of the second entity there exists only one
associated occurrence of the first.
Many to Many Relationships (M: N) One order may contain many items. One item can be contained in many orders
Notes 4 Session 4
Customs Receipt Online Audit 23
For one occurrence of the first entity, there exists many related occurrences of the
second entity and for every occurrence of the second entity, there may exist many
associated occurrences of the first.
Example: An organization has employees assigned to specific departments. The employees may work on several projects at the same time. The project uses parts, which are supplied by different suppliers, and stored, in various warehouses. Normalization
Refinement of the E-R Model
Segregation of data over many entities or tables
Normalized model converted to physical database tables
Normalization is the process of refining the data model built by the Entity-
Relationship diagram. The Normalization technique, logically groups the data over a
number of tables, with minimum redundancy of data. The entities or tables resulting
from Normalization contain data items, with relationships being represented by
replication of key data item(s).
The goal of a relational database design is to generate a set of relation schemes
that allow us to store information with minimum redundancy of data and allow us to
retrieve information easily and efficiently. The approach followed is to design schemes
that are in an appropriate form one of the so-called Normal form.
The first step towards Normalization is to convert the E-R Model into Tables or
Relations. The next step is to examine the tables for redundancy and if necessary,
change them to non-redundant forms. This non-redundant model is then converted to a
database definition, which achieves the objective of the Database Design Phase.
Notes 4 Session 4
Customs Receipt Online Audit 24
Need for Normalization Improves database design
Ensures minimum redundancy of data
Reduces need to reorganize data when design is modified/enhanced
Removes anomalies for database activities
The tables derived from the E-R Models may be complex and contain redundant
attributes, which have to be removed. The process of Normalization also removes any
undesirable errors, resulting from database activities like inserting, updating and
deleting values in a table. Storage space may also be conserved, thus resulting in a more
efficient database.
Un-normalized Data structures
An Un-normalized Data structure contains redundant and disorganized data,
which needs to be organized, by dividing the data over several tables to avoid
redundancy. This is achieved by going through the process of Normalization.
Example:
Supplier Code Supplier Name
Supplier Status
City supplier Part Code
Part Name
Weight Qty City
Destination
801 RAM 15 CALCUTTA 101 SCREW 8 500MUMBAI
802 SHYAM 20 CHENNAI 102 NUT 16 200HYDERABAD
803 AMIT 25 HYDERABAD 103 BOLT 20 250CHENNAI 804 RAJESH 15 MUMBAI 102 NUT 16 300MUMBAI 805 SUNDER 25 HYDERABAD 104 BOLT 20 50CALCUTTA
806 MURLlDHARAN 15 JAIPUR 102 NUT 16 200CALCUTTA
The above table presents several difficulties in operations like:
Notes 4 Session 4
Customs Receipt Online Audit 25
Insertion of Fields
If a new field is introduced into the system, it cannot be added to the database,
until it becomes related to another existing field, e.g. if a supplier name is introduced,
its details cannot be entered in the table unless a part name is present for that supplier.
Updation of Fields
If the Supplier Code of a supplier is to be modified, it has to be changed
throughout the table, in all occurrences of the supplier record. Missing out even a single
correction would result in inaccurate data.
Deletion of Fields
If information related to a specific column is to be deleted, the entire row has to
be deleted, which results in loss of required information. For example, if the row of the
supplier 'Amit' is deleted, the information about the 'Part Name' is lost. Deletion of
supplier details also deletes other details.
Steps in Normalization First Normal Form ( 1 NF )
Identify repeating groups of fields
Remove repeating groups to a separate table
Identify the keys for the tables
Key of parent table is brought as part of the concatenated key of the second table
Second Normal Form (2 NF)
Check if all fields are dependent on the whole key
Remove fields that depend on part of the key
Notes 4 Session 4
Customs Receipt Online Audit 26
Group partially-dependent fields as a separate table
Name the tables
Identify key(s) to the table(s) Third Normal Form (3 NF)
Remove fields that depend on other non-key attribute can be calculated or derived from logic
Group interdependent fields as separate tables, identify the key and name the table
A Table is in the First Normal Form when it contains no repeating groups. The
repeating columns or fields in an un-normalized table are removed from the table and
put into tables of their own. Such a table becomes dependent on the parent table from
which it is derived. The key to this table is called the Concatenated Key
(composite/combination), with the key of the parent table forming a part of it.
A table is in the Second Normal Form, if all its non-key attributes are fully
dependent on the whole attribute. This means that each field in a table must depend
upon the entire key. Those that do not depend upon the combination key, are moved to
another table on whose key they depend on. Structures, which do not contain
combination keys, are automatically in the 2 NF.
A table is said to be in the Third Normal Form, if all the non-key attribute of the
table are independent of all other non-key fields of the same table.
Invoice Management System
An Invoice management system accepts items and customer details from the
user and prepares invoices. The item details include item description, quantity sold, rate
and discount if applicable. For each order, the customer is given an invoice. Each
invoice can have details of more than one item.
Notes 4 Session 4
Customs Receipt Online Audit 27
The Raw table containing Invoice details: Un-normalized
Invoice.
No Invoice
date Order
No Challan
No Cust No
CustomerName
ItemNo
Item Desc.
Qty Sold Rate Dis Inv
Value112 12/08/97 1 1 C1 S. Srikant 11 Pepsi 2 8 Nil 38 112 12/08/97 2 1 C1 S. Srikant 12 Butter 1 22 Nil 38 113 16(08/97 1 1 C4 Kavita 14 Bread 1 12 Nil 12 114 16/08/97 1 1 C1 S. Srikant 18 Biscuit 2 22 Nil 54 114 16/08/97 2 1 C1 S. Srikant 12 Pepsi 4 8 Nil 54 First Normal Form
The attributes Invoice number, Invoice date, Order No, Challan No, Gust no and
Invoice Value are repeating groups in the Invoice Table. These attributes can be are
split into a separate table called Invoice table which contains the Invoice number,
Invoice date, Order No, Challan No, Gust No and Inv Value.
The identifier of this table is Invoice Number. The other table is called Invoice Items,
which contains Invoice-no, Item No, Item Description, Qty sold, Rate and Discount.
The identifier of this table is Invoice no and Item no, which identifies a single row.
Invoice Table
Invoice No.
Invoice date
Order No
Challan No
Cust NoCustomer Name
Invoice Value
112 12/08/97 1 1C1 S Srikant 38 113 16/08/97 1 1C4 Kavita 12 114 16/08/97 1 1C1 S. Srikant 54
Notes 4 Session 4
Customs Receipt Online Audit 28
Invoice Items
Invoice. No Item No Item Desc. Qty Sold Rate Discount
112 11 Pepsi 2 8 Nil 112 12 Butter 1 22 Nil
113 14 Bread 1 12 Nil 114 18 Biscuit 2 22 Nil 114 12 Pepsi 4 8 Nil
Second Normal Form
The Invoice Item Table is further split, by removing Item description and rate
which are not dependent on the full-concatenated key (Invoice No. + Item No). The new
table is named as Items table, which contains Item Description, Rate and Item No as its
primary key. The identifier of this table is Item no, which identifies a single row.
The remaining attributes in the Invoice Item table consist only of. Invoice no,
item no, quantity sold and discount. The identifier here is Invoice no + Item no, which
identifies single row. Here each element is dependent on full-concatenated key.
Invoice Table
Invoice No
Invoice date
Order No
Challan No
Cust No Customer Name
Invoice Value
112 12/08/97 1 1C1 S. Srikant 38 113 16/08/97 1 1C4 Kavita 12 114 16/08/97 1 1C1 S. Srikant 54
Notes 4 Session 4
Customs Receipt Online Audit 29
Invoice Items Invoice. No Item No Qty Sold Discount
112 11 2 Nil 112 12 1 Nil 113 14 1 Nil 114 18 2 Nil 114 12 4 Nil Item table Item No Item Desc Rate 11 Pepsi 8 12 Butter 22 14 Bread 12 18 Biscuit 22 Third Normal Form
The Invoice Table derived from the un-normalized table is now in the Second
Normal Form can be further normalized. There is still a dependency between non-key
attributes: Customer Name depends upon Cust No, a non-key attribute. Customer Name
is removed to form the Customer Table, with Customer Number as the key. The
remaining attributes remain in the Invoice Table with Invoice Number as the key.
Invoice Table Invoice. No
Invoice date
Order No
Challan No Cust No Invoice Value
112 12/08/97 1 1 C1 38 113 16/08/97 1 1 C4 12 114 16/08/97 1 1 C1 54 Customer Table Cust No Customer Name C1 S. Srikant C4 Kavita
Notes 4 Session 4
Customs Receipt Online Audit 30
Invoice Items Invoice. No Item No Qty Sold Discount
112 11 2 Nil 112 12 1 Nil 113 14 1 Nil 114 18 2 Nil 114 12 4 Nil Item Table Item No Item Desc, Rate 11 Pepsi 8 12 Butter 22 14 Bread 12 18 Biscuit 22 Relational Database Management System (RDBMS)
A Relational Database Management System (RDBMS) is an information system
that presents information as rows contained in a collection of tables, each table
possessing a set of one or more columns. Codd described the elements of a relational
database as relation, attributes, domains, and the relational operators.
Today, the relational database is at the core of the information systems for many
organizations, public and private, large and small. Informix, Sybase, SQL Server are
RDBMS having worldwide acceptance. Oracle is one of the powerful RDBMS products
(till version 7.3) that provides efficient and effective solutions for major database
management.
Object-Oriented Database Management System (OODBMS)
There are several types of databases being currently used, using network,
hierarchical and relational data models. But, these databases are not able to fully meet
the requirements of -
Notes 4 Session 4
Customs Receipt Online Audit 31
. Engineering applications
. Applications containing images and graphics
. Scientific applications
. Information systems
. Multimedia applications
. Applications accessing multiple database management systems
Such applications are quite different from traditional applications in their
structure and requirements. Their objects are more complex. We also need to define
new data types and operations to deal with such new objects for e.g. in case of
Applications containing large data types (images, graphics and sound files etc.).
The object-oriented approach can handle such requirements without being
limited by traditional DBMS data types and query languages. This is due to its ability to
define the structure and operations of complex objects easily.
An object-oriented database management system (OODBMS) integrates a
DBMS with the concepts of object-oriented programming. It tries to collate the
persistence of a DBMS with the expressiveness of an object-oriented programming
language. An object-oriented database thus stores persistent objects permanently on
secondary storage. An OODBMS permits these objects to be shared among different
applications by providing necessary DBMS functions such as indexing, concurrency
control and recovery. The main advantage of using object-oriented concepts to design
the database3 is that such a database is fully compatible with object-oriented
applications and systems. Moreover, an OODBMS is oriented towards operations on
single objects. RDBMSs are very inefficient in their performance with single objects.
Features of Oracle 8i
High transaction processing performance
Notes 4 Session 4
Customs Receipt Online Audit 32
All the facilities for transaction processing and its recovery in case of any failure
are supported in Oracle 8i for better performance of transaction processing.
Industry accepted standards
All the recent technologies like NCA, object oriented technology and distributed
data processing are supported in Oracle 8i.
Manageable Security
Very strong security provisions are there inside Oracle 8i to guard against
malicious users.
Large Database Support
In supporting large databases, Oracle is more reliable compared to any other
database packages.
Concurrent Processing
More than one user can work simultaneously on the same database without any
interference.
Client/Server environment
It supports client server technology, i.e. the server contains the main database
and clients (users) can access the database to fetch and manage only that data for which
they are given the authorisation.
Distributed database systems
Oracle 8i supports distributed database environment. i.e. applications made on
different platforms and in different environments can exchange the data with the
common interface language called Interface Definition Language (IDL).
Notes 4 Session 4
Customs Receipt Online Audit 33
Portability
Runtime models made inside Oracle 8i environment can run without any
changes on other compatible platforms easily.
Compatibility
It is compatible with all sorts of front ends although, Oracle 8i has its own front
end but still Oracle databases can be used with other front ends like Visual Basic, VC++
etc. easily.
Oracle WebDB
Oracle WebDB is a complete web development environment for building the
HTML web pages with content based on the data stored in the Oracle database. By
using the browsing based interface the developers can build forms, reports, charts,
calendars, menus. Oracle WebDB build wizard guides the WebDB to automatically
write the PL/SQL code therefore there is no need to know PL/SQL for creating the
components.
Oracle WebDB is very easy to use, access and easy to administer. Oracle
WebDB possesses high level of security and ensures that the data is available to only
those who have the permission to access it.
Oracle WebDB provides advanced performance-tracking facilities, which let
administrators ask pertinent questions about system performance. Administrators can
easily keep track of peak load times, most accessible modules, and which users used the
particular system during a given time. Pre-built reports in Oracle WebDB displays
performance and security histories, down to the browser type and IP address of the end
user. Administrators can also create their own customized reports by performing ad-hoc
queries against the logs.
Notes 4 Session 4
Customs Receipt Online Audit 34
Oracle WebDB provides a browser-based interface through which the
administrators can manage database roles, users and grants. In addition Web server
settings and specific privileges offered by WebDB can also be managed by the
administrators.
Oracle IFS (Internet File System)
Oracle IFS provides the ease of use of a file system. IFS is a Java application
that runs within the Oracle Java Virtual Machine and enables the database to become an
internet development and deployment platform. Hybrid documents that combine the
relational and non-relational data can be stored and viewed. The IFS allows intelligent
text queries since the files and folders are indexed on file and content properties.
The IFS treats the database as if it were simply a shared network drive, i.e. the
users can store and retrieve the files managed by the database as if they were files
managed by a file server. System administrators now have a single store for file storage
and messaging which helps in administration easily and efficiently.
Oracle interMedia
Oracle interMedia enables the Oracle 8i to manage the text documents, audio,
and video. interMedia offers several techniques, which ensure fast and accurate text
searching. Also the surfers on the net can easily access the multimedia data in different
ways by using the SQL statements, if the multimedia data they want to access is Oracle
interMedia based application.
Java Virtual Machine
With the introduction of Oracle 8i, Java is now in the picture as a language for
the client/server applications. In Oracle 8i, Oracle has embedded Java Virtual Machine
(JVM) in its database engine giving developers the ability to create their applications in
a variety of programming models.
Notes 4 Session 4
Customs Receipt Online Audit 35
Components of Oracle Java Virtual Machine Library Manager
Once Java objects are successfully loaded into the database they are stored
persistently as database library units which are the database's equivalent of operating
system files. After that, management of all such libraries is done by the Library
manager.
Class Loader
The Oracle 8i Java VM provides an embedded Java Class Loader, which locates,
loads and initializes local DBMS. Stored Java classes in response to requirement
generated by Oracle 8i Java VM's runtime. The Class Loader reads the class
information and produces all of the data structures needed by Oracle 8i JVM to actually
execute Java code.
Memory Manager (Garbage Collector)
The Oracle 8i Java VM's Memory Manager isolates the Java application and the
rest of the Oracle 8i Java VM from the details of memory allocation and collection. It is
tightly integrated with the database. Memory management architecture directly accesses
SQL memory heaps.
Native Compiler
The server environment is considered quite distinct from client application.
Oracle 81's Java VM embeds a native code compiler, which translates standard Java
class binaries generating specialised programs, which are then compiled (by an
embedded platform dependent C compiler) to native dynamic libraries.
Notes 4 Session 4
Customs Receipt Online Audit 36
These native dynamic libraries are stored persistently in the database and are
dynamically loaded by the Oracle Java VM at runtime.
SQLJ
SQLJ is basically a language that embeds the static SQL in Java in such a way
that it is compatible with Java's design philosophy. SQLJ Translator runs before
compilation. This translation process replaces SQLJ statements with Java source
statements with calls to JDSC, the standard Java application-programming interface to
the database Le. SQLJ is a way to embed the SQL in Java programs execution.
The main goal of SQLJ is to provide simple extension to Java to allow the easy
interaction of Java programs with databases.
The various schemas used at runtime are modeled as distinct connection context
classes in S programs, which allow type checking using the same schemas at, translate
time. SQL sup_ connecting to multiple different schemas at the same time.
Multithreading Considerations
Multithreading means dividing the transaction processing into multiple threads
(which can exe, concurrently) for fast processing, where thread is a path of execution.
SQLJ can be used to write multithread application. SQL runtime supports
multiple threads sharing same connection context but sometimes it subjects to
synchronization limitations. While process execution context should not be shared.
Example: If two or more threads are executing SQL operations using some
common context at same time, then race condition may occur in which result of an
execution in one thread ma_ overwritten by the result of execution of some other thread.
Notes 4 Session 4
Customs Receipt Online Audit 37
To avoid such race condition each thread should use a different execution context,
whenever SQL is executed on a saved connection context.
Database Security Features
Using Oracle 8i, the users can be strongly authenticated, even remotely, and the
data is protected in transit using network encryption. Oracle 8i ensures that the same
strong security is enforced whether the data is accessed directly by the user, or through
middle tiers, such as transaction processing monitors or application servers.
The Virtual Private Database
Intranet organization is struggling with the problem of application security.
Oracle 8i addresses these security needs with the concept of virtual private database
server. With this, a web hosting company can maintain the data of multiple companies
in the same Oracle 8i database while allowing each company to see only their own data
Le. Single physical database file can be logically divided for different users according
to their own needs and the access rights that they have.
Example: SELECT * FROM orders; This command will display the contents of the whole table. But through Oracle 8i you can have a fine-grained access control for different users. SELECT * FROM orders WHERE cust_num = (SELECT custnum FROM customers WHERE custname = USERENV ('user'); i.e. only those tuples of the orders table will be displayed for which the specified user has the access right. i.e. an organisation can have different access conditions per user, per group of users, or per application.
Secure Socket Layers (SSL) support in Oracle: Oracle Application Server
Notes 4 Session 4
Customs Receipt Online Audit 38
supports Secure Sockets Layer to protect data privacy between the browser and the
application server as well as authenticating the application server and optionally the
user.
Partitioning Enhancements
Oracle 8i allows range partitioning of tables and multiple partitioning strategies
for indexes providing very large database support.
With the partitioning option, Oracle 8i supports all DML operations in parallel
today. In addition scans of indexes, export and import of table data and estimation and
calculation statistics can also be done in parallel or individual partitions. All recovery,
computation of statistics, import an export are supported on a per partition basis.
Oracle 8i as an Object Oriented Database Management System (OODBMS)
As Oracle 8i is a database server, which offers the capabilities of object oriented
technology including the facilities which were provided by the earlier versions of
Oracle. Oracle 8i, an Object Oriented Database Management System (OODBMS)
provides efficient and effective solutions for major database management.
The three flavours of OODBMS are:
Relational: the traditional Oracle RDBMS Object Relational: The traditional Oracle RDBMS extended to include
object oriented concepts and structures such as abstract data type, nested tables and varying arrays.
Object Oriented: An object-oriented database whose design is based on object oriented analysis and design.
Oracle 8; provides full support for all three different implementations relational,
object relational and object oriented through the help of Network Computing enabled by
Network Computing Architecture (NCA), which provides the framework for building
applications over heterogeneous platforms.
Notes 4 Session 4
Customs Receipt Online Audit 39
Oracle Server and Oracle Database
The Oracle Server is an object-oriented database management system that
provides an open, comprehensive, and integrated approach to information management.
An Oracle server consists of an Oracle Database and an Oracle Server Instance.
An Oracle Instance
Each time a database is started, a system global area (SGA) is allocated and
Oracle background processes are started. The system global area is an area of memory
used for database information shared by the database users. The combination of the
background processes and memory buffers is called an Oracle instance.
An Oracle instance has two types of processes. They are:
User processes: A user process executes the code of an application program (such as an
Oracle Forms application) or an Oracle Tool (such as Oracle Enterprise Manager).
Oracle processes: Oracle processes are server processes that perform work for the user
processes and background processes that perform maintenance work for the Oracle
server.
Network Computing Architecture (NCA)
Supports Client/Server
Supports Internet
Supports Object Technology
NCA is multi-tier architecture The key factors that influenced the creation of the Network Computer Architecture (NCA) are as follows:
Explosive growth of the Internet and the World Wide Web.
Increasing complexity and expense to administer client/server applications on a variety of client platforms such as PC's, Mac's and UNIX workstations.
Notes 4 Session 4
Customs Receipt Online Audit 40
Support for Object.
Support for multiple programming languages.
Support for distributed application and database servers.
Continued support for legacy applications (for example client/server)
Network Computing Architecture (NCA) is the first truly cross platform environment
for developing and deploying network centric applications using open and accepted
defacto standards seamless across both the web and the corporate enterprise. NCA
provides a unifying framework, which allows the different worlds of client/server, the
web and distributed Object technology (CORBA) to share common computing model
based on standards.
NCA provides a foundation software platform that enables universal connectivity and
flexible extensibility to every component on an application. Based on open standard,
throughout developers can select a client of choice, a language that suits the application,
and an appropriate programming model for rapid deployment. NCA is a multi-tier
architecture.
Network Computing Architecture is a strategy that supports a wide range of platforms such as:
Client/Server
World Wide Web (WWW)
Object Technology
Using Network Computer Architecture, any developer will be able to build or extend
existing applications that combine the extensibility of the object world, the robustness
of the client/server world and the ease of use of the Internet.
Client/Server Architecture
Notes 4 Session 4
Customs Receipt Online Audit 41
In this architecture the database system is divided into two parts:
1. A Front End or a Client portion 2. A Back End or Server portion
The Client executes the database application that accesses database information and
interacts with the user. The Server executes the Oracle software and handles the
functions required for concurrent, shared data access to an Oracle database. Client
Server architecture is a two-tier architecture. Oracle 7.x was following the client server
architecture.
Notes 4 Session 4
Customs Receipt Online Audit 42
World Wide Web (WWW)
Network Computing Architecture emphasizes the role of the Internet and WWW.
Explosion of Internet also enabled RDBMS vendors to develop dynamic display of
database contents on the web. Internet is a global computer network of interconnected
networks. It is sometimes called the information superhighway that is capable of
sending text, sound, graphics and videos to computers around the world using the
telephone lines. There is a group of host computers linked together by a dedicated high-
speed, telecommunications connection.
World Wide Web (WWW) is an Internet navigation tool that helps in finding retrieving
widely dispersed information through out the world.
Object Technology
Object Technology helped in designing an object oriented database whose design is
based on Object Oriented Analysis And Design (OOAD). With this technology the
traditional Oracle RDBMS extended to include object oriented concepts and structures.
Note:
One should not confuse Network Computer Architecture with Network Computer.
Network Computing Architecture is software architecture, whereas the network
computer is hardware platform.
CORBA
CORBA stands for Common Object Request Broker Architecture. It is a product
of a consortium called the Object Management Group (OMG) that includes over 600
companies representing the entire spectrum of the computer industry, the notable
exception being Microsoft. CORBA is a set of specifications defining a client/server
middleware architecture for an open software bus on which object components written
by different vendors can inter operate across networks and operating systems. CORBA
Notes 4 Session 4
Customs Receipt Online Audit 43
accomplishes this goal through the use of an Object Request Broker (ORB), which is a
piece of software that handles request for object services.
Oracle Products The Oracle Application Development Tools consist of the following: SQL * Plus It is Oracle's extension of SQL. Oracle Forms Builder
Application developers design data entry and query screens with Oracle Forms
Builder. End users can use these screens to manipulate data in the ORACLE database.
The interface with the user is event driven or function key driven. There are three types
of modules one can create with Oracle Forms Builder.
These are:
Forms Builder: allow update, creation, and deletion of data within ORACLE objects.
Menu: defines an assortment of main menus and any number of sub-menus.
Library: a repository of centralized PLISOL (a Client/Server procedural Language) code accessed by other Oracle Forms modules. Oracle Reports Builder
It is the report writer for ORACLE, having a Windows-based, mouse-driven interface.
It can be used to produce multimedia reporting, which includes images, sounds and
charts. Developers can create master/detail reports, matrix reports, and form letters
using these modules.
Oracle Book
It is an On-Line document viewing facility for the sharing of text across Oracle
Notes 4 Session 4
Customs Receipt Online Audit 44
products. It has three components viz.:
Designer: Provides for the creation and maintenance of On-Line documents.
Converter: Takes older formats of Book documents and converts them to the latest release.
Runtime: Provides viewing capabilities and is used to propagate Book documents to the user community. Oracle Loader and SQL * Connect
It is a tool that very quickly allows the user to load data stored in a variety of
formats into an ORACLE database. SQL * Connect enables a relational database to talk
to traditional databases present in the same host or in a different host.
Oracle Office
It is an office automation product, designed to manage the administrative needs
of any enterprise. The components that make up Oracle Office are:
Office Mail: An integrated messaging environment, with the ability to manage messages. Office Scheduler: Manage time schedule and meetings with other personnel. CoAuthor: A spell checker.
Office Manager: The Office administration tool.
Office Directory: Places information about people, meeting rooms and office equipment. Developer/2000
This product offers a complete solution when ORACLE Clients need to design,
code, implement, and maintain systems. It provides for rapid application development
in a Client-Server Windows environment. It bundles products such as:
Oracle Forms Builder
Oracle Reports Builder
Notes 4 Session 4
Customs Receipt Online Audit 45
Oracle Graphics Builder
Oracle Book
Oracle Browser
Oracle Procedure Builder
Oracle Open Client Adapter (OCA) for Open Database Connectivity (ODBC)
SQL * Plus
SQL * Net. Oracle CASE tool -- Designer/2000
Oracle's latest CASE (Computer Aided Software Engineering) tool,
Designer/2000 automates the steps of System Development Life Cycle .The various
tools provided in Designer/2000 are:
Process Modeller
Entity Relationship Diagrammmer
Data Flow Diagram
Function Hierarchy Diagram
Data Diagram
Module Logic Navigator
Module Data Diagram
Repository Object Navigator
Preference Navigator Oracle Power Objects
Oracle Power Objects is another application development environment that is
supported in the Windows and Mac environments. The Power Object user interface is
closer to Visual Basic than Oracle Forms. Power Objects also provide object-oriented
features such as inheritance.
Notes 4 Session 4
Customs Receipt Online Audit 46
Introduction to Oracle
Designing a table and inserting values
Q.1. Design a table with the following structure and save it as Emp
Field name Field type Empno number Ename Text Job Text Mgr number Hiredate Date / time Sal Number Comm Number Deptno number
Ans.1. To create the emp table the following command at the SQL prompt and press <Enter>
Create table emp(empno number, ename varchar2(20), job varchar2(10), Mgr number, Hiredate date, sal number, comm. Number, Deptno number);
Q.2.Design a table with the following structure and save it as Dept
Deptno number Dname Text Loc Text
Ans. 2. Similarly to create the Dept table please type the following command at the SQL prompt and press <Enter> Create table Dept (deptno number, dname varchar2(20), loc varchar2(20)); <Table created > message indicates that the table has been successfully created.
Notes 4 Session 4
Customs Receipt Online Audit 47
Data for the above tables Emp EMPNO ENAME JOB MGR HIREDATE SAL DEPTNO --------- ---------- --------- --------- --------- --------- -------- 7369 SMITH CLERK 7902 17-DEC-80 800 20 7499 ALLEN SALESMAN 7698 20-FEB-81 1600 30 7521 WARD SALESMAN 7698 22-FEB-81 1250 30 7566 JONES MANAGER 7839 02-APR-81 2975 20 7654 MARTIN SALESMAN 7698 28-SEP-81 1250 30 7698 BLAKE MANAGER 7839 01-MAY-81 2850 30 7782 CLARK MANAGER 7839 09-JUN-81 2450 10 7788 SCOTT ANALYST 7566 19-APR-87 3000 20 7839 KING PRESIDENT 17-NOV-81 5000 10 7844 TURNER SALESMAN 7698 08-SEP-81 1500 30 7876 ADAMS CLERK 7788 23-MAY-87 1100 20 7900 JAMES CLERK 7698 03-DEC-81 950 30 7902 FORD ANALYST 7566 03-DEC-81 3000 20 7934 MILLER CLERK 7782 23-JAN-82 1300 10 2. Dept DEPTNO DNAME LOC --------- -------------- ------------- 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON Q.3.Insert the above values into the emp and dept tables Ans. 3. Insert into emp values(&empno , ‘&ename’, ‘&job’, ‘&Mgr’ , ‘&Hiredate’, &sal , &comm, &Deptno ); (Please note (and ensure) varchar and date fields are given within quotes) This command will prompt you to enter the values one by one. Upon entering the last value , the message will be <1 row created> At <SQL> type commit; to save the data.
Notes 4 Session 4
Customs Receipt Online Audit 48
At <SQL> type ‘/’ to continue adding more rows. At the end Type 'commit;' to save the data at <SQL>. At <SQL> type Select * from EMP; to display the data. Same procedure can be repeated to enter values into Dept table
ORACLE – QUERIES
Queries are used in Oracle to extract data from one or more tables in a desired
fashion. Some examples are given below. The questions, the answer syntax and the
results for certain queries are given below for guidance.
To query and check availability of an object (table, view, synonym etc.) SQL> Select * from tab; 1. To display all the data in EMP table SQL> select * from EMP; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO --------- ------ ------- ----- -------- ----- ---- ------ 7369 SMITH CLERK 7902 17/12/80 800 20 7499 ALLEN SALESMAN 7698 20/02/81 1600 300 30 7521 WARD SALESMAN 7698 22/02/81 1250 500 30 7566 JONES MANAGER 7839 02/04/81 2975 20 7654 MARTIN SALESMAN 7698 28/09/81 1250 1400 30 7698 BLAKE MANAGER 7839 01/05/81 2850 30 7782 CLARK MANAGER 7839 09/06/81 2450 10 7788 SCOTT ANALYST 7566 19/04/87 3000 20 7839 KING PRESIDENT 17/11/81 5000 10 7844 TURNER SALESMAN 7698 08/09/81 1500 0 30 7876 ADAMS CLERK 7788 23/05/87 1100 20 7900 JAMES CLERK 7698 03/12/81 950 30 7902 FORD ANALYST 7566 03/12/81 3000 20 7934 MILLER CLERK 7782 23/01/82 1300 10 14 rows selected. 2. Write a select statement to display all the employees whose salary is less than 3000. SQL> select ename, sal from EMP where sal<3000;
Notes 4 Session 4
Customs Receipt Online Audit 49
ENAME SAL ---------- --------- SMITH 800 ALLEN 1600 WARD 1250 JONES 2975 MARTIN 1250 BLAKE 2850 CLARK 2450 TURNER 1500 ADAMS 1100 JAMES 950 MILLER 1300 11 rows selected.
3. Write a select statement to display the employees’ name working in
department 30 and as MANAGER
SQL> select ename, job, deptno from EMP where deptno=30 and job='MANAGER'; ENAME JOB DEPTNO ---------- --------- --------- BLAKE MANAGER 30 4. Write a select statement to display name, salary for those
employees whose salary range between 2000 and 4000
SQL> SELECT ENAME, SAL FROM EMP WHERE SAL BETWEEN 2000 AND 4000; ENAME SAL ---------- --------- JONES 2975 BLAKE 2850 CLARK 2450 SCOTT 3000 FORD 3000 5. Write a select statement to display the employees not getting commission SQL> SELECT ENAME, COMM FROM EMP WHERE COMM IS NULL; ENAME COMM
Notes 4 Session 4
Customs Receipt Online Audit 50
---------- ----- SMITH JONES BLAKE CLARK SCOTT KING ADAMS JAMES FORD MILLER 10 rows selected. 6. Display the employees whose names start with ‘J’ SQL> SELECT ENAME FROM EMP WHERE ENAME LIKE 'J%'; ENAME ---------- JONES JAMES 7. Write a select statement to display unique jobs in table EMP SQL> SELECT DISTINCT JOB FROM EMP; JOB --------- ANALYST CLERK MANAGER PRESIDENT SALESMAN 8. Write a select statement to display employee name and department
number for employee number 7566
SQL> SELECT ENAME, DEPTNO FROM EMP WHERE EMPNO=7566; ENAME DEPTNO ---------- --------- JONES 20 9. Write a select statement to display employee name and department
number of all employees in departments 10 and 30 in alphabetical order
Notes 4 Session 4
Customs Receipt Online Audit 51
SQL> SELECT ENAME, DEPTNO FROM EMP WHERE DEPTNO IN(10,30) ORDER BY ENAME; ENAME DEPTNO ---------- --------- ALLEN 30 BLAKE 30 CLARK 10 JAMES 30 KING 10 MARTIN 30 MILLER 10 TURNER 30 WARD 30 9 rows selected.
10. Write a select statement to display employee names, salary and
salary increased by 20%
SQL> SELECT ENAME,SAL, SAL*1.2 FROM EMP; ENAME SAL SAL*1.2 ---------- --------- --------- SMITH 800 960 ALLEN 1600 1920 WARD 1250 1500 JONES 2975 3570 MARTIN 1250 1500 BLAKE 2850 3420 CLARK 2450 2940 SCOTT 3000 3600 KING 5000 6000 TURNER 1500 1800 ADAMS 1100 1320 JAMES 950 1140 FORD 3000 3600 MILLER 1300 1560 14 rows selected.
top related