MySQL Study Material, Study notes of Database Programming

Getting started with SQL and databases

Typology: Study notes

2023/2024

Available from 08/21/2024

shubham-sawant-3
shubham-sawant-3 🇮🇳

2 documents

1 / 34

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22

Partial preview of the text

Download MySQL Study Material and more Study notes Database Programming in PDF only on Docsity!

g. WO Is Dish) 7 Can We TenamMe cehtyayyr ee? See haus hy Gee rer ene Ce SELECT = Used to retrieve the data Statements Clauses : : i) WHERE ~ Condon __ dN} SELECT UNIQUE Ccolumn) i) GRoup BY- for Grouping ¥ CELECT DISTINCT (column) Using aggregare | - Retrieve only unique elements \Q)MAVING — Tt Selecrs apnong I} from column the groups formed + — oF 1 by GROUP BY 6ouee | eraue ped SD qnoee By - order the column “S| Sevecr’ cabntlcoumn nama — i SELECr Gunt COISTINGT calimnpame) SELECT Count Cx) —_Ret7ive numbpes ck Yams canbe used with GRovUPRY or I] ipeeee clause - | 3\| SELECT Top Gumped EROoM table L || = Repiove top given number ok Ceruts. ; Ay) sececr First Column), LACT (column?) | RANBaM-Ceshimna) = Gerrvove first last , and —randem eny valle : SY serect toe 1 (cotumn) . EROM tabie : ORDER BY NEW TDC) - - Remeve the Yandom yow in SSL setver SN nteax - oer tO obhera SMStOS, . 6)|| secectr column ASG ‘column name = Column Hanne cNanges £sam Calum pn fo Column name. - and raluma is calerted , ORE AAS BM eee ) Qs what ace guertet i vol neke QO. onok 1S wd Hou) As ye eT Sta clauses SravHing upite Iie! jeriex, 2E = _Guves condition “for tore 1e000a Ming cy = ctakemenis hence —_Naorousiang— “eetmmnaal tay ; _Queny— neice — Pliecing. ——— i — “3 Synrar - oe SELEcY COMM) NGIINS 5 —= == FROM —— J WHERE (CcandiHan) | Ty Canditien we use operarote like ~y WW] lagical 2 AND . GR - for Many Condens : 2) Compayaty DS <)>, <2 )S=, =, <> for not egug) ae S)| LIKE aeevaroy 3 %4s A%e, —4 , A=) O02, arte i SS a 09. WHERE column Like '%Q—' | Tt gives results twith ‘oO! terter ar second last posi, : in Value | %\| To find nuit we use WHERE Columnl “15 NOTNULL WHERE column: WHERE Columol 1S Nutu x _ WA _. 4) BETWEEN > to fod numbers in ner) range 7 WHERE Column name RETWEEN 10 AND 20 - WHERE Goiumnmame lor BETWEEN lo AND 20 __ & Wwe Can Use BRETWIEEN OPera for hoy Cntreqet, TEXLs DATE TIME ag well. Ee ad HIN operator 2 mMuttiole Values in where Clauye ——— Twice wmnnams IN (Value, Varwer. values) — PE —_tolumname Nor TN (vawwet valuen ve ao BINA Wo OS SY CRS LC Houjtouse Q whe is ohne C\ OLAS <" Pent aa le ———— CG whak is Using a res S po Bette oe —| Dag Sd i to |] snnicacan ve ascending ty deCaul+ Ts | mentioned! to cattemins gpeciti ed. Su nto SELECT -& ERoM table QRDER BN (column) ASG o® DEsc 3 <— *S¢/DEse conve — het {ll Se LECT FROM table ORDER BY (Colump) ASC LEMIT num + Limit the Number of reguirs toNum’ OFFSET Num — skie first'num2 vesutts 3 SELECT EROM table ORDER BY Column! Asc , Column? DESC; First condivion is excused fiyst diven mast Brion ry tnen gecand column/ second eonciitoy ~ d HAVING CLAUSE ~ This clause sed in ascactarien —unith g¥eup by douse gQoplicd ro each gralap «+ Wesu Lire aaa Bimilay te there laude fueh dice — || 4s 44s sed width Qa yp by one — SELECT column hence _ssseah_ Fors an play yng —_FRoM tape U condihe uth Groue be —} GRobv Co Clause —H HAVING Condi Han 2 BO O, tow te @ 201 TECaye of vo doA£ je C Camiin| Page ZNSERT Statement Date — | INSERT — isd to insert new data into table. | INSERT INTO ‘taple name class’ | UCENSERT INTO SELECT Staremegr Crd, name, Mmayiss) | SELECT Td, name, marks _ CFRom table name clase WHERE (condition) ; INSERT INTO Sintement Without coer fying Colurmms. SEre CH INSERT INTO “*dblename class VALUES Cvaluel, Value 2, Voile) —L i) with soecihying Columns ta Al) Sh INSERT INTO table name Class (column! « column2, columns) VALUES (vale! . Valuee, Youre?) - «| Toxe caxe of Sequence anal WARS hay Oo} Values pastel Tt Gnd thely column matches - 44 Wo can use musiole I cert into’ = value statemeads ——j| ar a. Hme.- kT we can incest default values also as 2 | INSERT Dwyo teble name | __ DEFAULT VALVES Oe —~q SF Put nie voles, oo e UPDATE Starement AT PF ueDATE = Used to madify data, that adneathy eneists: _ |L_ 40 verieve tre data to modify we use WHERE _ | CADIS - a: — - TTP Suntan ~ I UPDATE +abie name. _ || SET Column name = expression — || WHERE (Ccandition) jf eq. | UPDATE _tanle name Class iq_|_name |Last nam | Ser Name =‘Shubham' 17133, [Shubhar| Sawant | ineaess = ‘Samant! ___ || WHERE id = 17123 3 —_ i} ___*| we can ser value tO null by sebding ' NULL —f —H a BQ wwii AS FWe ALLE eeryt oF 1 S9C? 7) comin Jon, comin ess fee = —— et ——— LF _ _ two_tabjes. “Joined. 6G bean Bue J] euses snore not marin C\ther left «% right sided Values Shawn. = TI ~_REINNIR TOIN - tuo tables combined where Key e€lornet of fey chum ns Matchen. 4 | People, Staten i name. . abbr | fue 4 Marcus | CA CA cali fornia —H Tennifer | VA DE | Delaware | devin | MA VA Vivainic, Byh- cA i} Toner jon J ems [nm aby fu | SEI ECT ke “ePonarcusl ca | ca [calle |] FRaM Peaple Joniffo| va va [viene | TON sinres Orit | ew [oa [cory ON People Stare = Crares:aby)~ : an WN SLE VUES — Mokehes Outer join LECT Foiln nome _| stare | abby SELET * C00 YOu CA CA |cadiky FROM People Tennite| vA | YA [Vigna LEFT Join SGrares Renin mA nu | NU ON People Stare = Stares: abby; Baty cA CA [ealw | RIGAT Join =] gratel _dbby| fall sete mar | ca_| CA [eal FROM Peaple Se ster | WA VR | Vind RIGHT TAN OO A OA CH \edbe LON © Paaple - State = Stakes -Obb7, | A | nw | DE [Oeh {. Crusinoad 1S COAT AY 0" oaktsu * Jobe Camiin| Page a. ~ COLDS yo") camin |r “FULL OUTER OPN ———o— : SELECT X& — — Peom table FULL OUTER . JOIN. able 2. _— an tablet colt = tablet colt _ CROSS JTO\N = when each rays ob ftySt FAb\e Comal with each oul at Secand table tis a Cowles tol CXOSS. Tain. 89 i¢ two EARS « ISK 20 Gtiumn C585 Jo SyproK Produc Coll be 1SX70% BooTHUss . SELECT & ERomM table | Geass Torn table 2 tonle) tape & COF RUE ia_| name ic} Surname : ; eS. | sevrns { Subhnom ' | Sawant Shwohaurm Sous Q Rohit, | Shinde 1 Shussham Shiv: Baru SAG Sy Qus\ 3 t Sha) TE Mowitiply altho yoruss . Chose Prodlip i | a, | | Camlin Page Ay Date ! —~ | 4 4 UPPER , LOWER q _— uf oS SELEcr tower (name) [iS seLecr UPPER (name) i y ; ~hatne ) {it FROM city FROM city _ ORDER Ry hame ; ORDER RY Name | — ot fname fe — name _ mI pune PUNE ee - ++ f Satara SATARA —_ - S| geerace —_ ; SELECT REPLAC tah —_ | LACE Cnam), to! 1 Case. sensit ie FROM city . . id Name, a ut 2 we i bet x { tt p | | : [Camiin] Pag Nuentbets . — i ~ Data. Types ave Syghem dependent. different tm. Se Sysienn » ' TIntegeh Rea) (lock Qyl Co4 2) KIO = VO+20 => False Sacrificing gamuracy fs scale, So value aire Lange bub not precise in. Tea) Numbess + FuncHwons ee TYOF oF SELECT > Mreges TYPE GF C14); SELECT TYPEGF Citic) > Rea Wl SeLEct tYeFae (Panda) D> text Wil se Lect TYPPOF C Pande + toala’) > inieged, _ 20) f Tt Zives Texte as resute Te e@ycton, [ony SYS+ery—SuppotCeptertarwaio+ 25] oof LED AE, Ai visio SELECT 1/2» 1O/2 5 Select I7/5 APNG 5 SPLECT, Q2>2 4. 365 5 Dates and mes | format —____. HI ‘7 ROIS - O28-O8% 52014 a <= most tess > sia Significant signi Fi ant A iL ure ~ _wniversal time comrdinage, ta avoid tan Pricse —_ tise Standerd tlme | funcedans ly getece DATETIME ¢ tno!) = See 7 SeLecr DATE (Now!) = | Bse LECT TAME Cnaw")* = ‘427 minutes, +1 clay’ AS SELECT DATETIME C'rnoia’, "#3 hours’, "42 Yoars'")4 costume. Funcrton for corgi len chee Te VPRO TCO ON Note the plural and singwo%s aby | SocBuE. |) DATETIME Crow’) 2) DATE CNow) |2) TIMEChow!? _ it LolY~ to-29 W232 Dol. 10-29 Qyr Qh Br —t —— 14) pereTime (now','44 hours’, 427 minuter’, "-\dey sy!) —H ZOPDL 10-24 wa! So 'n6 Ho | _ oe oe o-, | Qs LONE ye Ae kM Cloluy ve. ( Ovcusnat ee SOMC AAaqaegale tunuto vigamiin|Pace Aggregates ~ — 7 =| | Clouse = GRonP BY - Tt is Used why celeot cratenast. ee oe — __|| “4e —atoup the —resuirs ah Quemy Mictehes the values _j] tq —toltarnan S_duad roe Bneyag A Laredo. _ SELECT cahumn naNe. Cs» _4 FROM table Name. i GROUP BY column name i | Funceans | iL COUNT feoonr ex) © a ee COUNT OF MTG. OF TOW | SELECT Count CX) {io | 10 ‘Danylatton! Calumne 4 FRom county : ” r ; Moor POWs Ul 6ELECT Count CPopwiation) Ser eD 3 TOT Dopulehe. | FROM Coun ny | ealuupay | 2) 11 NIN, MAX, SUM, AVG: | SELECT region , MIN CPonutation), OMNIA OF PopulaHon _t MAX CPapwlaton), Moa of POPUiahe’n — SUM CPopuiatinn), Smt ah No’ & 4 AVG ( Pop Wakion) Aversye Oh value’ - Po 50K —li FRoM Covnsry ms —IGRouP BY regions, grouping Psfuakon to ae HOP ARs. _—— — —_Feasan [ mirwfeoputanod | miaxc Poowton)| SUMACPopit _ANGG He AeACO ~ “C60 2556S | raxoxore 1a Hl Amenica. T° tox —— pin TOO (SSO £000 | 1500 concepts 6 Whar fs SQL ——— oS ef alec ete Sarat ove une S ch SQL stole — COL= Structuved Query language tras Lors We Communicate 4 ——J as —F “pit dara base. +0 Srore manipulate rerrieve dara hy | tess you noo diy Serucrve. af chayaloa se. |__— Hasapase - cansidered as cantainek at tables _ - tapie - Grids With fous and columps thotholds — dara. —_ fBueny- single starement in cQt, seu is Cuselnse — ve buy by -Canventions we use aspi tal lettres 5 fay Qucry. ISGL commands] —- DDL DML... DEL, Titec Dara delinaken Daya Monipuky [DAFA Can wel}. Trancacre language language Hang Uage Con yo} [__tanguoge commands like Commands Vike — |earamands commands ike | tke =. Creating , deleting create manipula Cree { Cater —f nedy fying he tne actual data Rewoke. oo ——_| databases ,scherr 1 j | —| toler, row? —| Columns be, - = —_—————— ——H) CRE RTE NCRUD Commands GRANT | NOM MAT | NALTER ‘N WHERE clause] i REvoke SAVERS] _ fQRENAME 7 : WON BR “ WDROP ee - \SET TRANS comme ny -—~)PyrRoncate a ee TT : | | Ase consere aise ee Sinead Vane asfever’ Com! sways 2 ex ofall: ~ Dephak aie tne HIPs oh keys 2 EXO Canstrainrs — _Cansrraimts limits tne Hype ot dais be Passed — wore dardbase they Cap be 9 ay to columns ar whale tape. thoy fea feliabilihd rot Dosa — n—enerenereninomenirenenemenere ere awe “Common constraint ? i} vy UNIQUE = __No duplicate tn givey column = i} 2) -NOT NOLL = NS NUL valine 7 2) DEFUALT - Te value not Passed cbetany ty: 4) CHECK ~ _EnsSuyes Nae’ in columen: Sarishy giv 5) ENDEX ~_ Rervive dara fram dakarboge quiday Q) PRIMERY KEY - combinaxtorn eat not NOLL & Wig [| D SECONDARY KEY - Uniquery identity Tous Teser | fram anohex, tate. }| Keys — Callumns Used to Cre ake Yeladonsh) ps wo} Phin tb —___|]_ anc) maintain uniqueness and verre data -factep . } Priory key - Not pu and triqne values cy Column Mm | Suitable: ta selerk ag primary bey wth : ne Can _Q\in the Aables @4: Ia, Passport UNniaue key Similar to PTUMALN on tup ALLows ene nut 19 Column — AltOmnore ke — Candidate key not selented as paso} Super key - Set a two o%& Move Columns that tani ide ni fy tine Yous 4. cambinalian St LC Pes keys | Primary (seu) hatha bet [Foreign key = Ty _ Reafron ship ul tin surg tables at L Slane _jarie— canbe Guother table . Ht can accent. teas wall Nu votre aktowed ‘ Cond idade. bef - Ady boy Sujtdble 4erc BIO gy St ken 49 Candidate OW. >. 4 ‘ fe