autumn orange logo
  • [Landing]
  • [Letters]
  • [Crafts]
  • [Collections]
  • autumn orange logo
  • [Landing]
  • [Letters]
  • [Crafts]
  • [Collections]
  • user profile picture
  • [Coven]
  • [Profile]
  • user profile picture
  • [Coven]
  • [Profile]
  • a orange logo

    Introduction to Databases

    Quick Nav
    Create E-R (entity-relationship) Diagrams and written descriptions
    Working with Weak Entities
    Creating E-R diagrams and written descriptions for superclasses and subclasses

    Computing as a utility

    The idea that computers can be turned on and off as needed allows companies to align technology expenditure with requirements at any time is computing as a utility, with other utilities being water, power, etc, the supply is effectively unlimited so the only factor is demand. Side thought; UTILITY MARKETS, NOT PLASTIC

    Foundations

    Database: Noun
    A database is a large collection of related data, personal is a few MB of data, medium is GB to TB of data, large is petabytes.

    A database is šŸ—ƒļø:

    Database example šŸ—žļø :
    Airline data

    Database Management Systems (DBMS)

    A database management system (DBMS) is a collection of software components that lets you

    Why not use the flat file method? (spreadsheets)

    Redundancy! šŸ”
    Data management is less flexible for creating and managing data which can lead to duplicate entries.

    Program data dependency

    No data integrity

    How does a database fix this?

    Database questions (queries)

    Database benefits

    File processing systems

    Hierarchical model

    Network Model

    Relational Model

    later models

    Users' views of a database

    Three-Schema Architecture

    Data independence / abstraction

    Schema vs Snapshot

    The Making of a Database

    Entity-Relationship (E-R) Model

    Notional Conventions

    How to make an E-R Diagram
    • Entities RECTANGLE
      • STUDENT, INSTRUCTOR, COURSE
    • Atributes OVAL
      • Name, address, phone_number, code, fee, length
      • Put an additional OVAL around an attribute to indicate that it can have multiple values
    • Relationships DIAMOND with a line
      • enrolled, teaches

    Other Indicators:

    • Double box = Weak entity
    • Underline = Unique Identifier
    • Double Outline / bubble = Multiple values
    • Derived attribute = Dotted oval (not solid)
    • Optional = No special indicator, explain it in documentation.
    • Single line -- Optional participation
    • Double line == Mandatory participation
    Creating Written E-R Descriptions

    An ENTITY description includes...

    • What it represents
    • What attributes it has
    • What causes it to be created/deleted
    • What instances to include/exclude

    An Attribute description includes...

    • What it represents
    • Maximum and minimum number of values recorded (eg. if you have multiple students there will be multiple duplicate attributes on an object)
    • Any dependencies on other attributes
    • Add a sentence to each entity identifying its key)

    A Relationship description includes

    • Name of relationship
    • Describe both directions of relationship, with names of entities involved preceding and and following the name of the relationship
    • For each instance of one entity, specify how many instances of the other entity it must (minimum) and may (maximum) relate to, and vice versa
    • Explain any additional restrictions
      • Participation keywords: Can, may, may not, might, will, must, exactly
      • Cardinality keywords include: One, one or more, more than one, many, several

    Types of Attributes

    Carnality Constraints

    Carnality constraints determine how many relationship instances each entity instance may participate in. Cardinals are numbers which refer to things, eg, 3 chairs, two cars, 4 cars, Ordinal numbers are relative, eg, 3 greater, 4 fewer, etc.

    Three types of relationships:

    Constraints

    Normalization

    Dependencies are reduced as you apply normal forms, normalization itself is the process of minimizing redundancy & dependencies by separating data elements into related tables


    Record / Instances

    Entity instances are rows in a database while attributes are columns

    Participation Constraints

    Participation determines if every entity instance must participate in some relationship instance

    The Four Participation Types

    Weak Entities

    Record type: Weak Entities

    A weak entity is an instance that depends on other instances for their existence. The associated entity is the owner entity, and the relationship between a weak entity and its owner is called an identifying relationship.
    A weak entity only has a partial key which uniquely identifies the instances associated with a particular instance of the owner entity.

    Example

    A social media user account is an entity, which can create messages, which are weak entities. The messages cannot exist without an associated account.

    E-R Diagram representation of weak entities

    • A weak entity is represented by a double rectangle
    • Identifying relationship is represented by a double diamond
    • Partial key is represented by a dashed underline

    Written representation of Weak Entities

    • Entity: "No WEAK_ENTITY will be included without a corresponding OWNER_ENTITY.
    • Attributes: "No set of attributes is sufficient to uniquely identify each WEAK_ENTITY. Each WEAK_ENTITY is identified by it's partial key together with the key of the related OWNER_ENTITY."

    Relationships with attributes and intersecting entities

    • Relationships can sometimes have attributes, in this case you can sometimes replace the relationship and attribute with a weak entity derived from the intersection of the other two strong entities
    • New relationships are identifying relationships
    • To represent it in writing, say "A NEW_ENTITY represents a combination of a ENTITY1 and a ENTITY2", then describe its attributes, and state that it is a weak entity, thus "There is no attribute that uniquely identifies a NEW_ENTITY; instances of NEW_ENTITY will be identified by the key1 and key2 of the related instances of ENTITY1 and ENTITY2"

    Relationship Types

    Composite vs Simple attributes

    Composite attributes contain derived or sub attributes while simple attributes stand on their own.

    2024-09-18 Super classes and Sub classes

    Super classes contain only attributes which are shared between all sub classes, while sub classes contain attributes which are purely self contained and not shared.

    Specialization vs Generalization

    Specialization constraints

    E-R Diagrams of super classes and sub classes
    1. Lines are drawn from superclass to circle, and from circle to each subclass
      1. Line to circle is single for partial specialization, double for total specialization
    2. Circle contains ā€˜d’ for disjointness constraint, 'o’ for overlapping constraint
    3. Lines from circle to subclasses contain subset symbols (with open end toward circle)
    Written descriptions of Superclasses

    Partial, disjoint: Every superclass may also be one of the following: list subclasses
    Partial, overlapping: Every superclass may also be one or more of the following: list subclasses

    Total Disjoint: Every superclass MUST also be exactly one of the following: list subclasses
    Total, overlapping: Every superclass must also be one or more of the following: list subclasses

    The relational model

    A relational database is made up of two-dimensional tables called relations, each representing some entity recorded in the database.
    Each row of a relation is a tuple, or record, representing one instance of that entity.
    Each column of a relation is an attribute for which each tuple has a value assigned, and a domain which from which its values are taken. A domain consists of atomic values- no multi-valued or divisible attributes are allowed.
    Lastly, missing or unknown values are indicated by NULL.

    Domains (data types)

    Properties of a Relation

    1. Each relation (entity instance) has a unique name (key) in the database
    2. Each attribute has a unique name
    3. Each entry of a relation contains a single value from its attribute's domain
    4. The order of the records does not matter
    5. The order of the attributes does not matter
    6. No two records in a relation are identical

    DBMS Constraints

    E-R mapping

    Is the process of turning an E-R Model into a set of relations in the relational model.

    1. Map strong entities
    2. Map weak entities
    3. Map binary many-to-many relationships
    4. Map binary one-to-one relationships
    5. Map binary one-to-many/many-to-one relationships
    6. Map unary relationships
    7. Map ternary (and higher) relationships
    8. Map generalizations/specializations

    Strong entities become a table, the key of an entity becomes the primary key of the table, atomic attributes (not derived and has constraints so it's not null) become columns. Multi-valued attributes become new tables with columns for different values and it's own primary key, the original primary key from the parent becomes the foreign key in the new table.

    Classes of SQL Commands

    The Schema of a Relation

    SQL Domains

    SQL Queries


    Generally, the form is SELECT, WHERE, GROUP BY , HAVING, ORDER BY (in order)
    Others include FROM, DISTINCT

    INSERT INTO

    It's like for adding things and stuff but more fast I think... Make sure columns match 1:1!

    INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
      VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
    

    Equijoins

    These simply sort data where columns match between multiple tables, usually a primary and foreign key.

    select *
    from mydb.STUDENT, mydb.RESULT
    where mydb.STUDENT.SNO = mydb.RESULT.SNO
    and mydb.RESULT.GRADE > 90
    

    Outer joins

    Two tables are selected and all rows from the specified table are returned, however if there is a match, data from the other table is returned as well.

    select bc.lastname, bo.orderid, bo.orderdate
    from Book_customer bc LEFT OUTER JOIN Book_order bo
    using (customerid);
    

    Join On

    Join ON just sandwiches results from two tables together. Not much to it. Not always suppoted.

    select bc.lastname, bo.orderid, bo.orderdate
    from Book_customer bc JOIN Book_order bo
    ON bc.customerid = bo.customerid
    AND bc.lastname = 'GIRARD';
    

    Natural Join

    Natural join needs identical columns which have the same data type and simply merges return data.

    select *
    from mydb.STUDENT
    NATURAL JOIN mydb.RESULT
    where GRADE > 93
    

    Self Join

    Pro tip: Don't lick frozen poles in winter. This joins a table to itself, which is helpful for when you need to find sets of data stored in the same table.

    select customer.lastname, referredby.lastname
    from customer.book_customer, referredby.book_customer
    where refferedby.referred = customer.customerid
    

    Update

    Update a record! Change names, details, etc.

    UPDATE customer.
    SET customer.book_customer = 'Joe'
    where customer.id = 24245
    

    SQL Wildcards

    _ = One character
    % = Any number of characters (eg, B% could be B0, Boo, Boston, or Boooooo)

    SQL Math

    Count, sum, min, max, and avg all work in SQL!