0% found this document useful (0 votes)
43 views28 pages

Unit-1 Final

RDBMS-Oracle notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views28 pages

Unit-1 Final

RDBMS-Oracle notes
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

For more references Please Visit :

https://easy2learncode.in

RDBMS Using Oracle


unit-1
(Unit-1: DBMS Overview, SQL, SQL*Plus )
- Sojitra Dhruvi H.

22
RDBMS Using Oracle unit-1

Oracle is one of the most powerful database


management system(dbms) based on relational
database model,provided by oracle corporation

 Introduction to DBMS
 A database can be defined as a collection of logical, meaningful
data.
 The simple example would be your personal detail, this would
generally contain:
A. First name
B. Last name
C. City name
D. Mobile number…

DBMS(Database Management System) is a software or


tool to provide the base to store the data and helps user to
manage the data with the task like inserting data, deleting
data, updating data and processing of data.
Thus ,DBMS is an organized, collection of data.

https://easy2learncode.in Page 2
RDBMS Using Oracle unit-1

 Introduction to RDBMS
1. What is relationship?
Employee Department

Here, relationship shows in two different Entities(Tables).


 RDBMS
 Oracle is the first RDBMS tool that was presented by
an IBM research scientist called Dr.E.F.Codd.
 It is a collection of inter-related tables which holds
interrelated data.
 Characters create columns(fields), columns create
rows(records). Rows create table.
https://easy2learncode.in Page 3
RDBMS Using Oracle unit-1

 In more than one table,some data items will be


common. So such common columns create a base for
relation.
 In which columns also known as fields and attributes
& rows known as tuples and record.
 When different tables have common columns with the
same type of information, then such tables create a
relational database.
 A computer application that designs, manages,
maintains and displays such related data is called an
RDBMS
 Difference between DBMS and RDBMS
DBMS RDBMS
In DBMS, concept of relationship In RDBMS, It is based on the
is not there in a DBMS. If it is concept of relationships only.
exists it is very less.
It doesn’t support client/server It can support client/server
architecture. architecture.
Uses concept of file. Each table is Uses concept of table. Many
given an extension in DBMS. tables are grouped in one
database in RDBMS.
speed of operation is very slow. Speed of operation is very fast.
In every DBMS software, the Hardware and Software
hardware and software requirements are high.
requirements are less.
Facilities and utilities offered are Facilities and utilities offered are
limited. many.
Some of the DBMS tools are Some of the popular RDBMS
Dbase, FoxPro. tools are Oracle,MS SQL Server.
DBMS normally use a 3GL. RDBMS normally use a 4GL.

https://easy2learncode.in Page 4
RDBMS Using Oracle unit-1

 Dr.E.F.Codd Rules
1. The information rule
The basic requirement of the relational model is to first:
all data should be presented in a table format and data
are represented only one way: as values within columns
with in rows.
2. Guaranteed access rule
 Every table value can be accessed by providing their
table name, field/column name and key.
 All data are uniquely identified and accessible
through all this identity.
 All data should be accessible without uncertainty.
3. Systematic treatment of null values
 A field should be allowed to remain Empty.
Handling of missing or non applicable data.
 This is distinct to zero(0) or empty strings(“ ”).
4. Relational online catalog
 The catalog (data dictionary) is part of the
database.
 Catalog is based on relational model.
 Relational database must provide access to its
database structure through the same tool that
are used to access the data.
5. Comprehensive data sub language rule

https://easy2learncode.in Page 5
RDBMS Using Oracle unit-1

 The database must support at least one


specific defined language that includes
functionality for all SQL categories like data
definition, data manipulation, data integrity
and databse transaction.
6. View updating rule
 Views are virtual tables. They appear to
behave as conventional tables except that
they are built dynamically when query is run.
 It is not always theoretically possible to
update views.
7. High-level insert, update & delete.
 Must support set-at-a-time updates, insert
and delete. For e.g., update stud set
rollno=22 where rollno=2;
 Many rows can be updated with this single
transaction/statement.
8. Physical data independence
 Physical layer of the architecture is mapped
onto the logical layer.
 Here users and programs are not dependent
on the physical structure of the database.

