Final Project Preliminary Designs Pretty good designs. Remember that design is an iterative process. Don’t get married to your design. OK to change. You will implement this model in Access. If it doesn’t work you won’t be able to populate the database or query it. If you had red ink on your design come see me again with the final design before you implement it.
Common problems/issues Many-to-many relationship between presenter and proposal – not limited to just one co-presenter. Review question scores – only question number and the score for each review is recorded. Questions are not kept in this database. These are for individual and consensus reviews. Proposal and consensus review have one-to-one relationship. Be careful with primary keys. Do you have enough attributes to uniquely identify each instance? Year as discriminator for speaker and reviewer. A person can be a speaker/reviewer in multiple years. Review Captains – recursive or two relationships between group and reviewers?
Think about order of real world events and affects on db How should we connect consensus review, individual review, review group with proposal? The order these things happen is reviewers and review groups and proposals are first. Next is assignment of proposals to review groups. Then individual reviews happen. Then consensus reviews are conducted. And finally final status of proposal is determined. If we connect review group to consensus review then how can we assign proposals to review groups before consensus reviews occur? It may seem conceptually right to connect group to consensus review, but as long as the groupid is in proposal we can do joins to get info out?
SQL Functions (again) What happens with NULLS with Ave, Count, etc? NZ function allows values to be used where NULLS are NZ (expression, ValueIfNull) SELECT NZ(dateDue,"no due date") FROM Rental; Sort by aggregate function? either use function again or use ordinal position in output table
Views Virtual Tables – contents defined by queries Called Saved Queries in Access Used just like tables Purpose: Security – limiting access to data Query development – modularity
View Advantages Security – restrict user access to only subset of data. Specific to each user (group). Modularity – they allow programmers to create modular queries. Simplicity – users can create their own views to simplify complex tables Consistency – if underlying tables change, views can remain the same
View Disadvantages Performance – they appear to be tables but need to be created on-the-fly each time the view is referenced in a query. No indexing on views. Update Restrictions – simple views may allow updates, but complex views usually are only read-only
Video videoIddateAcquiredmovieIdstoreId 1011/25/ /5/ /31/ /5/ /5/ /25/ /12/ /29/ /25/ /10/ movieIdtitlegenrelengthrating 101The Thirty-Nine Stepsmystery101R 123Annie Hallromantic comedy110R 145Lady and the Trampanimated comedy93PG 189Animal Housecomedy87PG Elizabethcostume drama123PG Stagecoachwestern130R 987Duck Soupcomedy99PG-13 Movie Rental accountIdvideoIddateRenteddateDuecost /3/20021/4/2002$ /24/20025/2/2002$ /24/20024/30/2002$ /22/20022/25/2002$ /22/20022/25/2002$ /1/200112/31/2001$ /14/20022/16/2002$ /24/ /1/20021/8/2002$ /1/20021/4/2002$3.49
Create View Let’s find all rented comedy videos using a view. CREATE VIEW comedyvideos AS SELECT * FROM Movie m INNER JOIN Video v ON m.movieId=v.movieId WHERE m.genre like ‘*comedy*'; m.movieIdtitlegenrelengthratingvideoIddateAcquiredv.movieIdstoreId 123Annie Hallromantic comedy110R1112/5/ Annie Hallromantic comedy110R11212/31/ Annie Hallromantic comedy110R1134/5/ Annie Hallromantic comedy110R1233/25/ Lady and the Trampanimated comedy93PG1455/12/ Animal Housecomedy87PG /5/ Animal Housecomedy87PG /29/ Duck Soupcomedy99PG /10/
Use that in another query SELECT c.videoId FROM comedyvideos c INNER JOIN Rental r ON c.videoId=r.videoId; videoId
Inline View You can also put a “view” in the FROM part of the SQL statement. That is, a SELECT that SELECTS from a view. SELECT c.videoId FROM [SELECT * FROM Movie m INNER JOIN Video v ON m.movieId=v.movieId WHERE m.genre like '*comedy*']. AS c INNER JOIN Rental r ON c.videoId=r.videoId;