20
Data Models, Schemas & Data Models, Schemas & Instances Instances And And Database Languages Database Languages

Data Models, Schemas & Instances

Embed Size (px)

Citation preview

Page 1: Data Models, Schemas & Instances

Data Models, Schemas & Data Models, Schemas & InstancesInstancesAndAndDatabase LanguagesDatabase Languages

Page 2: Data Models, Schemas & Instances

Data ModelData ModelA collection of concepts that can be used to

describe the structure of a databaseData model is a collection of conceptual(logical)

tools for describing data, relationship etc.provides the necessary means to achieve data

abstractionBy structure of a database, we mean the data types,

relationships, and constraints that should hold for the data

04/07/23 Database Management System 2

Page 3: Data Models, Schemas & Instances

Categories of Data ModelsCategories of Data Models

High level or Logical (Conceptual)Data Model – provide concepts that are close to the way many users perceive data

Low level or Physical Data Model - provide concepts that describe the details of how data is stored in a computer

Representational Data Model - provide concepts that may be understood by end users but that are not too far removed from the way data is organized within the computer.

04/07/23 Database Management System 3

Page 4: Data Models, Schemas & Instances

CONTINUEDCONTINUED……Physical data models defines record structure, file

structure etc.Logical data models use concepts such as entities,

attributes & relationships Entity – represents a real world object or a concept

Ex: employee, student, projectAttribute - represents some property of interest that

further describes an entity Ex: Employee's name or salary.

04/07/23 Database Management System 4

Page 5: Data Models, Schemas & Instances

TYPES OF DATA MODELSTYPES OF DATA MODELSLogical Data Model

Entity – Relationship Model (ER model) Object – Oriented Model

Representational or Implementation Data Model

Relational Model Network Model Hierarchical Model

04/07/23 Database Management System 5

Page 6: Data Models, Schemas & Instances

ENTITY - RELATIONSHIP (ER) ENTITY - RELATIONSHIP (ER) MODELMODEL

It is based on a perception of a real world that consists of a collection of basic objects, called entities and the relationships among these objects.

The overall logical structure (schema) of a database can be expressed graphically by an E-R diagram

04/07/23 Database Management System 6

Page 7: Data Models, Schemas & Instances

EXAMPLE ER DIAGRAM FOR EXAMPLE ER DIAGRAM FOR COMPANY DATABASECOMPANY DATABASE

04/07/23 Database Management System 7

Employee Department

Age

Salary

Ssn

Emp_Name

Dept_Location

Dept_Name

Dept_Number

Dept_Number

Mgr_Ssn

Works in

Page 8: Data Models, Schemas & Instances

RELATIONAL MODELRELATIONAL MODELUses a collection of tables to represent both data

and the relationships among those dataEach table has multiple columns, and each

column has a unique nameIn the formal relational model terminology, a

row is called a tuple, a column header is called an attribute, and the table is called a relation

In Relational model data is organized in the form of tables .

04/07/23 Database Management System 8

Page 9: Data Models, Schemas & Instances

It uses a collection of tables to represent both data and the relationships among those data.

The advantage of this model is that it offers flexibility. This is the most popular method

04/07/23 Database Management System 9

Cust-name

Social security

Cust-street

Cust-city

A/c no: Balance amt

johnson 1 xxx yyy A-101 500

smith 2 yyy xxx A-215 200

hayes 3 aaa bbb A-102 100

turler 4 bbb aaa A-201 100

jones 5 ccc ddd A-217 120

lincy 6 ddd ccc A-222 200

smith 2 yyy xxx A-201 --

johnson 1 xxx yyy A-201 --

Page 10: Data Models, Schemas & Instances

Here balance is not given in the first table. We have to represent the relationship b/w account no: and balance is shown in the next table

04/07/23 Database Management System 10

Cust-name

Social security

Cust-street

Cust-city A/c no:

johnson 1 xxx yyy A-101

smith 2 yyy xxx A-215

hayes 3 aaa bbb A-102

turler 4 bbb aaa A-201

jones 5 ccc ddd A-217

lincy 6 ddd ccc A-222

smith 2 yyy xxx A-201

johnson 1 xxx yyy A-201

Page 11: Data Models, Schemas & Instances

a/c no Balance amt

A-101 500

A-215 200

A-102 100

A-201 100

A-217 120

A-222 200

04/07/23 Database Management System 11

Page 12: Data Models, Schemas & Instances

Network modelNetwork model

Here data is organized as a collection of records and the relationships among data are represented by links.

It looks like an arbitrary graph.The collection of records connected to one

another by means of links, where link is an association between 2 records.

The operations on the n/w model are find, insert, delete, modify etc.

04/07/23 Database Management System 12

Page 13: Data Models, Schemas & Instances

johnson

1 ---

04/07/23 Database Management System 13

A-201 100

hayes 3 ---

turler 4 ---

lincy 6 ---

smith 2 ---

jones 5 --- A-217 120

A-222 200

A-102 100

A-215 200

A-101 500

Page 14: Data Models, Schemas & Instances

Hierarchical modelHierarchical modelHere data is represented by collection of records

and relationships among data by linksIt is similar to network modelThe only difference is that it takes the structure

of a tree

04/07/23 Database Management System 14

Page 15: Data Models, Schemas & Instances

johnson

1 ---

04/07/23 Database Management System 15

A-201

100

hayes

3 --- turler

4 ---

lincy

6 ---

smith

2 ---

jones

5 ---

A-217 120

A-222

200

A-102

100A-215 200

A-101

500

root

A-201

100

A-201

100

Page 16: Data Models, Schemas & Instances

DATABASE SCHEMADATABASE SCHEMAThe description of a database is called the database

schema It is the complete structure of database.Subschema is a part of the database pertaining to the

user’s need. To create a schema , the syntax is :

CREATE SCHEMA schemaname [AUTHORIZATION username] [schema element[…]]

Where schemaname is the name of the schema that is to be created. Authorization class is used for all created objects that can be later owned by the user.

04/07/23 Database Management System 16

Page 17: Data Models, Schemas & Instances

SCHEMA DIAGRAM FOR A SCHEMA DIAGRAM FOR A COMPANYCOMPANY DATABASE DATABASE

04/07/23 Database Management System 17

Ssn Emp_Name Age Mgr_Ssn Dept_NumberSalary

Employee

Dept_Number Dept_Name Dept_Location

Department

A displayed schema is called a schema diagram

Page 18: Data Models, Schemas & Instances

INSTANCESINSTANCESThe data in the database at a particular moment

in time is called a database state or snapshotIt is also called the current set of occurrences

or instances in the database

04/07/23 Database Management System 18

Page 19: Data Models, Schemas & Instances

AN INSTANCE FOR THE AN INSTANCE FOR THE EMPLOYEEEMPLOYEE TABLETABLE

04/07/23 Database Management System 19

Ssn Emp_Name Age Salary Mgr_Ssn Dept_Number

101 Mathew 32 50000 NULL 1

102 David 27 37000 101 1

103 Mary 23 20000 102 2

104 John 26 30000 101 2

105 Catherine 23 22000 104 2

Page 20: Data Models, Schemas & Instances

DATABASE LANGUAGESDATABASE LANGUAGESData Definition Language (DDL) – to specify

the database schemaData Manipulation Language (DML) - to

express database queries and updatesDDL and DML are not two separate languages.

Instead they simply form parts of a single database language, such as the widely used SQL (Structured Query Language)

04/07/23 Database Management System 20