340 likes | 479 Views
Advantages of using a Data Base. Controlling Redundancy Restricting Unauthorized users Providing Persistent storage for program objects Providing storage structure Providing Backup and Recovery Multiple User Interfaces Complex Relationships Enforcing Integrity constraints. Data Model.
E N D
Advantages of using a Data Base • Controlling Redundancy • Restricting Unauthorized users • Providing Persistent storage for program objects • Providing storage structure • Providing Backup and Recovery • Multiple User Interfaces • Complex Relationships • Enforcing Integrity constraints
Data Model • Underlying the structure of data base • Collection of conceptual tools • Defines data, relationships, constraints etc Categories of Data Models • High- level or Conceptual • Representational • Low-level or Physical
Object Based Logical Model Network Model Hierarchical Model • Entity –Relationship model • Object – oriented model • Semantic model • Functional data model
Schema:The description of the data base • Schema diagram: The diagrammatic representation of the schema • Schema Construct: Each object in the schema • Snapshot: The data in a database at a particular moment of time current set of occurrences current set of instances • Meta-data : Storing of description of schema constructs and constraints is called metadata
Three Schema Architecture • External Schema describes: • part of the database that a particular user group is interested in and hides the rest of the database from that user group. • Conceptual Schema: • Describes the structure of the database • Hides the physical storage structures • Describes data types, relationships, constraints etc • Also known as high level data model • Internal Schema describes: • the physical storage of the database • uses physical data model, • describes the complete details of data storage
Data Independence Logical Data Independence • Capacity to change the conceptual schema without having to change external schemas or application programs • Changing conceptual schema means: changing constraints, expanding or reducing database etc. • Only view definitions the mappings need to be changed Physical Data Independence • Capacity to change the internal schema without having to change conceptual schemas • Changing internal schema means: reorganizing physical files, creating access rights etc
Data Languages DDL( Data Definition Language) • Underlying the structure of data base • Collection of conceptual tools • Defines data, relationships, constraints etc DSL( Data Storage Language) • Specify internal schema VDL( View Definition Language) DML( DataManipulation Language) • High level or non-procedural DML • Low-level or procedural DML
DBMS Interfaces • Menu Based Interfaces for web-browsing • Forms-based Interfaces • Graphical User Interfaces • Natural Language Interfaces • Interfaces for parametric Users • Interfaces for the DBA
Data base system Utilities • Loading • back-up • File – organization • Performance monitoring
Two-Tier Client/server architecture Client Client Client Print Server Print Server Print Server Logical two-tier C/S architecture Physical two-tier C/S architecture
Three-Tier Client/server architecture GUI, Web Interface Client Application programs, Web Pages Application Server Or Web Server DBMS Data Base Server Logical three-tier C/S architecture
Entities, attributes etc • Entity: An object with physical existence • Attribute: A particular property that describes an entity • Simple or Atomic attributes: Attributes that are not divisible • Composite attributes: Can be divided into smaller sub parts • Composite attributes can form a hierarchy • Single valued attribute: An attribute which has a single value for a particular entity • Multi-valued attribute: An attribute which has a more than one value for a particular entity • Stored and derived attribute: age attribute is derived from birth-date attribute • Complex attributes: a structure of many attributes.
Entity types, sets, keys, domains • Entity Types: An entity type defines a collection of entities that have the same attributes • Entity set: Collection of all entities of a particular entity type in the database at any point of time is called an entity set Accommodation - entity type Student - entity type E1 Josna, III B.Sc,College hostel E2 Sharal , IIBSC, Outside hostel E3 Nishath, IIIBCA, with Parents … … … e1 06100, Josna, III B.Sc e2 07101, Minu , IIBSC e3 06320,Vianni,IIIBCA … … …
key attribute: An attribute whose values are distinct for each individual entity in the entity set • Weak entity type: An entity type which has no key attribute • Value sets or Domains: the set of values that may be assigned to an attribute for each individual entity • The value of an attribute A for an entity e is referred to as A(e) • Relationship: An attribute of one entity type referencing to an attribute of another entity type; • Eg: Name of “Accommodation” entity type referencing name of student entity type
A relationship type R among n entity types E1,E2,….En defines a set of associations • Mathematically, the relationship set R is a set of relationship instances riwhere each ri associates n individual entities(e1,e2,e3….en) Employee Works for Department e1 e2 e3 e4 e5 e6 r1 r2 r3 r4 r5 r6 d1 d2 d3 d4
Degree of relationship: no.of participating entity types. Given an example of relationship with degree 3.(Supplier, Part and project) • Role Names: Signifies the role that a participating entity plays in each relationship Supply Project Supplier s1 s2 . . r1 r2 r3 r4 r5 r6 j1 j2 j3 j4 Part p1 p2 p3 .
Recursive relationships: The same entity type participates more than once in a relationship in different roles. Such relationship types are called as recursive relationships Supervision Employee e1 e2 e3 e4 e5 e6 r1 r2 r3 r4 r5 r6
Cardinality Ratio: Maximum number of relationship instances that an entity can participate in. • 1:1 or 1:n or n:1 or m:n • Participation constraint: Specifies whether the existence of an entity depends on its being related to another entity via the relationship type.
E-R Diagrams Key attribute Entity Multivalued attribute Weak Entity Composite attribute Relationship Derived attribute Identifying relationship R E1 E2 attribute R E1 E2
Relational data model concepts • The relational model represents the database as a collection of relations • Informally a relation is called as “table” • A row is called as a ‘tuple’ • A column header is called as an ‘attribute’ • A ‘Domain ‘ D is a set of atomic values for an attribute • A ‘relation shema’ R is denoted by R(A1,A2,A3….,An) is made up of relation name R and list of attributes (A1,A2,A3….,An) • The degree of a relation is the number of attributes n of its relation shema • n-tuple is an ordered list of n-values t =< v1,v2,v3,….vn) where each value vi, is an element of domain(Ai) or is a NULL value. • A relation state/relation instance r of the relation schema R(A1,A2,A3….,An) is denoted by r(R) and is a set of n-tuples r = {t1,t2,t3,…..tm)
Student Relation Attributes Relation Name Tuples
Mathematical definition for “relation” A relation r( R) is a mathematical relation of degree n on the domains dom(A1), dom(A2),…..dom(An), which is a subset of The Cartesian product of domains that define R The Cartesian product specifies all possible combinations of values from the underlying domains. Cardinality is the total number of values in a domain and it is denoted by |D|. The total number of tuples in the Cartesian product is: |dom(A1)| X |dom(A2)| X ………….. X |dom(An)|
Characteristics of relations • Ordering of tuples in a relation( Not predefined but can be done logically) • Ordering of values within a tuple • Values and NULLs in a tuple • Interpretation of a Relation
Constraints Restrictions imposed on the actual values in a database state There are three main categories: • Inherent model-based constraints: Constraints that are inherent in the data model • Schema based constraints: Constraints that can be directly expressed in the schemas of the data model that is specifying constraints in DDL • Application based constraints: Constraints that are expressed and enforced by the application programs
Domain Constraints Domain constraints specify that within each tuple, the value of each attribute A must be an atomic value from a domain dom(A). The data type for an attribute is domain constrain Key Constraints • A relation is defined as a set of tuples • All elements of a set are distinct • So all tuples in relation must also be distinct • It means no two tuples in any relation instance r should have the same combination of for all their attributes • For any two distinct tuples t1 and t2wehave the constraint that: t1 [Sk] ≠t2[SK] where SK is called as SUPER KEY of the relation schema R. • Super key can have redundant values but a key or primary key value cannot repeat in any tuple.
Key A key satisfies two constraints: Two distinct tuples in any state of the relation cannot have identical values for the attributes in the key It is minimal superkey- that is a super key from which we cannot remove any attributes and still have the uniqueness constraint hold. Candidate Key In general a relation schema may have more than one key. In such cases each of the keys is called as candidate key. One of the candidate keys denoted as primary key Primary key is the candidate key whose values are used to identify tuples in a relation
Entity Integrity and Referential Integrity Constraints • The entity integrity constrain states that no primary key value can be null • The referential integrity constraint is specified between two relations and is used to maintain the consistency among tuples in two relations Foreign Key • A set of attributes FK in relation schema R1 is a foreign key of R1 that references relation R2 if it satisfies the following two rules: • The attributes in FK are said to reference or refer to the relation R2 • A value of FK in a tuple t1 of the current state r1(R1) either occurs as a value of PK for some tuple t2 in the current state r2(R2) or is null. • Here we have t1[FK]=t2[PK] and we say that tuple t1 references to the tuple t2 • Also R1 is referencing relation and R2 is referenced relation
Primary Key Foreign Key