Database Slides
Database Slides
• Database System: The DBMS software together with the data itself.
Sometimes, the applications are also included. ( Software + Database )
SCHEMA VS METADATA
• Metadata: The extra information generated when you take a picture with your
phone such as date, location, etc.
• Schema: The layout of a website such us where is the main title, content, etc.
THREE LEVEL/SCHEMA ARCHITECTURE
• External – What the user sees: focus on what different types of users will see when viewing the
database. They are concerned with what data the user will see and how the data will be
presented to the user.
• Conceptual – The logical model: focus on the logical nature of the data representation. They are
concerned with what is represented rather than how it is represented.(define database structures
such as tables and constraints)
• Internal – The physical model: place the emphasis on how the data are represented in the
database or on how the data structures are implemented.
MAPPINGS
• High Level or Conceptual data models provide concepts that are close to the
way many users perceive data, entities, attributes and relationships. (Ex. ERD)
• Physical data models describes how data is stored in the computer and the
access path needed to access and search for data.
ENTITY RELATIONSHIP MODELING
• Entity - An entity is a thing in the real world with an independent existence. Physical existence
(for example, a particular person, car) or conceptual existence (for instance, a job, or a
university course). Types of entities: Weak- Regular
• Attribute - The particular properties that describe the entity. An EMPLOYEE entity may be
described by the employee’s name, age, address and salary attributes.
WEAK ENTITY TYPES
• DEPENDENT entity is identified by the dependent’s first name and birth date,
and the specific EMPLOYEE that the dependent is related to. DEPENDENT is a
weak entity type with EMPLOYEE as its identifying entity type via the
identifying relationship type DEPENDENT_OF.
• Another example is a parent entity in a school database.
TYPES OF ATTRIBUTES
• Key: an attribute whose values are distinct (unique) for each entity and can be used to uniquely identify the record.
• Single/Simple: Attributes that are not divisible and have a single value for a particular entity instance.
KEY ATTRIBUTE
• Composite Key: the combination of the attribute values that together form a
key and must be distinct for each entity. For example, ID and Application_no
• Candidate Key: when an entity type has more than one key, those are
candidate keys
RELATIONSHIPS
1 1
Emp manage Dept
Partial Full
PARTICIPATION EXAMPLE
• Each customer has one Account identified by unique Account number, amount,
last transaction date (Day, Month and Year).
• The system records Transaction number, Transaction type, Transaction date,
Transaction amount and time. The system records the branch name where the
transaction occurred.
• A Customer can make any type of transactions (Withdrawal or Deposit) from
any branch of the bank.
ER-TO-RELATIONAL MAPPING
• If n > 2 then:
• Create a new third table
• Add FKs to the new table for all parent tables
• Add simple attributes of relationship to the new table if any
DATABASE CONSTRAINTS
• It is not mandatory
• It ensures at database level that the data is accurate and reliable.
• Having those rules enforced at database level rather than in the application
or presentation layer ensures that the rules are consistently enforced no matter
who manipulates the data and how it is manipulated.
SAME IN EVERY DBMS ?
• Not all database management systems support the same types of constraints.
• There may be special features or considerations for the specific system.
• The syntax for creating constraints also depends on the specific RDBMS.
• Not Null
• Unique Key
• Primary Key (Not Null + Unique)
• Referential Integrity (FK)
• Domain of Values (Check)
• Default
NOT NULL
• Join clause to combine rows from two or more tables based on a related
column between them.
TYPES OF JOINS
INNER JOIN
LEFT OUTER JOIN
RIGHT OUTER JOIN
FULL OUTER JOIN
SELF JOIN
EXAMPLE
• The following SQL statement matches customers that are from the same city
TABLE A & TABLE B
RESULT !!!!
ANOTHER EXAMPLE
TWO INSTANCES OF SAME TABLE
• Employee • Manager
RESULT
NON-EQUI JOIN