Hmewrk: Ppulate and Extract Data frm Yur Database 1. Overview In this hmewrk, yu will: 1. Check/revise yur data mdel and/r marketing material frm last week's hmewrk- this material will later becme the cntent f yur hme page. Yur data mdel must meet all the requirements (f last hmewrk) and yur prpsed web applicatin makes sense (can prvide the functinality yu claim) using the data mdel yu designed. 2. Using MySql Wrkbench, yu will create yur 4 database tables either directly using the MySQL Wrkbench UI (yu can use the MySQL Wrkbench SQL Tutrial fr this) r by generating a SQL CREATE script frm the data mdeling tl (there s infrmatin abut hw t d this at the end f the MySQL Wrkbench Data Mdel Tutrial) 3. Ppulate all fur f yur database tables with data. 4. Generate several SQL select statements. 5. Create a wrd dcument that shws all yur wrk. 6. Submit the wrd dcument, the final data mdel (.mwb file), and a PDF f the final data mdel (which will be published t yur web site in the next hmewrk). Page 1
2. Hmewrk Requirements 1. Yur Data Mdel shall: meet the check list f the last hmewrk (e.g., data types, PKs, FKs, the nullable nn-character fields that are required, etc.). have NO SQL keywrds as table names nr field names (Ggle t see list f SQL keywrds, but can't use these fr sure: user, rle, passwrd, state, date). be able t supprt the functinality described/marketed in yur hme page cntent (yur web app cannt deliver data unless that data is stred in yur database). If yur data mdel frm last hmewrk des nt meet the requirements abve, fix it and/r mdify yur hme page cntent. Yu are free t ttally red yur idea frm hmewrk 1, but the new data mdel and hme page cntent must meet the abve requirements. 2. Yur database shall cntain the fllwing realistic lking data: a. 2-3 recrds in yur user_rle table, ne f which will be the rle: ADMIN. b. 4-6 recrds in yur web_user table. c. 4-6 recrds in yur ther table d. 10-15 recrds in yur assciative table. Nte: yu have t enter yur data in rder. Fr example, yu cannt enter web_user recrds befre entering user_rle recrds because there is a reference (freign key) frm web_user t user_rle. The same is true fr the assciative table - its data must be entered after yu enter web_user data and after yu enter data int yur "ther" table. Page 2
3. Execute a SELECT statement fr each f the fllwing (and paste screen capture int wrd dc see submissin instructins fr specifics n hw yu are t d this): a. List all f the clumns f all recrds f yur ther table, rdering the clumns in a way that yu think users wuld like t view the data (dn't use "select *"). Srt the data by the first clumn. b. Shw all the recrds frm the web_user table jined with the user_rle table. Shw the rle name first, then the rle id, then the email address, fllwed by all the rest f the clumns f yur user table (rdered in a way yu think users wuld like t view the data shw the rle id nce, nt twice.) Order the result set by rle name, then email address (as a secndary srt). Include all recrds. There shuld be as many rws in yur result set as yu have recrds in yur user table. If yu have a lt mre (and see duplicatin), yu have frgtten the WHERE clause that jins the tw tables tgether. c. Jin yur assciative table with yur ther table. Include all the clumns except PK and FK (id) clumns. Order the clumns in a way yu think users wuld like t see them (nt "select *"). Order the result set by the first tw r three clumns. There shuld be as many rws in yur result set as there are recrds in yur assciative table. d. Jin yur assciative table with yur ther table and with yur user table. Include all the clumns except PK and FK (id) clumns. Order the clumns in a way yu think users wuld like t see them. Order the result set by the first tw r three clumns. There shuld be as many rws in yur result set as there are recrds in yur assciative table. Hint: yu need tw cnditins in yur WHERE clause, ne fr each PK/FK relatinship. e. Jin yur assciative table with yur ther table and with yur user table and with yur rle table. Include all the clumns except PK and FK (id) clumns. Order the clumns in a way yu think users wuld like t see them. Order the result set by the first tw r three clumns. There shuld be as many rws in yur result set as there are recrds in yur assciative table. Hint: yu need THREE cnditins in yur WHERE clause, ne fr each PK/FK relatinship that exists between the tables yu have included in yur SELECT statement. f. Mdify yur SELECT STATEMENT frm item e, adding a cnditin t yur WHERE s that yu see nly the data frm ne web_user (WHERE clause specifying a particular web_user_id). Select a user such that yur result set has at least 2 recrds in it. g. Mdify yur SELECT STATEMENT frm item e, s that yur WHERE clause specifies a criteria frm yur web_user table, a criteria frm yur ther table, and a criteria frm yur assciative table. Smewhere in yur SELECT statement, use the LIKE keywrd and % wildcard match. Cme up with cnditins such that yur result set has at least 2 recrds in it. Example f using LIKE: SELECT * FROM tablea, tableb WHERE tableb.tablea_id = tablea.tablea_id AND tableb.name LIKE '%temple%' Page 3
3. Submissin Requirements Attach the fllwing then submit int the Canvas HW assignment: The final data mdel (which yu may have altered r fixed frm last week s hmewrk).mwb file. PDF f final data mdel (File Exprt Print t File). Yu will publish in next week s hmewrk t yur web site. A dcument that cntains the inf described belw. Include yur last name in the file name f this dcument. Use landscape and narrw margins (the screen captures fr the SQL select statements will be pretty big). 1. Yur name. 2. Heading "Web Site Title" fllwed by the title yu plan t give yur web applicatin. 3. Heading "Marketing Material" fllwed by 1-2 paragraphs that attempt t entice peple t becme registered users and/r viewers f yur web site. This will becme the basis fr the cntent area f yur hme page. In yur paragraphs, d nt explain t me what yur web site will be able t d, write text that will entice users t visit yur site. 4. Heading "Data Mdel" fllwed by a screen capture f yur data mdel (created in MySQLWB). One way t get a screen capture is t press Alt-PrtSc (cpies active windw int the clipbard), paste int MsPaint (r any ther image editr), then cpy just the part f interest int yur wrd/rtf dcument (if yu paste the whle screen, it's t hard t read). Or use snippet tl. 5. Heading "Table Designs" fllwed by (fr each f yur fur tables) a screen capture f the table design and freign key tab f the table's design (if the table has a freign key). 6. Heading "SELECT Statements" (as specified abve). Fr each select statement: Cpy/paste the descriptin f the SQL statement (frm this dc). Paste a screen capture f the SQL query windw (we need the screen capture s we can be sure that yur SQL ran prperly). The screen capture shall include: tp area: syntactically crrect SQL (n red/errr messages), middle area: all rws and all clumns f result set, bttm area (Actin Output): cnfirmatin message with number f rws returned (right click the green checkbx - clear befre running the SQL that yu are screen capturing). Page 4
4. Hmewrk Grading 1. Prfessinalism: When yu answer the questins abut yur prpsed web applicatin, especially the last questin which asks fr marketing material, we are lking fr quality that wuld be acceptable by a real cmpany that might be paying yu t create their web site. 2. Check list: We will check that yur data mdel meets all f the requirements listed in hmewrk 1 (requirements such as data type, PK, FK, null-able, unique). This is very imprtant, since yu will lse pints in many future hmewrks and the prject if yur data mdel is nt as specified. 3. Cnsistency: Yur data mdel has t be able t supprt the functinality that yu say yur web applicatin will ffer. 4. Originality f Prject and Data Mdel: As in mst hmewrk assignments, pints will be deducted if yur answer is t similar t the sample r sample(s) prvided. In this case, I gave yu a lt f prject ideas, s it s OK if yur web applicatin prpsal is similar t ne f them. Hwever, yur data mdel cannt be verly similar t the cncert/band/venue example I prvided. It als cannt be verly similar t any ther student in the class. 5. Realistic Data: Yu were asked t enter realistic data s that yur web applicatin lks gd when it begins t display data n its pages. 6. SELECT Statements: The select statements must be syntactically crrect and prduce the required results. The screen captures need t be readable and verifiable as described in the submissin sectin. 5. Suggested apprach 1. Self check yur data mdel and functinality/marketing material. 2. Find a classmate r tw and d mutual review f data mdel / functinality. 3. Create yur database tables ne f tw ways: Create tables using the MySQL Wrkbench User Interface (essentially entering in the same table design as yu did fr yur data mdel frm last week s hmewrk). Yu can learn hw t d this frm the MySQL Wrkbench SQL tutrial. Generate a SQL CREATE script frm yur data mdel frm last week. a) Instructins fr this are at the end f the MySQL WB Data Mdel Tutrial but it is: File Exprt Frward Engineer SQL CREATE script. b) Frm the generated CREATE script, remve the database schema name `mydb.` where it exists as prefix t table names. c) Make sure yur database schema is set as the default schema d) Paste the mdified CREATE script int a Query windw and run the script. Yur tables shuld be created alng with all the clumn attributes, PKs and FKs. 4. Ppulate yur database with realistic lking data. If yu find ut that yu need t mdify PKs/FKs after yu have data in yur tables, yu will prbably have t delete all r sme f the data befre yu can make the PK/FK design changes. The database management system will NOT allw yu t add a rule (cnstraint) if there is already data that vilates that rule. 5. Start wrking n the SQL select statements and getting the screen captures. Page 5