I'm goingtobegoingovereverythingthatyouneedtoknowaboutSequelInordertodoabout 95% ofthestuffthatyou'lleverneedtodowithSequel, it's goingtobe a longvideobecause I havequite a bittocover.
So I'm goingtostartbytalkingaboutwhatsequelisandwhyit's importantforyou.
Allthesyntax, allthelanguageandeverythingthatyou'regoingtousewhenyou'reusingsequelinyourdaytodaylifeandsequelis a lotlikeCSSandthatit's verysimpletounderstandanduseandlearn.
That's why I'veincluded a listofexercisesinthedescription I haveagainHubRepo, That'llhave a bunchofexerciseswiththeirsolutionsandtheresultssothatyoucanworkthroughthoseexercisesafterwatchingthisvideotoget a betterunderstandingofhowsequelworksandhowtouseit.
Thencomingupnextweek, I'm goingtogooverthesolutionsforallthosedifferentquestionsthat I haveintherepo.
Soletmeknowinthecommentsdownbelow, whichtopicsyoufindthemostconfusingfromthisvideosothat I couldmakesuretodedicateextratimeandvideostomakingthoseeasiertounderstandforyou.
So, withoutanyfurtherado, let's getstartedtogetstarted.
Wefirstneedtotalkaboutwhatsequelis, andit's luckilyfairlystraightforwardsequel, whichstandsforstructuredquerylanguageisessentiallyjust a languagethat's designedforcreating, reading, updatinganddeletingdatafromdatabases.
Andprettymuchanyrelationaldatabasemanagersystemwillusesequelasthebaselineforhowitaccessesitsdataforcreating, reading, updatingand a leading.
Andnow, beforewecanactuallyjumpintolearningwhysequelissoimportant, wefirstneedtotalkaboutandunderstandwhat a databaseisandkindofhowtheywork a littlebit.
Essentially, a databaseisjust a collectionofdatainseparatedoutintodifferenttables, andthesetablesareindividualmodelsofdata, soyoumayhave a usertable.
Youmayhave a product's table, youmayhaveorderstable, andallthesetableswillbelinkingtoeachotherinordertocreateconnectionsbetweenthedifferentdata.
Sothenyouhave a tablewhichcontainsdatafor a singlemodelinsideofyourrelation.
Soifyouhaveoneuserthatwillquitetoeonerecordorrowinsideofyourtable, andtwouserswillbetoseparaterecordsoraroseinthattable, andthenallofthepropertiesofthatuser, suchastheir i d nameemail, password, thoseareallgoingtobecolumnsinsideofyourdatabase.
Andessentially, it's just a tablewithcolumnsandrowsthatrepresentyourdifferentrecordsanddifferentpropertiesofthoserecordsandinthedifferentwaysthatthatdataisrelatedtoeachother, ishowitbecomes a relationaldatabasesystem, whereyoucanlinkdatafromdifferenttablestoData's andothertables.
Andthat's howyoucancreate a complexdatalayoutsystemusingdatabases.
They'refairlystraightforwardandessentiallyjusthavetothinkaboutitas a collectionofdifferenttablesthatrepresentdifferentobjectsinsideofyourdata.
I recommendcheckingoutmylastvideo, which I'lllinkupinthetopcornerandinthedescriptionblowthatwilltellyouhowtodownloadmysequelserverandmysecretworkbenchonyourcomputerinordertofollowalong.
I nowhavemysequel, WorkbenchOpenandconnectedtomylocalmysequelserver.
But I don't haveanyfilesopenformetobeabletorunsequelcommands.
Inordertodothat, I needtoclickthisiconinthetopleftcornerherethatallowedmetocreate a newsequeltabforexecutingqueries.
When I clickonthat, openup a fileformethat I canstartwriting a sequelinsideof.
Sonowlet's talk a littlebitaboutthesequelSyntax, whichisluckilyreallystraightforwardtounderstand.
So I recommendalwaysending a cynicalintotheendofyoursequelstatement, nomatterwhatyou'redoing.
Also, eventhoughthekeywordscanbewritteninallcapsalllowercaseforanyothercombinationofuppercaseorlowercase, itisalmostalwaysbestpracticeandthestandardtowriteallofyourkeywordsinfulluppercaseinordertodistinguishthemfromyourcolumnnamesandtablenames, whichwillmostlikelybeinlowercaseformatas a postuppercase.
Also, ifyouneedtowrite a stringinsidersequel, usesinglequotesandthenputthestringinsideofthosesinglecoachtodistinguishthatyouhave a stringinsteadofsomeformofkeywordorsomeformoftableorcolumnname.
Sonowthatwehaveoutoftheway, let's getstartedwithactuallycreating a databaseforustouse.
Inthisexample, I'm goingtocreate a databasefor a recordcompany, whichwillhavebands, albumsandsongsinsideofitforyoutobeabletoworkwith.
Nowthatwe'vegotthesyntaxoutoftheway, we'regoingtocreate a databasefor a recordcompany, whichisgoingtocontaintablesforbandsandalbums.
Butit's goodtoknowthatitexistsincaseyouaccidentallycreate a databasethatyoudon't actuallywant.
Inourcase, that's exactlywhatwedid.
Sonowitwascreatetheactualdatabasethatwewant, which, as I mentionedearlier, isgoingtobefor a recordcompany.
Socreatedatabase.
Putthenameofourdatabase, whichisgoingtobe a recordcompanyinhere.
Andifwerunthatandrefreshdownhere, younowseethatwehave a recordcompanydatabaseandwecanstartaddingtablestothisdatabaseandstartaddingdataintothosetablesnowinordertomakeitsothatoursequelqueriesthatwe'rerunningoverhereinourfileactuallyrunagainstthedatabasethatwejustcreated.
So, forexample, inthistablewe'rejustgoingtoaddonecalm.
She's gonnacallit a testcolumn, andthenweneedtogivethatcolumn a typebecauseourdatabaseneedstoknowwhattypeofdatait's storing.
Forexample, isitgoingtobe a string?
Isthatimager?
Isit a datefloatingpointnumber?
Weneedtotellourdatabasewhattypeofdatathatholds.
Soinourcase, whatshe's intoandagain, sincethisis a keyword, I liketokeepitalluppercaseinordertodistinguishitfrommycolumnnamesandtablenames, andwedon't needtoendanyofthiswith a semicolonbecauseallofthisthreelinesrighthereis a singlesequelcommand.
Andthisinsideofhereisnotactually a command, sowedon't wanttoenditwithSymbicort.
Otherwise, we'regoingtogetanerror.
Sonowifweputourcursorinsideofthiscommandclicktoexecuteit, andifwerefreshourschemeoverhereontheleft, you'llseethatwenowhave a littledropdownbyourtablesandwehave a testtableandinsideofthattableinourcolumnswehaveourtestcolumn, whichis a typeofimager, andthat's awesome.
Sothiswillcreate a stringcolumnwith a maxlengthof 2 55 thatisgoingtobenamedanothercolumn, andthenwe'llendthatwith a semicolonandyou'llnoticethat I'vecreated a linebreakinhere.
Nowthatwe'veremovedthattablethatwedon't actuallywantLet's workonadding a tablefor a bandthatwe'regoingtouseinsideofourrecordcompanydatabase, sincewewanttorepresentdifferentbandsforourrecordcompany.
We'regoingtohavethat I d columntouniquelyidentifyaredifferentalbums.
Soitwillsay I d makeitanenergynotknowagainsincewedon't wantthistoeverbeemptyandautoincrementlastly, sothatautomaticallytakecareofincrementinthisnumberasweaddnewalbums.
Butwecan't justput a bandcolumninsideofhere, andwecan't putallthebandinformationinsideofthealbum.
Weneedtoreferencethebandtablefrominsideofouralbumtable, andthat's wherethis I D thatwecreatedupherecomesinhandybecausenowwecansaythat I d inthealbum's tableandthatwillallowustoreferencetheband's tablefromwithinthealbum's table.
Sothisisgoingtobeanimagerbecauseit's thesameasthisideaPierreandwewanttomakesurethatit's notknowbecausewedon't everwant a albumtonothave a band, sinceeveryalbumneedstobecomposedbysomeband, andthenweneedtodefineourprimarykeyJustus.
Wedidabove, sowe'llputprimarykey.
Andthen I D saystheideaisourprimarykeyforthealbumtableaswell.
Andthentheverylastthingthatweneedtodoisthisband I.
D isreferencingthisband's table, whichisreferredtoas a foreignkey, whichisanyformofkeythatreferences a tableotherthanitself.
Whereshouldbebandsinsteadofband, which I accidentallywritten?
Andnowifwerunthiscode, you'llseethatifwecomeovertoourtablesandwerefresh, we'renowgoingtohavethisalbum's tableandinsideofthisalbumtableinsteadofourforeignkeys, you'llseethatwehave a foreignkeylinkingouralbumstoourbandtable.
Wealsohaveallthecallsthatwe'vecreatedandtheindexfor a primarykeyandband I D, whichallowsustodoquicksearchesforthesedifferentcolumnsinsideofourdatabase.
Thelastthingthat I wanttotalkaboutwiththeselectstatementbeforewemoveonisthatyoucanactuallyorderthewaytheelementsinsideofyourselectstatementarerendered.
Sowewritedescendingattheendhere, runthisAndnowthey'reinreversealphabeticalorderandbydefault, descendingissetto a sendingwhichisgivengaveusthealphabeticalorderthefirsttime.
Sowewanttoinsertintothenamecolumn, thereleaseyearcalmandtheband I D.
Sowecanlinktheideaofthealbumto a specificbandthatwrotethatalbum, andthenwewantallthedifferentvaluesthatwewanttoinsert, andwe'regoingtoinsert a bunchofdifferentelementsintoouralbumstableinthisoneatstatement.
It's notgoingtohave a releasedatebecausewedon't knowwhenthisisactuallyreleased, andwe'regoingtosaythatthiswasanalbumputoutbyAvengesevenFoldandandthatwith a semicolon.
Andnowifwerunthis, weactuallyaddedallthosedifferentalbumstoouralbumstable, andwecanselectthemjustbyusingtheselectstatementthatwetalkedaboutearliersoagainst I sleptstarfromalbums.
Andifwerunthat, yousaidwehaveallthedifferentalbumsbeingreturneddownherewiththeirreleaseyearandtheband I D thattheycorrespondwith.
Andifyoulookattestalbum, you'llseethatthisisnoforthereleaseyearbecauseitdoesn't actuallyhave a yearthatreleasedsincewedidn't actuallysupply a year, whichisexactlywhatwewant.
As I talkedaboutearlier, wecanselectjustthenamefromouralbumstablesowecansliceselectthenamefromalbums.
As I mentioned, thiswearstatementcouldbeaddedtotheendofmultipledifferentstatements, andoneofthecaseswhereit's usedallthetimeiswhenyouwanttofilterwhatyou'reselectingfromthedatabase.
Butthere's quite a fewmorereallyuniqueandreallypowerfulfeaturesthatyou'regoingtouseallthetimeinSequel.
But I wanttotalkaboutandthe 1st 1 isthejointstatement, whichallowsustojointwodifferenttablestogetherondifferentproperties.
Soinourcase, wecreatedthisband I D.
Calmsowecanjoinourband I d toearebannedtableandordereditqueriedthedifferentalbumsfor a differentbandorthedifferentbandsfordifferentalbums, anditreallyallowsustocreatepowerfulqueriesthatallowustocreaterelationsbetweenourdatainsideofourdatabase, whichiswhatmakessequelsopowerful.
Wewanttoselectthemfromourbandsandouralbums, whoput a semicolonandrunthatyou'llseethatwegetallofourbandinformationbeingreturned, aswellasalloveralbuminformationbeingreturnedforallofthebandsthathavealbumsinsideofourdatabase.
Andeventhoughithasnothingontheleftside, whichisthisalbumsection, it's stillbeingreturnedbecausewe'redoing a rightjointinsteadofdoing a leftjointoraninnerjoin.
Soforthemostpart, you'reonlygoingtouseinnerjoinsandleftjointbecauserightjointsareessentiallythesamethingisleftjoinjustflipped, whichmakesit a littlebitmoreconfusingtoreasonwithinyourmind.
Sowewanttoselecttheaverage, soweuseaveragehere a V G andinsideofherewe'regoingtoplacethecolumnnamethatwewanttoaverageoversowell, averagethereleaseyearbecausewewanttofigureoutwhattheaverage
Oheveryone, I hopeyou'rehaving a goodday.
Subtitles and vocabulary
Click the word to look it upClick the word to find further inforamtion about it