https://easy2learncode.in Page 6
RDBMS Using Oracle unit-1

 Without affecting how user accesses it,


changes can be made to the underlying
architecture.
9. Logical data independence
 Users and all programs are independent of
the logical structure of the database.
 Viewing structure of the data should not be
changed when the logical structure of the
database changes.
10. Integrity independence
 Integrity constraints specific to a particular
relational database and storable in the data
dictionary.
 Alteration to integrity constraints should not
affect application programs.
11. Distribution independence
 Application should still work in a distributed
database. Parts of database exist in multiple
location.
12. Non subversion rule
 Database created in high level version and
run in low level version, then it should not
violate in low level version.

https://easy2learncode.in Page 7
RDBMS Using Oracle unit-1

 Importance of E.R.Diagram in Relational DBMS.


 Used to represent a connection among related entities like a link.
 This is one of the data model that was devloped by P.P.chen in 1976.
 ER diagrams specify what data we will store: the entities and their attributes.
They also show how entities relate to other entities.

An E-R diagram uses six basic symbols:


1. Entity that represents Rectangle
 A person,thing concept about which you want to store
data. Ex.student , courses.

2. Relationship that represents Diamond


 Used to represent a connection amoug related entities
like a link. Ex.student -to- college , Client –to- server

3. Attributes that represents Oval


 Data values of an entities.
 Chracteristics of person ,thing or concept.
 Ex.stud_id, stud_name, stud_class.

https://easy2learncode.in Page 8
RDBMS Using Oracle unit-1

4. ‘1’ to denote a single Occurrence.

(1:1)

5. ‘M’ to denote a multiple occurrence.

(1:M)/(M:M)

6. A line which links attributes to an entity and entity to


relationships.

Ex.,

 Relationship DBMS.
 1.One-to-one:
 One entity from entity set X can be associated with at most one
entity of entity set Y .
 Example: One student can register for any one courses..

https://easy2learncode.in Page 9
RDBMS Using Oracle unit-1


 2.One-to-many:
 One entity from entity set X can be associated with multiple entities of
entity set Y, but an entity from entity set Y can be associated with at
least one entity.
 For example, one class is consisting of multiple students.

 3. Many to Many:
 One entity from X can be associated with more than one entity from Y and
vice versa.
 For example, Students as a group are associated with multiple faculty
members, and faculty members can be associated with multiple students.

https://easy2learncode.in Page 10
RDBMS Using Oracle unit-1

 Introduction to SQL
 SQL Stand for structured query language.
 It is an query language used to creating and maintaining database
system.
 SQL is an intermediate language between user(client) and the
server.
 It is the basic tool of relational database for accessing data.
 SQL can used for insert,update and delete operations on data
into the database.
 Characteristics and features of SQL:
1. SQL is a Non-Procedural Language:
It means, in SQL there is no coding like looping, branching and
all.
It is command based language. Task can be performed using
commands only. For Example to INSERT COMMAND, DELETE
COMMAND, UPDATE COMMAND, SELECT COMMAND.
2. SQL can be used by any user
3. It reduces the amount of time required for creating and
maintaining database system.

 SQL Commands
There are SQL commands divided into three categories,
[1]Data Definition Language(DDL):
 It is a set of SQL commands used to create, modify and delete
database structures but not data.
 Database Structure contains columns, data types, size and
constraints.

https://easy2learncode.in Page 11
RDBMS Using Oracle unit-1

 Commands are as follows:


 CREATE:
To create objects like tables, views, synonyms etc. in the
database.
 ALTER:
Alters(modify) the structure of the database.
 DROP:
Delete objects(table,view) from the database.
 TRUNCATE:
Remove all records from the table, including all spaces
allocated for the records are removed.
 GRANT:
Gives user’s access privileges(permission) to database.
 REVOKE:
Withdraw access privileges given with the GRANT
command.
[2]Data Manipulation Language(DML):
 It contains the commands responsible for queries and changes
made to the table data.
 It can be used to changes the table data. All the commands of
this category can affect the table’s data.
 Commands are as follows:
 SELECT:
Recovers/Access Data From A Table, This Is The Main
Command In SQL.
 INSERT:
