Sei sulla pagina 1di 20

Data Models, Schemas & Instances And Database Languages

Data Model
A collection of concepts that can be used to describe the structure of a database Data model is a collection of conceptual(logical) tools for describing data, relationship etc. provides the necessary means to achieve data abstraction By structure of a database, we mean the data types, relationships, and constraints that should hold for the data

8/31/2012

Database Management System

Categories 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.

8/31/2012

Database Management System

CONTINUED
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, project Attribute - represents some property of interest that further describes an entity Ex: Employee's name or salary.

8/31/2012

Database Management System

TYPES OF DATA MODELS

Logical Data Model


Entity Relationship Model (ER model) Object Oriented Model

Representational or Implementation Data Model


Relational Model Network Model Hierarchical Model

8/31/2012

Database Management System

ENTITY - RELATIONSHIP (ER) MODEL


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

8/31/2012

Database Management System

EXAMPLE ER DIAGRAM FOR COMPANY DATABASE

Emp_Name Ssn Age

Dept_Name

Dept_Number

Dept_Location

Employee
Salary Dept_Number Mgr_Ssn

Works in

Department

8/31/2012

Database Management System

RELATIONAL MODEL
Uses a collection of tables to represent both data and the relationships among those data Each table has multiple columns, and each column has a unique name In 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 .

8/31/2012

Database Management System

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

Custname johnson smith hayes turler jones lincy smith johnson Social security 1 2 3 4 5 6 2 1 Custstreet xxx yyy aaa bbb ccc ddd yyy xxx Cust-city A/c no: yyy xxx bbb aaa ddd ccc xxx yyy
8/31/2012

Balance amt 500 200 100 100 120 200 --9

A-101 A-215 A-102 A-201 A-217 A-222 A-201 A-201

Database Management System

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
Social security 1 Custstreet xxx Cust-city yyy A/c no: A-101

Cust-name johnson

smith
hayes turler jones lincy smith johnson

2
3 4 5 6 2 1

yyy
aaa bbb ccc ddd yyy xxx
8/31/2012

xxx
bbb aaa ddd ccc xxx yyy

A-215
A-102 A-201 A-217 A-222 A-201 A-201
10

Database Management System

a/c no A-101 A-215

Balance amt 500 200

A-102
A-201 A-217 A-222

100
100 120 200

8/31/2012

Database Management System

11

Network 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.

8/31/2012

Database Management System

12

johnson 1 smith hayes turler jones lincy 2 3 4 5 6

-------------

A-101 A-215 A-102 A-201

500 200 100 100

A-217
A-222

120
200

8/31/2012

Database Management System

13

Hierarchical model
Here data is represented by collection of records and relationships among data by links It is similar to network model The only difference is that it takes the structure of a tree

8/31/2012

Database Management System

14

root

johnson

1 ---

smith 2 ---

hayes

---

turler

4 ---

jones

---

lincy

6 ---

A-101 500

A-215

200

A-102

100

A-217

120 A-222 200

A-201

100

A-201

100

A-201

100

8/31/2012

Database Management System

15

DATABASE SCHEMA
The 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 users 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.
8/31/2012 Database Management System 16

SCHEMA DIAGRAM FOR A COMPANY DATABASE


A displayed schema is called a schema diagram
Employee

Ssn Emp_Name Age Salary Mgr_Ssn


Department

Dept_Number

Dept_Number Dept_Name Dept_Location

8/31/2012

Database Management System

17

INSTANCES
The data in the database at a particular moment in time is called a database state or snapshot It is also called the current set of occurrences or instances in the database

8/31/2012

Database Management System

18

AN INSTANCE FOR THE EMPLOYEE TABLE

Ssn
101 102 103 104 105

Emp_Name Age
Mathew David Mary John Catherine 32 27 23 26 23

Salary
50000 37000 20000 30000 22000

Mgr_Ssn
NULL 101 102 101 104

Dept_Number
1 1 2 2 2
19

8/31/2012

Database Management System

DATABASE LANGUAGES
Data Definition Language (DDL) to specify the database schema Data Manipulation Language (DML) - to express database queries and updates DDL 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)

8/31/2012

Database Management System

20