RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of...

43
RDBMS FUNDAMENTALS 1

Transcript of RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of...

Page 1: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

1

RDBMSFUNDAMENTALS

Page 2: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed easily.A relational database is created using the relational model. The software used in a relational database is called a relational database management system (RDBMS). A relational database is the predominant choice in storing data, over other models like the hierarchical database model or the network model.

Page 3: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

3

Relational Model It is a simple data model in which database is represented as a collection of ‘relations’ ,where each relation is represented by a two dimensional table.

Page 4: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

4

Relational Model

Page 5: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

5

Relational Terminology

Formal Relational Term Informal Equivalent(s)

Relation Table

Tuple Row, Record

Cardinality Number of rows

Attribute Column, Field

Degree Number of columns

Primary key Unique identifier

Domain Set of legal values

Page 6: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.
Page 7: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

7

RDBMS Concept• Relational Database Management System: A type of database

management system (DBMS) that stores data in the form of related tables.

• Relational databases are powerful because they require few assumptions about how data is related or how it will be extracted from the database. As a result, the same database can be viewed in many different ways.

• The concept of relational databases was given by E.F. Codd at IBM in 1970.

• An important feature of relational systems is that a single database can be spread across several tables.

• This differs from flat-file databases, in which each database is self-contained in a single table.

Page 8: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

8

A key uniquely identifies a row in a table. In RDBMS, these are classified into the five:

• Primary Key

• Foreign Key

• Candidate Key

• Alternate Key

• Composite Key

Concept Of Keys In RDBMS

Page 9: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

9

• Primary Key : The primary key is a attribute of a relational table uniquely identifies the each tuple of a table or each record in the table. It can either be a normal attribute that is guaranteed to be unique. • Foreign Key : A foreign key is a column in a table that uniquely identifies the records from the different table .

• Candidate Key :  Any number of attributes that are uniquely identifying a row in a table is “candidate key” for the table.

• Alternate Key : We select one of the candidate key as Primary key. All candidate keys which are not chosen as "primary key" are “Alternate keys”. • Composite Key : The key which uniquely identify the rows of the table and which is made up of more than one attribute is called “composite key”.

Concept Of Keys In RDBMS

Page 10: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Two types relationship:one-to-many (1:M)

book-publisherA book has one publisher but a publisher may publish many books

many-to-many (M:M)books-to-authors

A book may have many authors and an author may write many books

Page 11: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Normalization•Normalization was first

proposed by Codd as an integral part of the relational model. It prevents data manipulation anomalies and loss of data integrity. The most common forms of normalization applied to databases are called the normal forms. Normalization trades reducing redundancy for increased information entropy.

Page 12: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

First normal form (1NF) sets the very basic rules for an organized database: 

· Eliminate duplicative columns from the same table.

 · Create separate tables for each group of related

data and identify each row with a unique column or set of columns (the primary key). 

Page 13: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Second normal form (2NF) further addresses the concept of removing duplicative data: 

· Remove subsets of data that apply to multiple rows of a table and place them in separate tables.

 · Create relationships between these new tables

and their predecessors through the use of foreign keys.

Page 14: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

  

• Third normal form (3NF) goes one large step further: 

· Remove columns that are not dependent upon the primary key.

 Finally, fourth normal form (4NF) has one requirement:

· A relation is in 4NF if it has no multi-valued dependencies.Remember, these normalization guidelines are cumulative. For a database to be in 2NF, it must first fulfill all the criteria of a 1NF database. 

Page 15: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

15

ORACLE - RDBMS Software

• The oracle Corporation is the world’s leading supplier of software for information management and world’s second largest independent software company.

• It is the top selling multi-user RDBMS.

• Oracle’s application covers business intelligence, e-commerce , euro , Financials(such as accounts receivables, accounts payable, and general ledger), human resources, internet procurement, manufacturing, mobile, projects, sales, services, strategic enterprise management, and treasury.

15

Page 16: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

16

Some more leading RDBMS Products

•SQL Server•IBM’s DB2

Page 17: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

• SQL referred to as Structured Query Language is a special-purpose programming language designed for managing data in relational database management systems (RDBMS).

Page 18: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Data manipulation

•The Data Manipulation Language (DML) is the subset of SQL used to add, update and delete data:

• INSERT adds rows (formally tuples) to an existing table.

•UPDATE modifies a set of existing table rows.•DELETE removes existing rows from a table.

Page 19: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Data definition

•The Data Definition Language (DDL) manages table and index structure. The most basic items of DDL are the 

•CREATE, •ALTER, •RENAME, •DROP and •TRUNCATE statements:

Page 20: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

CREATE creates an object (a table, for example) in the database.

ALTER modifies the structure of an existing object in various ways, for example, adding a column to an existing table or a constraint.

TRUNCATE deletes all data from a table in a very fast way, deleting the data inside the table and not the table itself. It usually implies a subsequent COMMIT operation, i.e., it cannot be rolled back (data is not written to the logs for rollback later, unlike DELETE).

DROP deletes an object in the database, usually irretrievably, i.e., it cannot be rolled back.

Page 21: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Data control

The Data Control Language(DCL) authorizes users and groups of users to access and manipulate data. Its two main statements are:

GRANT authorizes one or more users to perform an operation or a set of operations on an object.

REVOKE eliminates a grant, which may be the default grant.

  

Page 22: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

22

RELATIONAL ALGEBRA• Relational Algebra is a procedural language that can

be used to tell the DBMS how to build a new relation from one or more relations(tables) in the database.

• While using the relational algebra, user has to specify what is required and what are the procedure or steps to obtain the required output.

• It is a theoretical language with operations that work on one or more relations to define another relation without changing the original relation(s).

Page 23: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

23

RELATIONAL ALGEBRA