Insert Data Into A Table.
 UPDATE:
Updates Existing Data Within A Table.
 DELETE:

https://easy2learncode.in Page 12
RDBMS Using Oracle unit-1

Deletes All Records From A Table,Never Table.


 CALL:
Call A PL/SQL Or Java Sub Program.
 LOCK:
Table Control Concurrency.

[3]Data Control Language(DCL):


 It is the component of SQL statement that control access to
data and to the database.
 Occasionally DCL statement are grouped with DML
statements.
 These category is also called as transaction control
language(TCL).
 Commands are as follows:
 COMMIT :
save work done.
 ROLLBACK :
restore database to original since the last commit.
 SAVEPOINT :
identify a point in a transaction to which you can later
rollback.
 SET TRANSACTION :
change transaction options like what rollback segment to
use.
 GRANT / REVOKE :
grant to take back permissions to or from the oracle
users.
 SQL Basic Datatypes
 (1)CHAR :
 the CHAR datatype is a fixes-length alphanumumeric character string.

https://easy2learncode.in Page 13
RDBMS Using Oracle unit-1

1. Size can range from a minimum of 1 to a maximum of 2000


characters.
2. If the data is shorter then the defined length,it is space padded
on the right.
 For ex.CHAR data type of 5 size. CHAR(5)

s y a m

 (2)VARCHAR2 :
 The VARCHAR2 datatype is a alphanumeric string having a maximum
lenth of size bytes.
1. Only require the amount of space needs to store the data. Its
columns can store up to 4000 byte.
 Ex.VARCHAR2 datatype of 5 size .VARCHAR2(5).
g o p i

 (3)VARCHAR:

A VARCHAR datatype is currenty synonymous with the VARCHAR2


datatype.

 (4)LONG : the LONG datatpe is large object(LOB) datatypes. Variable


length up to 2GB.

1. Uses for GROUP BY and ORDER BY or CONNET BY.

 (5)NUMBER : the number datatype store number with a two


parameter. That is precision of P digists and S scale of digits.

 The precision is the number of digits in a number. It ranges from 1 to


38.

https://easy2learncode.in Page 14
RDBMS Using Oracle unit-1

 The scale is the number of digits to the right of the decimal point in a
number. It range from -84 to 127.

 Ex.NUMBER(4,2) insert value of 12.671

1. Result : 12.68

 (6)DATE:the DATE datatype is used to store date and time


information.

 It consider date value like year,month,date,hour,minut and second.

 Ex.DD-MM-YYYY

 SYSDATE() function return the current system date and time from the
database server.

 Introduction to SQL*Plus
 SQL*Plus is an interactive and batch query tool that is installed with
every Oracle Database Server or Client installation.
 It has a command-line user interface, a Windows Graphical User
Interface (GUI) and the iSQL*Plus web-based user interface.
 SQL*Plus enables you to manipulate SQL commands and PL/SQL
blocks, and to perform many additional tasks.
 With SQL*Plus, you can: Enter, edit, store, retrieve, and run SQL
commands and PL/SQL blocks. Format, perform calculations on, store,
and print query results in the form of reports

 SQL*Plus formatting commands


1. Describe : it describe your whole table structure. It means name
of the column, constrains name, data type, and its size.
For ex., SQL>desc/describe<table_name>

https://easy2learncode.in Page 15
RDBMS Using Oracle unit-1

2. Define : to define global variable for assign value to variable


For ex., SQL>define pi=3.14

3. Show : display the environmental settings i.e., line size,page size,


headings
For ex., SQL>show linesize

4. Set : to set the environmental settings


For ex., SQL>set linesize 200
For ex., SQL>set pagesize 10

5. Get : retrieve of sql file and places it into the sql buffer
For ex., SQL>get d:/outputfile.txt

6. List : to display the last command which is executed.

7. Change : used to change the column name


For ex., change<oldname><newname>

8. Run : to run or execute any file .

9. Spool : to generate the output file. By default, the spool command


created a file with .lst extension., .lst file is a text file that
contain a list of data.

10. Remark : for creating comments. It will consider as a


comment and will not be executed.

