Download presentation
Presentation is loading. Please wait.
Published byKatrina Quinn Modified over 8 years ago
1
Lecture 16 Introduction to Database Concepts
2
Differences Between Tables and Databases Database: table of info –iTunes –Automobile registrations –Demography tables
3
Canada’s Demographic Information
4
The Database’s Advantage Metadata advantage –Search by country –Compute world population
5
The Database’s Advantage Tags for database fulfill two roles –Identify type of data, –Define affinity of data
6
XML: A Language for Metadata Tags XML: Extensible Markup Language User creates tags
7
XML: A Language for Metadata Tags Matching tags Use on Web Written in plain text editor
8
Rules for Writing XML
9
XML Similar to HTML No spaces Case sensitive Whitespace b/w tags
10
XML Example Scenario –Create a database for Windward Islands archipelago in South Pacific –Develop tags Tahiti 1048 Affinity role
11
XML Recommended declaration (beginning of file) Version Encoding
12
Expanding the Use of XML Adding another archipelago Same file Same structure Additional tag:
13
Expanding the Use of XML Root element of XML database –Encloses all content – in previous example
14
New root element
15
Attributes in XML Attributes (like HTML) –Use for additional metadata, not for actual content –Quotes (single or double) Divergent …
16
Effective Design with XML Tags Identification Rule –Label Data with Tags Consistently (E.g. from previous XML?) Affinity Rule –Group Related Data (E.g.?) Collection Rule –Group Related Instances (E.g.?)
17
Effective Design with XML Tags Difference b/w Collection Rule and Affinity Rule –Both for grouping –Single instance or collection?
19
Other XML Examples Note CD catalog Breakfast menu http://www.w3schools.com/xml/xml_exam ples.asphttp://www.w3schools.com/xml/xml_exam ples.asp
20
Relational Databases Relational databases (RDBs) –Relationships among different kinds of data (e.g., Student, Course) –Description with XML –Answering queries
21
Entities Entity –Anything that can be identified by a fixed # of attributes Attributes –Names and values
22
Entities Entity defines a table (Island) –Name of entity is name of table Column represents attribute –Values in column are attribute values Row –Entity instance (often just entity)
23
Island Example Island entity as table
24
Island Example Island entity as XML Isabela 4588 1707 Fernandina …
25
Entities Attributes have data types –Number, date, image, etc. 14 Ensures proper format
26
Properties of Entities Table can be empty Order rows/columns irrelevant Each row represents different entity No two rows can be same
27
Keys Attributes distinguish rows –Single attribute –Multiple attributes Candidate key –Attribute(s) which uniquely defines entity
28
Keys Primary key –Candidate key used by database Keys must distinguish among potential entities Unique IDs can be assigned –E.g., M#
29
Keys North American Political Units –Candidate keys? CountryNameCapitalLargest City USAlaskaJuneauAnchorage CAAlbertaEdmontonCalgary … MXZacatecasZacatecasZacatecas
30
Atomic Data –Values stored for attributes –Not separable Separate fields for street, city, state, etc. –Exceptions Dates, time, and currency E.g., 01/01/1970 (with format dd/mm/yyyy)
31
Database Schemes How to define a table? –Tags –Schema Table name Attributes and data types Primary key
32
Database Table Definition
33
Database Tables Recap Entities: rows; Columns (fields): attributes Rows and columns unordered Tables and fields should have mnemonic names Fields must be atomic One or more attributes define the primary key
34
Operations on Tables Relational database: collection of tables Key operation of database: search User queries db, s/w searches
35
Operations on Tables Operations on tables produce tables (which may be empty) Operations –Select –Project –Union –Difference –Product –Join
37
Select Operation Select –Takes rows from one table to create new table Select Test From Table Test applied to each row
38
Select Operation Test is short formula Test uses –attribute names –constants –relational operators <, ≤, ≠, =, ≥
39
Select Query Select Interest=“Beach” From Nations Select Lat > 40 AND N_S = ‘N’ From Nations
40
Project Operation Project –Builds a new table from the columns of an existing table Project Field_List From Table
41
Project Query Project Name, Domain, Interest From Nations
42
Union Operation Union –Combine two tables with same attributes Table1 + Table2
43
Union Query At45OrBelow = (Select Latitude >= 45 AND N_S = ‘S’ From Nations) ExtremeGovt = At60OrAbove + At45OrBelow
44
Difference Operation –Remove common rows in two tables –Same fields Table1 − Table2 –E.g., Nations – At60OrAbove
45
Product Operation Product –Multiplying tables together –Creates “super table” Table1 × Table2 –Each row of Table2 is appended to each row of Table1
46
Product Example
47
Super = Nations × Travelers New table with ten fields Results in
49
Product Operation Merges info that may not “belong together” Super table usu. “trimmed down”
50
14-50 Product Example, Trimmed Super = Nations x Travelers Assign = (Select N_S=‘S’ AND E_W=‘W’ AND Friend=‘Isabella’ From Super) + (Select N_S=‘S’ AND E_W=‘E’ AND Friend=‘Brian’ From Super) + (Select N_S=‘N’ AND E_W=‘E’ AND Friend=‘Wen’ From Super) + (Select N_S=‘N’ AND E_W=‘W’ AND Friend=‘Clare’ From Super) Master = Project Name,Friend From Assign
51
Join Operation Join –Combines two tables, but it doesn’t necessarily produce all pairings –Match on common fields Table1 Table2 On Match
52
Join Applied Join –A “lookup” operation on tables For each row in one table, locate a row (or rows) in the other table with the same value(s) in the common field(s) –If found, combine the two; if not, look up the next row
53
Master Northern On Master.Name = Northern.Name
54
Structure of a Database Two forms of tables –Physical database Stored on disk –Logical database (view) Created for users on-the-fly Customized for their needs Separate management from presentation
56
Physical Database Physical database –Designed by database admins –Efficient storage –Avoids redundancy O/w update problems
57
Logical Database Logical database –Shows users view of info they want –Created on demand –Generated from copy stored in physical database
58
Queries Query –Specification using five operations and Join –Results in new table –Written in SQL (Structured Query Language) standard
59
Defining Physical Tables Defining DB: Database Schemes (schema) –Metadata specification of a database’s tables –Gives the table names, fields, types –Used to analyze a DB design
62
14-62 Connecting Database Tables by Relationships Student and Home_Base tables –Can have different security access restrictions Access Home_Base data without having access to more sensitive data in Student –Separate tables but not independent Student_ID connects the two tables (establishes a relationship between them) –Primary key
63
The Idea of Relationships Relationship –Correspondence between rows of different tables
64
Relationship Examples Familiar relationship examples –Father_Of relationship between a man and his child –Daughter_Of relationship between a girl and her parent –Employed_By relationships between people and companies
66
Practical Construction Using QBE Database systems can make development of a Join easy Query By Example (QBE) in Microsoft Access –Software provides a template of a table, and we fill in what we want in the fields (example) –Software generates query
69
Summary XML for metadata Database tables Table queries –Select, project, union, product, difference, join –SQL
70
Summary Relationships Physical vs. Logical database QBE
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.