• In Relational Algebra, each operation takes one or more relations as its operand(s) and another as its result.

• That is, in relational algebra, R1 + R2 = R3

where, ‘R1’ & ‘R2’ are relations (operands) ‘+’ is relational operator which gives R3 as a

resultant relation

Page 24: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

24

Types of Relational Operators

Relational Operators are classified into two types:

•Traditional Set Operators

•Special Operators

Page 25: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

25

Traditional Set Operators

Union

Intersection

Difference

Cartesian Product

Page 26: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

26

Union

• In mathematical set theory, the union of two sets is the set of all elements belonging to both sets.

• It is denoted by ‘U’.

• If S1 = {1,2,3,4,5} and S2 = {4,5,6,7,8} Then union of two sets (S1 U S2) would be the set {1,2,3,4,5,6,7,8}

Page 27: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

27

In case of union operation on two relational tables…

Suppose there are two tables ‘R’ and ‘S’

R

R U S

C.Name C.Status

A Good

B Excellent

C.Name C.Status

B Excellent

C Bad

S

C.Name C.Status

A Good

B Excellent

C Bad

Page 28: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

28

Intersection• In mathematics, an intersection of two sets

produces a set, which contains all the elements common to both sets.

• It is denoted by ‘ ’• If S1 = {1,2,3,4,5} and S2 = {4,5,6,7,8} Then intersection of two sets (S1 S2) would be

the set {4,5}

Page 29: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

29

In case of intersection operation on two relational tables…

Suppose there are two tables ‘R’ and ‘S’

R

R intersection S

C.Name C.Status

A Good

B Excellent

C.Name C.Status

B Excellent

C Bad

S

C.Name C.Status

B Excellent

Page 30: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

30

Difference• In mathematics, the difference between two sets

produces a set, which contains all the elements of one set, which are not in the other.

• It is denoted by ‘-’• If S1 = {1,2,3,4,5} and S2 = {4,5,6,7,8} Then difference between two sets (S1 - S2) would

be the set {1,2,3} or, (S2 – S1) = {6,7,8}

Page 31: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

31

In case of difference operation on two relational tables…

R

R - S

C.Name C.Status

A Good

B Excellent

C.Name C.Status

B Excellent

C Bad

S

C.Name C.Status

A Good

C.Name C.Status

B Excellent

S - R

Page 32: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

32

Cartesian Product• In mathematics, the cartesian product of two sets is

the set of all ordered pairs of elements such that the first element in each pair belongs to the first set and the second element in each pair belongs to the second set.

• It is denoted by ‘X’ (cross)• If S1 = {1,2,3} and S2 = {4,5,6} Then the cartesian product (S1 X S2) is the set:

{(1,4),(1,5),(1,6),(2,4),(2,5),(2,6),(3,4),(3,5),(3,6)}

Page 33: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

33

In case of cross (X) operation on two relational tables…

Male_Female

F.Name F.Job

A Clerk

B Sales

M.Name M.Job

C Clerk

D Sales

Male

F.Name F.Job M.Name M.Job

A Clerk C Clerk

A Clerk D Sales

B Sales C Clerk

B Sales D Sales

Female

Page 34: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

34

Special (Relational) Operators

Select

Project

Join

Page 35: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

35

Select Operation

•It is used to select some specific records from the database based on some criteria.

• It is mathematically denoted as ‘ o ’•Syntax: o <selection condition>(Relation) Example: o age <= 30 (person)

Page 36: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

36

Project Operation

•It is used to select the records with specified attributes while discarding the others based on some specific criteria.

• It is mathematically denoted as ‘ ’•Syntax: <selection condition> (Relation) Example: Name (Person)

Page 37: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

37

Join Operation

•It is applied on two relations when we want to select related tuples from two given relation.

•It is denoted by | |•Syntax: R1 | | R2 where R1 and R2 are two related

relations•Example: student | | course

Page 38: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

What Are the Limitations of Relational Databases in Business Applications?

Relational databases power many different types of business applications, including customer relationship management systems and billing programs. These databases offer powerful information management tools to business leaders, but the technology behind a relational database also imposes limitations. These drawbacks become apparent not only within the database itself, but also in the mechanisms by which business applications access the data.

Page 39: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Data Complexityinexperienced programmers may design systems that create unnecessary complexity or limit the future development of the database through poorly chosen data types.

Broken Keys and RecordsRelational databases require shared keys to link information spread across several tables.If the data types linking the keys are different, the database cannot link the records without additional rework by the report developer.

Developer ExpertiseAs the complexity of a relational database increases, the skill set required by the RDBMS administrator, various users and report developers also increases.

Page 40: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Hardware Performance•Complex queries require sophisticated

processing power. Although most desktop computers can manage the databases of the size and complexity often encountered in a small business setting, a database with external data sources or very complex data structures may require more powerful servers to return results within an acceptable response time.

Page 41: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

The benefits of a database that has been designed according to the relational model are numerous. Some of them are:

• Data entry, updates and deletions will be efficient.• Data retrieval, summarization and reporting will also be

efficient.• Since the database follows a well-formulated model, it

behaves predictably.• Since much of the information is stored in the database rather

than in the application, the database is somewhat self-documenting.

• Changes to the database schema are easy to make. 

Page 42: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

Summary

• The relational database model was created by E.F. Codd in 1969 and is founded on set theory and logic.

• A database designed according to the relational model will be efficient, predictable, well performing, self-documenting and easy to modify.

• Every table must have a primary key, which uniquely identifies rows in the table.

• Foreign keys are columns used to reference a primary key in another table.

• You can establish relationships between tables in a relational database: one-to-many, many-to-many .

Page 43: RDBMS FUNDAMENTALS 1. A relational database is a collection of data items organized as a set of formally described tables from which data can be accessed.

thankyouBy:rajni gupta