2
Overview
• Thisdocumentcovers2issues:• HowtoinstallSQLitemanagerinFirefoxbrowser:- SQLiteisthemostwidelyuseddatabase.Forexample,Firefoxusesittostoreyourbookmarks.YouaregoingtoinstallasmalltoolthatallowsyoutoexplicitlycreateandmanageadatabasewithFirefox.
• HowtoloadthesmallIMDBmoviedatabase:• IpostedasmallfilethatcontainssubsetofdatafromtheIMDBmoviewebsite("300– SmallIMDB- SQLite.sql").YouwilluploadthesedataintoyourlocalversionofSQLiteandthenissuesqueriesoverthedatabase.
4
SQLite&SQLiteManger
Background:http://www.sqlite.org/about.htmlhttp://en.wikipedia.org/wiki/SQLite
FirefoxPlug-in:https://addons.mozilla.org/en-us/firefox/addon/sqlite-manager/
5
HowtoinstallSQLiteinFirefoxDownloadandinstallSQLiteManager forFirefox
▪ ClickonAdd-ons
DownloadandconnecttosmallIMDB withSQLiteManager
▪ Downloadthefollowingfilefromourclasswebsite:"300- Small_IMDB_for_SQLite.sql"
▪ StartSQLiteMangerandfollowtheinstructionsonthefollowingpages
DownloadandinstallFirefox
▪ DownloadFirefoxfromwww.mozilla.org/firefox
▪ InnewerversionsofFirefox,youhavetopress"ALT"toseethe"menubar".
▪ RestartFirefoxwhentheinstallationisdone
Menubar:pressALT
▪ Searchfor"SQLite"inthetoprightsearchbar
▪ FindandinstallSQLiteManager StartSQLiteManager
6
InstallingolderversionofFirefox
• Firefoxversion57("Quantum")hasdisabledsomeexistingadd-ons.WethusneedtouseanolderversionofFirefox(youcanhavemultipleversionsinstalledinparallelonyourmachine;usetheolderversiononlyforclassnotforbrowsingtheweb;onlyoneversioncanbeopenatatime)
• Downloadversion"Firefox56.0.2“fromhttps://support.mozilla.org/en-US/kb/install-older-version-of-firefox
InstallolderversionaccordingtoyourOS
7
DisableUpdates
OpenBrowserandClickonoptions
• Weneedtoprevent"auto-update"duringtheinstallation• TurnofftheWiFi/Internetconnection.• OpenoldversionofFirefoxandgotoOptions.
8
• ScrolltoFirefoxUpdates
Select"Nevercheckforupdates(notrecommended)"
• CloseFirefoxandturnWifi backon.• Installtheplug-in
10
DownloadthesmallIMDBmoviedatabase
• DownloadthesmallIMDBmoviedatabase"300– SmallIMDB- SQLite.sql"fromoursharedfolder(seeresources)toyourcomputer
11
ImportingIMBDmoviedatabase(1/4)
2.Createanewdatabase.Youcancallit"Small_IMDB"
1.StartSQLitemanagerinFirefoxunderTools(press"ALT"toseethemenubar)
12
ImportingIMBDmoviedatabase(2/4)1.StarttheImportWizard
3.SelectourSmallIMDBDB
2.ChooseSQLinsteadofCSV
4.OK
14
ImportingIMBDmoviedatabase(4/4)1.TypeyourqueriesNowyoucanseethe7
newlycreatedtablesinthedatabase
2.ThenHit "Run SQL"or press "Ctrl + F12"(or "Ctrl + ;" on Win)
3.Yourqueryresultswill(hopefully)appear
15
-- Findallfilmswhichhave"Bill"inthenameselect*frommoviewherenamelike'%Bill%';
MoreInterestingIMDBqueries
• Executethefollowingtwoqueriesbelow,justcopyandpastetoavoidsyntaxerrors("--"indicatesacomment).Canyoufindalternativeinterestingqueries?
-- Findallactorsandtheirroleswhoplayedinamovie-- with"Bill"inthenameselectfname,lname,role,namefrommovie,cast,actorwheremovie.id ="cast".midand"cast".aid =actor.idandmovie.name like'%Bill%';
Thetablename"cast"requiresquotationmarksasitisaprotectednameinSQLite(butnotinSQLserver)
16
ReferentialIntegrity
PName Price Category Manufacturer
Gizmo $19.99 Gadgets GizmoWorks
Powergizmo $29.99 Gadgets GizmoWorks
SingleTouch $149.99 Photography Canon
MultiTouch $203.99 Household Hitachi
Product CompanyCName StockPrice Country
GizmoWorks 25 USA
Canon 65 Japan
Hitachi 15 Japan
Gizmo $14.99 Gadgets Hitachi
SuperTouch $249.99 Computer NewCom
...violatesKeyconstraint
...violatesForeignKeyconstraint
SimplifieddefinitionKeyconstraint:minimalsubsetofthefieldsofarelationisauniqueidentierforatuple.Foreignkey:mustmatchfieldinarelationaltablethatmatchesacandidatekeyofanothertable
19
WhatistheschemaofthissimplifiedMovieDatabase?
Actoridfirst_namelast_namegender
Movieidnameyearrank
Castaidmidrole
Theschema describesthestructureofadatabase,i.e.tables,attributes,integrityconstraints
Actor(id,first_name,last_name,gender)Cast(aid,mid,role)Movie(id,name,year,rank)
Actor.id,Movie.id=primarykeysofthecorrespondingtablesCast.aid=foreignkeytoActor.idCast.mid=foreignkeystoMovie.id
Tables Attributes
IntegrityConstraints(primarykeyscanalsobeshownbyunderlining)
20
MoredetailsonthesmallIMDBschema
ThedatainthisdatabaseisfromtheIMDBwebsite.OursmallIMDBmoviedatabaseconsistsof7tableswiththefollowingschema:
ACTOR(id,fname,lname,gender)MOVIE(id,name,year)DIRECTOR(id,fname,lname)CAST(aid,mid,role)MOVIE_DIRECTOR(did,mid)MOVIE_GENRE(mid,genre)DIRECTOR_GENRE(did,genre,prob)
ThedataweuseforthisclassisonlyasmallsubsetofthelargeIMDBmoviedatabase,thusyoumaynotbeabletofindallyourfavoritemovies.ButyouwillfindsomeQuentinTarantinomovies.Howmany?
21
SmallIMDBMovieDatabase:Schema
Actoridfnamelnamegender
Movieidnameyearrank
Directoridfnamelname
Castaidmidrole
Movie_directordidmid
Movie_genremidgenre
Director_genredidgenreprob
22
SmallIMDBMovieDatabase:ExampleTuples
id fname lname gender933 Lewis Abernathy M2547 Andrew Adamson M... ... ... ...
Actorid fname lname429 Andrew Adamson2931 Darren Aronofsky... ... ...
Director
did genre prob429 Adventure 0.75429 Music 0.25... ... ...
Director_genre
did mid11652 1092044291 17173... ...
Movie_director
id name year rank10920 Aliens 1986 8.217173 Animal House 1978 7.5... ... ... ...
Movie
aid mid role16844 10920 Lydecker36641 10920 Russ Jorden... ... ...
Castmid genre10920 Sci-Fi10920 Action... ...
Movie_genre