Unit-1 Final
Unit-1 Final
https://easy2learncode.in
22
RDBMS Using Oracle unit-1
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…
https://easy2learncode.in Page 2
RDBMS Using Oracle unit-1
Introduction to RDBMS
1. What is relationship?
Employee Department
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
https://easy2learncode.in Page 6
RDBMS Using Oracle unit-1
https://easy2learncode.in Page 7
RDBMS Using Oracle unit-1
https://easy2learncode.in Page 8
RDBMS Using Oracle unit-1
(1:1)
(1:M)/(M:M)
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
https://easy2learncode.in Page 12
RDBMS Using Oracle unit-1
https://easy2learncode.in Page 13
RDBMS Using Oracle unit-1
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:
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.
1. Result : 12.68
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
https://easy2learncode.in Page 15
RDBMS Using Oracle unit-1
5. Get : retrieve of sql file and places it into the sql buffer
For ex., SQL>get d:/outputfile.txt
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.
https://easy2learncode.in Page 16
RDBMS Using Oracle unit-1
https://easy2learncode.in Page 17
RDBMS Using Oracle unit-1
https://easy2learncode.in Page 18
RDBMS Using Oracle unit-1
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;
https://easy2learncode.in Page 19
RDBMS Using Oracle unit-1
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.
Normal Description
https://easy2learncode.in Page 20
RDBMS Using Oracle unit-1
Form
https://easy2learncode.in Page 21
RDBMS Using Oracle unit-1
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
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
To convert the given table into 2NF, we decompose it into two tables:
https://easy2learncode.in Page 23
RDBMS Using Oracle unit-1
1. X is a super key.
https://easy2learncode.in Page 24
RDBMS Using Oracle unit-1
Non-prime attributes: In the given table, all attributes except EMP_ID are
non-prime.
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
o For BCNF, the table should be in 3NF, and for every FD, LHS is super
key.
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
Now, this is in BCNF because left side part of both the functional dependencies
is a key.
Follow Us :
https://easy2learncode.in Page 28