Documente Academic
Documente Profesional
Documente Cultură
Schema Diagram
• for displaying database schema
• schema construct: an object in the schema
• no instance of records
Meta-data
• descriptions of the schema constructs and
constraints
• stored in the database catalog
Schema Evolution
• Schema change prompted by the change of
application requirements
Schemas, Instances and Database
State
Database Schema (meta-data): The description of a
database. Includes descriptions of the database
structure and the constraints that should hold on the
database.
Schema Diagram: A diagrammatic display of (some
aspects of ) a database schema.
Database Instance: The actual data stored in a
database at a particular moment in time. Also called
database state ( or occurrence, snapshot)
The database schema changes very infrequently. The
database state changes every time the database is
updated. Schema is also called intension, whereas
state is called extension.
Figure 2.1 Schema diagram for UNIVERSITY database
schema construct
Known data:
name of record types, data items
Figure 1.2
UNIVERSITY Database
External External External
schema 1 schema 1 schema 1
Conceptual schema
Physical schema
Disk
EEXTERNAL SCHEMA
External
Level CONCEPTUAL SCHEMA
Conceptual
Item_Number Character (6)
Item_Name Character(30)
Conceptual Price Numeric(5,2)
Stock Numeric(4)
Level
PHYSICAL SCHEMA
Physical
Stored_Item Length=50
Physical Item # Type = Byte(6), offset = 0, Index = Ix
Level Name Type = Byte(30), offset = 6
Price Type = Byte(8), offset = 36
Stock Type = Byte(4), offset = 44
29
Describes several views of the database based on the
database model.
Course(CourseNo:Integer, CName:String,
Credit:Integere, Dept:String)
Section(SecId:Integer, CourseNo:Integer,
Sem:Integer, Year:Integer, Instructor:String)
GradeReport(RegNo:Integer, SecId:Integer,
Grade:Char)
Describes the actual storage details of the relations
described in conceptual schema.
Faculty_Private(Fid:Integer, Salary:Float)
Hierarchical Model
Network Model
Relational Model
Hierarchical data model
A hierarchical database model is a data model in
which the data is organized into a tree-like structure.
The data is stored as records which are connected to
one another through links. A record is a collection of
fields, with each field containing only one value.
The entity type of a record defines which fields the
record contains.
A record in the hierarchical database model
corresponds to a row (or tuple) in the relational data
model and an entity type corresponds to a table (or
relation).
The hierarchical database model mandates that each
child record has only one parent, whereas each parent
record can have one or more child records. In order to
retrieve data from a hierarchical database the whole
tree needs to be traversed starting from the root node.
This model is recognized as the first database model
created by IBM in the 1960s
Network Data Model
The network model is a database model conceived as a
flexible way of representing objects and their
relationships. Its distinguishing feature is that the
schema, viewed as a graph in which object types are
nodes and relationship types are arcs, is not restricted to
being a hierarchy or lattice.
While the hierarchical database model structures data as
a tree of records, with each record having one parent
record and many children, the network model allows
each record to have multiple parent and child records,
forming a generalized graph structure. The network
model, in comparison to the hierarchic model, was that
it allowed a more natural modeling of relationships
between entities. Although the model was widely
implemented and used, it failed to become dominant for
two main reasons. Firstly, IBM chose to stick to the
hierarchical model with semi-network extensions in
their established products. Secondly, it was eventually
displaced by the relational model ,which offered a
higher-level, more declarative interface.
Relational Model
The relational model (RM) for database management
is an approach to managing data using a structure and
language consistent with first-order predicate logic, first
described in 1969 by Edgar F. Codd. In the relational
model of a database, all data is represented in terms
of tuples, grouped into relations. A database organized
in terms of the relational model is a relational database.
The purpose of the relational model is to provide
a declarative method for specifying data and queries:
users directly state what information the database
contains and what information they want from it, and let
the database management system software take care of
describing data structures for storing the data and
retrieval procedures for answering queries.
Attribute
A characteristic of an entity; something the entity is identified by
E.g., Customer name, Employee name
Domain
An attribute of an entity can have a value from a value set .This
Value set is called Domain.
Entity Type and Entity Set
Entity Type
It defines a set of entities that have the same properties or same
attributes. Each Entity type in the database is described by its name
and attributes. For example Company, Employee.
Entity Set
{
EmpId EmpName Address PhNo
E001 Rahul Delhi 1234567890
E002 Neel Mumbai 9876543211
E003 Hardik Bangalore 9765437623
E004 Priyanka Calcutta 9854321355
Types of Attribute
Simple Versus Composite
Single valued versus Multi valued
Stored and Derived
Degree of Relation
The degree of a relationship type is the number of participating entity
types.
Hence the Works_for relationship is of degree two.Because the
works_for Relation is between EMPLOYEE and DEPARTMENT.
Types of Relationship Depending Upon the Degree
Binary Relationship
The relationship having degree two is known as Binary relationship. e.g
The relationship between STUDENT and FACULTY
Ternary Relationship
The relationship type of degree three is called ternary relationship.For
example relationship Supply between the SUPPLIER,PART and
PROJECT
Relationship Cardinality
The cardinality ratio for a binary relationship specifies the number of
relationship instances that an entity can participate in. For example, in
the works-for binary relationship type, Department: Employee is of
cardinality ratio 1:N,meaning that each Department can be related to
numerous employees.
Keys
Alternate Key – Alternate Key can be any of the Candidate Keys except
for the Primary Key.
E.g. of Alternate Key is “Name, Address” as it is the only other
Candidate Key which is not a Primary Key.
Secondary Key – The attributes that are not even the Super Key but can
be still used for identification of records (not unique) are known as
Secondary Key.
DBMS Languages
Data Definition Language (DDL) Used by the DBA and database designers to
specify the conceptual schema of a database. In many DBMSs, the DDL is also
used to define internal and external schemas (views). In some DBMSs, separate
storage definition language (SDL) and view definition language (VDL) are
used to define internal and external schemas.In General storage definition
language (SDL) and view definition language (VDL) are the part of DDL.
SELECT C.name
FROM Students S, Takes T, Courses C
WHERE S.name=“Mary” and
S.ssn = T.ssn and T.cid = C.cid
sid=sid
name=“Mary”
CREATE TABLE
CREATE [TEMPORARY] TABLE [table name] (
[column definitions] ) [table parameters].
.
The DROP statement is distinct from the DELETE and
(non-standard) TRUNCATE statements, in that they do
not remove the table itself. For example, a DELETE
statement might delete some (or all) data from a table
while leaving the table itself in the database, whereas a
DROP statement would remove the entire table from the
database
ALTER statements
Alter - To modify an existing database object.
-Procedural DML:
• Also called record-at-a-time (record-oriented) or low-level DML
• Must be embedded in a programming language.
• Searches for and retrieves individual database records and uses looping
and other constructs of the host programming language to retrieve multiple
records.