DATABASES – I IS 524 Dr. Chandra Amaravadi
IN THIS PRESENTATION.. Importance of databases Real world concepts: entities, eclasses, attributes Data model Organization concepts DBMS & DBMS activities and functions
NEED FOR DATABASES All organizations need to manage information A church needs to maintain information on donations A consulting company needs to manage its contacts A doctor needs to know if a patient is allergic to a particular medication. An airline exec needs to know occupancy on a flight. Information is the lifeblood of an organization.
NEED FOR DATABASES.. To get information when we need it, it needs organization. A database can be thought of as an organized collection of information. What is information used for? What is it about? Where does it orginate?
BASIC DATA CONCEPTS
REAL WORLD CONCEPTS Entities Entity Classes Attributes Data models Database approach/philosophy
ENTITIES Individual examples of things and objects are called entities. They are modelled only as a collection.
WE ARE MORE INTERESTED IN Eclasses has has Organization customers departments has eclasses has product Sales/vendor Organization deals with many eclasses
ENTITY CLASSES HAVE PROPERTIES Properties are called attributes customers Departments Dept. code, name, manager, budget machines/ parts Sales/vendors
DISCUSSION Classify the following as entity, entity class or attribute John (as a person) San Francisco (as name of a city) Customer Book Store# Customs Microsoft Microsoft employees The book “The Second Machine Age” Invoice Production
SUMMARY OF CONCEPTS Entity – Individual example of person, place or thing. Entity Class – Collection of related entities. Attributes – Properties of entity classes about which we would like to collect information. Eclasses & attributes are used in developing data models
DATA MODELS (ER MODELS) Abstract view of the data & relationships Captures relationships between eclasses Supports DB design & implementation Relationship between students and courses? between doctors and patients? between teams and players?
DATA MODELS… Three types of relationships among entity classes A B A B 1:1 For each value of A, one and only one value of B and vice versa. A B 1:M A For each value of A, many values of B, but for each B only one A. B M:N A B For each value of A, many values of B and vice versa.
DISCUSSION Identify the types of the following relationships Company -- president Instructor -- students Flights -- pilots City -- convention centers Club -- members Team – players (professional) Company -- city Books – authors Artists -- records
THE DATA BASE APPROACH Entity classes File 1 File 2 Organization cust. File 2 emp. Organization Data model Data base
BASIC ORGANIZATION CONCEPTS
BASIC ORGANIZATION CONCEPTS data vs information attribute primary key file record schema
DEFINING DATA Data: Data consists of raw facts e.g. 298-2034 USA 46 29 29 104 China 38 27 23 88 Russia 24 26 32 82 Great Britain 29 17 19 65 Germany 11 019 14 44 Japan 7 14 17 38 Australia 7 16 12 34 France 11 11 12 34 Are raw facts useful? meaningful?
INFORMATION Information: collection of facts, data presented in a context, elaboration of data. Country Gold Silver Bronze Total USA 46 29 104 China 38 27 23 88 Russia 24 26 32 82 Great Britain 17 19 65 Germany 11 14 44 Japan 7 Australia 16 12 35 France 34
INFORMATION AS A COLLECTION OF FACTS Name: Chris Nash DOB: 2-4-1965 Profession: Engineer Address: 415 Walnut street. Details describe a person more. They are called ______
NOTION OF A RECORD Collection of facts is called a ________ Acct#: 4555950 Date: 12/5/14 Time: 4:48 pm Merchant: WIU Union Card type: Master Card Issuer: First Bank It is actually a collection of __________ values
ONE ATTRIBUTE HAS A UNIQUE VALUE Which of these has a unique value? Acct#: 4555950 Date: 12/5/14 Time: 4:48 pm Merchant: WIU Union Card type: Master Card Issuer: First Bank The unique attribute is called ___________. 3300 3305 3313
ORGANIZATION OF DATA/ INFORMATION Transaction#: 55643 Date: 12/5/15 Time: 4:08 pm Merchant: Vitales Card type: Master Card Issuer: First Bank Transaction#: 55644 Date: 12/6/15 Time: 4:10 pm Merchant: WIU Union Card type: Master Card Issuer: First Bank Observations about these two “units” of data?
TRADITIONAL CONCEPT OF A FILE Assume the following is stored somewhere, Western Illinois University strives to maintain a community which values academic excellence; institutional integrity; and justice, equity, and diversity. Such an environment is essential in fostering the intellectual growth and personal development of all students. Each member of the University community shares responsibility in maintaining conditions which support the University's purpose. The Code of Student Conduct is designed to provide basic guidelines to advance the University's mission as a premier educational institution. A traditional file is a collection of characters
CONCEPT OF A DATABASE FILE Transaction#: 55643 Date: 12/5/15 Time: 4:08 pm Merchant: Vitales Card type: Master Card Issuer: First Bank Transaction#: 55644 Date: 12/6/15 Time: 4:10 pm Merchant: WIU Union Card type: Master Card Issuer: First Bank Transaction ID Date Time Merchant 55643 12/05/15 4:08 pm Vitales 55644 12/06/15 4:10 pm WIU Union A database file consists of _________________ .
DATABASE ORGANIZATION Structure/schema Attributes/field names Primary key PROD# DESCR. PRICE QUANTITY IR888E Refrigerator $1,800 20 TS3233 Television $67 32 Record Record A database is organized into ______, _________ and _______. attr. values
DATABASE ORGANIZATION.. PRIMARY KEY (FYI) Also referred to as a key Every table should have one Generally short and a number Value should be unique in a table; in other words ____ ? Can be one attribute or a combination listed as left most attribute E.g. SS#, id#, vin#, isbn#
DATABASE ORGANIZATION Database – A group of related files; collection of information File/table – A group of related records Record – a grouping of related field values Attribute – property e.g. hair color Schema -- This is the logical view of the database (tables and fields) Primary key – An attribute whose values are unique within a file Secondary key – Any other attribute DBMS – software program to provide controlled data access Database Files/tables Records Attr. values
DBMS
DBMS DBMS - SW program to create, manage and provide controlled access to the data Example Access, Oracle, DB2 What can we do with a DBMS?
DBMS ACTIVITIES & FUNCTIONS Activities with DBMS Define structure/schema Data entry Modify data query data get reports
DATA DEFINITION Define structure/schema Field Name Data type Description Length Decimals Prod# Numeric Unique prod code 6 Descr Text Short prod description 25 Price Currency Product price 2 Attributes and data types (and other characteristics) are specified as part of data definition
DATA ENTRY Product #: Description: A form is used to enter data Heading PRODUCT DATA ENTRY Label Product #: Description: Field Data entry form
MODIFY DATA Modify data Add Delete Change Records/field values
Query by example (QBE) form QUERYING DATA -QBE Can use QBE or SQL to query data list products costing less than $200 prod# descr. price quantity < 200 Query by example (QBE) form list employees in finance department e_ssn ename edept e_join_dt “finance”
RETRIEVAL WITH SQL The structured query language can be used instead of QBE Each SELECT statement has three parts SELECT, FROM and WHERE SELECT is used to select output attributes FROM is used to specify the source tables WHERE is used for row selection criteria e.g. price < 400; zip = 61455 etc. SELECT <attr. list> FROM <tables> WHERE <condition1 AND/OR condition 2…>
RETRIEVAL WITH SQL.. Reservation RESULT SQL QUERY Flt# Confirm# Pname Confirm# AA1802 Smith PA5R2 PA802 LX5R2 UA3702 Mahoney ZB46A RESULT SQL QUERY Flt# Confirm# AA1802 PA5R2 PA802 LX5R2 Select Flt#, Confirm# From Reservation Where Pname = “Smith”;
ANOTHER EXAMPLE What is the result of the query? SELECT flt#, deptime, arrtime FROM ?? WHERE depcity = "PHX" and destcity = "ORD"; FLIGHTS flt # depcity destcity deptime arrtime AA 802 PHX ORD 1:51 AM 6:05AM UA 3702 COS D 7:35 AM 8:05 AM AA 812 SEA 4:55 AM 9:00 AM D 42 5:40 PM 9:15PM UA775 DFW STL 4:45 PM 5:30 PM What is the result of the query?
DISCUSSION Write SQL queries to list: 1) employee names. 2) Employees who live in Macomb. 3) employees who enjoy soccer. Emp EID eName eAddr eCity 423 Smith 100 Oak lane Macomb 425 501 Johnson 1430 N. Park street Rock Island
THE THEORY OF RETRIEVAL Dept dCode dName dMgr Fin. Finance Jon Sas Sales and service Ross Acc. Accounts Jan DEPTS. have EMPLOYEES Emp EID eName eAddr. 11893 Jon 100 Oak street 11895 Carey 15 Candy lane 11896 Ross 1317 Fox creek list EID, eName, dName
RETRIEVAL FROM MULTIPLE TABLES When data is retrieved from multiple tables, it is called a multi-table query Attr. From different tables are linked primary key in one table cross-reference key in the other table The linking is carried out in the “Where” part of a query
MULTI-TABLE SELECT STATEMENT Used to retrieve data from more than one table SELECT table1.attr1, table2.attr2 . . . . FROM table1, table2, . . . . . WHERE table1.fkey = table2.fkey AND/OR condition1 AND/OR . . . . . . . . . . . . . ; RULES When there are multiple tables, attr. names preceded by table name. “From” will have list of tables as usual. The WHERE part will have values of common attr. equated there can be more than one condition, connected by AND or OR Using the rules above, write a query to list EID, eName, dName
GETTING DATA OUT.. A report specification RH Title PH Column Headings PRODUCT LISTING Title PH Column Headings PRODUCT # DESCR. PRICE Detail Product # Descr. Price Fields PF RF Average Price Footer A report specification
GETTING DATA OUT.. PRODUCT LISTING PROD# DESCRIPTION PRICE M100 Chair $ 50.00 M150 Table $200.00 Average Price $153.00 A generated report
SUMMARY OF DBMS ACTIVITIES Activities with DBMS Define structure /schema Enter data modify data query data get reports
DBMS ARCHITECTURE D B M S Kernel Data Defn. SQL Prog. Language Interface Data Diction- ary Screen/ Report Gen. Appln. Gen. D B M S Kernel Export/Import
USEFULNESS OF DATABASES
USAGE OF DATA/INFORMATION What if a customer wants know price of a shirt in a department store? Returns? What if a manager wants to know what products were sold on a particular day? Suppose we have detailed information on each and every transaction in a store, what can we do with that?
IMPORTANCE OF DBMS’s Operational Usage: To store and record information e.g. bal, price, grades etc. To retrieve information e.g. check#432 cashed? To report information e.g. daily sales To answer queries e.g. how many shoes were sold? Strategic Usage: To analyze trends Identify sales prospects
DISCUSSION QUESTIONS A collection of information about machines and parts is called _____? A collection of records is called________ ? The smallest unit of data in a database is _________ ? What is QBE apart from expansion of abbreviation? How does QBE differ from SQL? What does data definition mean? Where would databases be used? How are databases used? Do databases deal with data or information? What is a good database application?
THAT’S ALL FOLKS!