Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
CSS/416 Data Design and Retrieval Workshop 3 Database Management Systems Terminology Traditional MIS File RDBMS Table Relational Algebra Relation Record Row Tuple Field Column Attribute CSS/416 Workshop 3 2 Database management Systems Relational model Based on 1970 paper by E.F. Codd User sees all data in tables Tables can be combined using “set” operations (linked via columns) Metadata also stored in tables as above Logical design separate from physical implementations CSS/416 Workshop 3 3 Database Management Systems Functional Dependencies A -> B; A determines B (A is Determinant) Partial (PK = AB, B -> C) CustID -> Customer Name CSS/416 Workshop 3 4 Database Management Systems Keys Derived from entity identifier One or more attributes (more = composite key) Uniquely determine a row Functionally determine an entire row’s attributes CSS/416 Workshop 3 5 Database management systems Modification Anomalies (multiple themes) SID 100 Activity Skiing Fee 200 150 175 200 Swimming Squash Swimming 50 50 50 - Can’t insert fact that scuba diving cost $175 - Cant update swimming fee - Delete SID 100=>lose skiing data CSS/416 Workshop 3 6 Database Normalization Entities should have common theme Stages First Normal form Second Third Others (BCNF, 4th, 5th, DK) Impact on referential integrity Denormalize for performance (city, state, zip is classic example) CSS/416 Workshop 3 7 Database Normalization 1st normal form – eliminate multivalued attributes(repeating groups) 2nd normal – no partial key functional dependencies 3rd normal – eliminate transitive dependencies CSS/416 Workshop 3 8 Database Normal Forms Violates first normal – why? Plant Name Eqpt Name Plant Mgr Eqpt Mfgr ethylene Final cooler, feed heater Jim Smith ABC Exchanger 1247 Locust styrene Feed pump Bill Gunn XYZ Pumps 432 Broadway styrene Feed pump Bill Gunn ABC Exchanger 1247 Locust CSS/416 Workshop 3 Mfgr Addr 9 Database Normalization 1st Normal satisfied Still violates 2nd normal– why? Plant Name Eqpt Name Plant Mgr Eqpt Mfgr ethylene Final cooler Jim Smith ABC Exchanger 1247 Locust ethylene Feed heater Jim Smith ABC Exchanger 1247 Locust styrene Feed pump Bill Gunn XYZ Pumps 432 Broadway styrene Feed heater Bill Gunn ABC Exchanger 1247 Locust CSS/416 Workshop 3 Mfgr Addr 10 Database Normalization PlantN ame Plant Mgr PlantN ame Eqpt name Eqpt Mfgr Mfgr Addr ethylene Jim Smith ethylene Final cooler ABC Exchanger 1247 Locust styrene Bill Gunn ethylene Feed heater ABC Exchanger 1247 Locust styrene Feed pump XYZ Pumps 432 Broadway styrene Feed heater 1247 Locust 2nd OK but 3rd? ABC Exchanger CSS/416 Workshop 3 11 Database Normalization PlantN ame Plant Mgr Ethylene Jim Smith styrene Bill Gunn Eqpt Mfgr Mfgr Addr ABC Exchanger 1247 Locust XYZ Pumps 432 Broadway PlantN ame Eqpt name Eqpt Mfgr ethylene Final cooler ABC Exchanger ethylene Feed heater ABC Exchanger styrene Feed pump XYZ Pumps styrene Feed heater ABC Exchanger Satisfies 3rd normal form CSS/416 Workshop 3 12 Database Normalization BCNF – Every determinant is a candidate key Fourth – Multi-valued dependencies Fifth – Can recombine relations CSS/416 Workshop 3 13 Database Normalization Domain Key (DK/NF) Provably free from anomalies But no one way to generate this form All constraints follow from domain definitions and keys CSS/416 Workshop 3 14 Database Normalization Domain Key (DK/NF) “The key, the whole key, and nothing but the key” CSS/416 Workshop 3 15 Database Design Translating a model to the Database Entities -> tables Establish primary & foreign keys Many-to-many relations ->Junction table Business rules -> triggers, constraints, etc. Surrogate keys Security Typically done with a “CASE” tool CSS/416 Workshop 3 16 Database Design One-to-one Auto # Employee 1 Has 1 Auto Emp # CSS/416 Workshop 3 17 Database Design One-to-many Mfgr 1 Makes N Equipment Mfgr # CSS/416 Workshop 3 18 Database Design One-to-many (w/ ID Dependency PK = inv#, item# Invoice 1 Has N Line Item Inv # CSS/416 Workshop 3 19 Database Design Many-to-many Mfg # Eqpt ID Mfgr_Eqpt Equipment Mfgr M N CSS/416 Workshop 3 20 Database Design Recursive Member 1 1 Referred by Member # CSS/416 Workshop 3 21 Database Design IS-A relationship (Subscriptions) Member Member# Print CSS/416 Workshop 3 Online 22 Database Design Learning teams to implement sample relations for above E-R relationships: 1 to 1 1 to many Many to many 1 to many w/ ID Dependency Recursive IS-A CSS/416 Workshop 3 23 SQL Two main language components Data definition language (DDL) Data manipulation language (DML) CSS/416 Workshop 3 24 SQL Data definition language (DDL) Create, alter, drop, etc. Frequently implemented via various CASE tools: Visio, Embarcadero, ERWin, etc. But – also very useful for database administration CSS/416 Workshop 3 25 SQL Create Statement Create table patient (name varchar2(35) not null, age smallint, gender varchar2(1), account_number integer not null, primary key account_number) <..additional constraints such as foreign keys, etc. ..> CSS/416 Workshop 3 26 SQL Select (Projection) Select plantname from equipment Select (Restriction) Select * from equipment where eqpt_name = ‘feed heater’ CSS/416 Workshop 3 27 SQL Select (Selection + projection) Select eqpt_name from equipment where plantname = “styrene” Sorting (Ordering) Select * from manufacturers order by eqpt_mfgr CSS/416 Workshop 3 28 SQL There are many built in functions Some are called aggregate functions Count Max Avg Etc. Example Select max(age) from dependents CSS/416 Workshop 3 29 SQL Joins (old syntax) Select m.mfgr_addr from manufacturers m, equipment e where m.eqpt_mfgr = e.eqpt_mfgr and e.plantname = ‘styrene’ CSS/416 Workshop 3 30 SQL Joins (new syntax) Select m.mfgr_addr from manufacturers m inner join equipment e On e.name = m.name where e.plantname = ‘styrene’ CSS/416 Workshop 3 31 SQL Subqueries Select m.mfg_addr from manufacturers m where eqpt_mfgr in (select e.eqpt_name from equipment e) CSS/416 Workshop 3 32 SQL Insert Insert into equipment values(‘propylene’, ‘feed heater’, ‘ABC Exchanger’) Update Update manufacturers Set address = ‘18 Front Road’ Where mfgr_name = ‘ABC Exchanger’ CSS/416 Workshop 3 33 SQL Delete Delete from equipment Where plant_name = ‘styrene’ And eqpt_name = ‘feed cooler’ How many rows could this delete? CSS/416 Workshop 3 34 SQL Exercise Create the tables in the design exercise Create a few sample SQL selects, etc. CSS/416 Workshop 3 35 Functions of a Database Application Page 238 Figure 10-1 © 2000 Prentice Hall CRUD “the first function of a database application is to CRUD views” Create Read Update Delete Page 237 CSS/416 Workshop 3 37 Format or Materialize views “the second function of a database application; the appearance of the content” Page 238 CSS/416 Workshop 3 38 Other database functions Enforce constraints Provide for security and control Execute business logic Page 238 CSS/416 Workshop 3 39 E-R Diagram Page 240 Figure 10-3b © 2000 Prentice Hall Relational Design Page 240 Figure 10-3c © 2000 Prentice Hall Relational Design (w/ Surrogate Keys) Page 240 Figure 10-3d © 2000 Prentice Hall Relational Diagram Page 241 Figure 10-3e © 2000 Prentice Hall View “A structured list of data items (attributes) from the entities or semantic objects defined in the data model” A view can be materialized or formatted as a form or report Page 242 CSS/416 Workshop 3 44 Recordset “the result of an SQL statement” Page 243 CSS/416 Workshop 3 45 CRUD actions on a view Read SELECT CUSTOMER.CustomerID, CUSTOMER.Name FROM CUSTOMER, WORK WHERE CUSTOMER.CustomerID = WORK.CustomerID Page 243 CSS/416 Workshop 3 46 CRUD actions on a view Create INSERT INTO CUSTOMER (CUSTOMER.Name, CUSTOMER.City) VALUES (NewCust.CUSTOMER.Name, NewCust.CUSTOMER.City) Page 244 CSS/416 Workshop 3 47 CRUD actions on a view Update INSERT INTO CUSTOMER (CUSTOMER.Name, CUSTOMER.City) VALUES (NewCust.CUSTOMER.Name, NewCust.CUSTOMER.City) Page 246 CSS/416 Workshop 3 48 CRUD actions on a view Delete Cascading deletions depends on relationship cardinality Page 247 Figure 10-6 © 2000 Prentice Hall Form “a screen display used for data entry and edit” Forms should... reflect the view structure make data associations graphically clear encourage appropriate action Page 248 CSS/416 Workshop 3 50 Forms in a GUI Environment Drop-down list Option buttons in groups Check boxes Page 251 CSS/416 Workshop 3 51 GUI controls Page 252 Figure 10-10 © 2000 Prentice Hall Report Design Reports should... reflect the structure of the underlying view handle implied objects Page 253 CSS/416 Workshop 3 53 Enforcing Constraints Domain Uniqueness Relationship Cardinality 1.1 and 1.N fragments orphans Business Rule triggers Page 256 CSS/416 Workshop 3 54 Security Horizontal Vertical Page 264 CSS/416 Workshop 3 55 Control System of menus Transaction boundaries(Atomic unit of work) Page 265 CSS/416 Workshop 3 56