Stephen C. Hayne 4 User Data n Data about –Entities or objects »employees, departments, products.... »students, courses, professors –Attributes »SS#, name, address, salary, department –Relationships (bi-directional) between entities or objects »Employees assigned to Departments. »Departments are assigned Employees. »Students take Courses. »Courses are taken by Students.
Stephen C. Hayne 5 Users’ Data n For relational databases, tables with rows and columns representing unique records and attributes n Not all tables are equally desirable: What is the problem with this? MovieRatingStar Saving Private RyanGTom Hanks Saving Private RyanGMatt Damon TitanicRKate Winslet TitanicRLeonardo Di Caprio
Stephen C. Hayne 6 Relationships Between Entities Relationships Between Entities n Cardinality –the number of entities of each type that may participate in the relationship –may be »1:1 (one-to-one) »1:M (one-to-many) »M:N (many-to-many) –to determine cardinality, ask: »for each A, how many B’s may be related? »for each B, how many A’s may be related?
Stephen C. Hayne 7 Minimum & Maximum Cardinality n For each A, what is the minimum and maximum number of related B’s. n For each B, what is the minimum and maximum number of related A’s. n If the minimum is zero –The relationship is “optional.” –The entity may or may not (sometimes) participates n One or more –The relationship is “mandatory. The entity must (always) participate.
Stephen C. Hayne 8 Relationship Examples n Business Rules n 1 : 1 (one-to-one) –Each faculty member is always assigned to one office. –Each office is sometimes assigned to one faculty member. n 1 : M (one-to-many) –Each employee is always assigned to one department. –Each department is always assigned many employees. n M : N (many-to-many) –Each student always takes many courses. –Each course is sometimes taken by many students
Stephen C. Hayne 9 What is the cardinality between... n Cities and zip codes? –Each city ? has ? zip codes. –Each zip code ? corresponds to only ? city. ===> 1:M n People and phone numbers? –Each person ? has ? phone numbers. –Each phone number ? belongs to ? persons. ===> M:N
Stephen C. Hayne 10 Four Data “Models” n Hierarchical n Network n Relational n Object Oriented
Stephen C. Hayne 11 Hierarchical n Support 1:1 and 1:M Relationships n Parent - Child Viewpoint n Parent (Owner) record has one or more children (Members) –Customer has one checking account –Checking account has many transactions n Each child (member) has only one parent (owner)
Stephen C. Hayne 12 Example Hierarchy: Banking Database Customer# | SS# | Address|... Checking Acct. # | Current Balance | Statement Date Check# | Date | Payee | Amount Deposit# | Date | Amount Savings Acct. # | Current Balance | Statement Date
Stephen C. Hayne 13 Simple Network n Children may have more than one parent n Example: Joint checking account John DoughJayne Dough Checking Acct. # 999
Stephen C. Hayne 14 Complex Network n Supports M:N relationships Students CoursesSecurities Portfolios
Stephen C. Hayne 15 Relational Model n Data organized into tables (relations) n Tables have columns (attributes) n Data stored in rows (tuples) n Each row has a unique primary key n Relationships included in the data
Stephen C. Hayne 16 Relational Tables and Data EMPLOYEE(SS#, EmployeeName, EmployeeAddress, Department_ID) DEPARTMENT(DEPARTMENT_ID, DepartmentName, Manager) EMPLOYEE SS#EmployeeNameEmployee AddressDepartment_ID 1223John DoughWall StreetAcct 3214Jayne DoughWall StreetFin 7653Jill OutleyWellbornAcct DEPARTMENT DEPARTMENT_IDDepartmentNameManager AcctAccountingBeane Kounter FinFinance Cash McCall
Stephen C. Hayne 17 Metadata n “Data about the data.” n Data dictionary - Data Definition Language –For each table or record »Table or record name »Number of columns or Fields »Primary key –For each data item »Date item name »Data type (Numeric, date, text...) »Size
Stephen C. Hayne 18 Metadata n Use DDL n Description of database structure n System tables (e.g., tables and columns)
Stephen C. Hayne 19 Indexes n Usually “inverted lists” for accessing data. DepartmentEmployees Acct1223, 7653 Fin3214
Stephen C. Hayne 20 Indexes and other data structures n Improve performance for sorting and searching n But: overhead of updating n Who has Info Systems as major?
Stephen C. Hayne 21 Application Metadata n Structure & format of application components –Forms –Reports –Queries –Etc.
Stephen C. Hayne 22 Forms n Data entry n Hiding IDs
Stephen C. Hayne 23 Queries n By example (QBE) n By form n By DML (Data Manipulation Language)
Stephen C. Hayne 28 The Database Schema n Tables n Relationships n Domains –constraints on values that a column may have. –e.g. date, integer number, text of length N... –ID’s (primary keys) must be unique n Business rules –Rules or policies that must be enforced in the database. »Each employee is always assigned to one department. »Each department is always assigned one or more employees.
Stephen C. Hayne 29 Summary n Database Systems include –the database consisting of »Data, Metadata, Indexes, Application metadata –the database management system (DBMS) »Design Tools & Run Time Tools