11. Ttitle : top title for report generation. To give the title on top of
the report.
12. Btitle : To give the title on bottom of the report.

13. Break on : according to user requirement to insert the break in


records , pages,etc…

https://easy2learncode.in Page 16
RDBMS Using Oracle unit-1

14. Compute :to calculate the mathematical operation like


sum,average,min,max,etc..

 Operator and Expression


[1]Arithmetic Operators:
 The Arithmetic Expressions are used to display mathematically
calculated data.
The calculations are for output purposes only.
Operators Use
* Multiplication
/ Division
+ Addition
- Subtraction
For example: increment salary by 2500 whose employee number is 2.
SELECT ename,salary+2500
FROM employee where eno=2;
[2]Logical Operators:
Logical Operators Meaning
AND Returns TRUE only if both
conditions are true.
OR Returns TRUE if one or both
conditions are true.
NOT Returns TRUE if the condition is
false.
For example: SELECT * FROM stud WHERE fname=’angel’ AND
lname=’patel’;

[3]Range Searching Operators:

https://easy2learncode.in Page 17
RDBMS Using Oracle unit-1

 In order to select data that is within a range of values, the


BETWEEN operator is used.
For example:
SELECT * FROM stud WHERE stud_id BETWEEN 1 and 10;
SELECT * FROM stud WHERE stud_id BETWEEN ‘M’ AND ‘Z’;

[4]Pattern Matching(wild cards) Operators:


 When you do not know the exact string values, in these cases,
you can select rows that match a pattern of characters.
 A search with the wild cards requires you to use the LIKE
operators.
Wild card Use
% Represents zero or more characters.
_(Underscore) Represents any one character.

[5]IN & NOT IN Predicates Operators:


 The arithmetic operator(=)compares a single value to
another single value.
 In case a value needs to be compared to a list of values
then the IN Predicate is used.
 The IN Predicate helps reduce the need to use multiple
OR conditions.
 Example .,
SELECT * FROM Employee WHERE city
IN(‘Rajkot’,’Mumbai’,’Ahmedabad’,’Baroda’);

SELECT * FROM Employee WHERE city


IN(‘Rajkot’,’Mumbai’,’Ahmedabad’,’Baroda’);

https://easy2learncode.in Page 18
RDBMS Using Oracle unit-1

[6]IS NULL & NOT NULL Predicates Operators:


IS NULL essentially instructs oracle to identify columns in
which the data is missing.
Display only those records or values, which are empty or
unknown or missing.(Does not similar to zero)

Example.,
SELECT name,city FROM stud WHERE fees IS NULL;
SELECT name,city FROM stud WHERE fees IS NOT NULL;

[7]Concatenation(||) Operators:
This is used to concatenate two strings. The strings can be
either column names or literals.
To use either “||” or CONCAT() function.

For example.,
SELECT city||country from Location;
SELECT CONCAT(city,country) from Location;

 SQL v/s SQL*Plus


SQL SQL * PLUS
1 SQL is a language to interact SQL * PLUS is not a language
with the server to access the but recognized SQL statements
database. and sends them to the server.
2 SQL manipulates data and SQL * PLUS does not allow
table definitions(structure) in manipulation of values in the

https://easy2learncode.in Page 19
RDBMS Using Oracle unit-1

the database. database.


3 SQL is entered into the SQL SQL * PLUS is entered one line
buffer on one or more lines. at a time, not stored in the SQL
buffer.
4 SQL uses a termination SQL * PLUS does not require
character(;) to execute termination character(;),
commands immediately. executes commands
immediately.
5 SQL uses functions to perform SQL * PLUS uses commands to
some formatting. format data.
6 By using SQL commands, we By using SQL * PLUS commands,
can directly interact with the we cannot directly interact with
database. the database.
7 SQL is a basic query langage It is a environment setting tool,
for the commands with report formatting tools, editing
database. a file, editing a command line
buffer etc.
8 It is an application Tool. It is setting oriented Tool
9 Examples: create , Insert, Examples: Edit, Describe, Run
Delete

 Normalization
 Normalization is a database design technique that reduces data
redundancy and eliminates undesirable characteristics like
Insertion, Update and Deletion Anomalies.
 Normalization rules divides larger tables into smaller tables and
links them using relationships.
 The purpose of Normalisation in SQL is to eliminate redundant
(repetitive) data and ensure data is stored logically.

Types of Normal Forms:

Normal Description

https://easy2learncode.in Page 20
RDBMS Using Oracle unit-1

Form

1NF A relation is in 1NF if it contains an atomic value.

A relation will be in 2NF if it is in 1NF and all non-key attributes


2NF
are fully functional dependent on the primary key.

A relation will be in 3NF if it is in 2NF and no transition


3NF
dependency exists.

A stronger definition of 3NF is known as Boyce Codd's normal


BCNF
form.

First Normal Form (1NF)

 A relation will be 1NF if it contains an atomic value(single record).


 It states that an attribute of a table cannot hold multiple values. It
must hold only single-valued attribute.
 First normal form disallows the multi-valued attribute, composite
attribute, and their combinations.

Example: Relation EMPLOYEE is not in 1NF because of multi-valued


attribute EMP_PHONE.

https://easy2learncode.in Page 21
RDBMS Using Oracle unit-1

Second Normal Form (2NF)

 In the 2NF, relational must be in 1NF.

 In the second normal form, all non-key attributes are fully functional
dependent on the primary key

Example: Let's assume, a school can store the data of teachers and the
subjects they teach. In a school, a teacher can teach more than one
subject.

TEACHER table

TEACHER_ID SUBJECT TEACHER_AGE

25 Chemistry 30

25 Biology 30

47 English 35

https://easy2learncode.in Page 22
RDBMS Using Oracle unit-1

83 Math 38

83 Computer 38

In the given table, non-prime attribute TEACHER_AGE is dependent on


TEACHER_ID which is a proper subset of a candidate key. That's why it
violates the rule for 2NF.

To convert the given table into 2NF, we decompose it into two tables:

Third Normal Form (3NF)

 A relation will be in 3NF if it is in 2NF and not contain any transitive


partial dependency.

 Transitive dependency means when a nonprime attributes


determines another nonprime attributes.

https://easy2learncode.in Page 23
RDBMS Using Oracle unit-1

 In partial dependency the non-prime attribute is functionally


dependent on part of any part(subset) of that attributes.

 3NF is used to reduce the data duplication. It is also used to achieve


the data integrity.

 If there is no transitive dependency for non-prime attributes, then


the relation must be in third normal form.

A relation is in third normal form if it holds atleast one of the following


conditions for every non-trivial function dependency X → Y.

1. X is a super key.

2. Y is a prime attribute, i.e., each element of Y is part of some


candidate key.

{EMP_ID}, {EMP_ID, EMP_NAME}, {EMP_ID, EMP_NAME, EMP_ZIP}....so o


n

https://easy2learncode.in Page 24
RDBMS Using Oracle unit-1

Candidate key: {EMP_ID}

Non-prime attributes: In the given table, all attributes except EMP_ID are
non-prime.

Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP


dependent on EMP_ID. The non-prime attributes (EMP_STATE,
EMP_CITY) transitively dependent on super key(EMP_ID). It violates the
rule of third normal form.

That's why we need to move the EMP_CITY and EMP_STATE to the new
<EMPLOYEE_ZIP> table, with EMP_ZIP as a Primary key.

https://easy2learncode.in Page 25
RDBMS Using Oracle unit-1

Boyce Codd normal form (BCNF)


o BCNF is the advance version of 3NF. It is stricter than 3NF.

o A table is in BCNF if every functional dependency X → Y, X is the


super key of the table.

o For BCNF, the table should be in 3NF, and for every FD, LHS is super
key.

Example: Let's assume there is a company where employees work in


more than one department.

The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.

To convert the given table into BCNF, we decompose it into three tables:

https://easy2learncode.in Page 26
RDBMS Using Oracle unit-1

Candidate keys:

https://easy2learncode.in Page 27
RDBMS Using Oracle unit-1

For the first table: EMP_ID


For the second table: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}

Now, this is in BCNF because left side part of both the functional dependencies
is a key.

Follow Us :

https://easy2learncode.in Page 28

You might also like