0% found this document useful (0 votes)
31 views23 pages

DBMS Journal

Uploaded by

jobajo5825
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
31 views23 pages

DBMS Journal

Uploaded by

jobajo5825
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 23
02) Execute a single ine gery ord group gnc Mysqts creak datatoare company Guy oF > WOW afk Hy 419 Use “dompony ; com) Database Chor My sqis create table employers C employee. tJ INT PRIMARY KEL, depart ment VARCHAR ( salory DECIMAL (10,2) Guery oF Fineness ted HYysql> INSERT INTO eeployees VALVES. (2 'HR", s0000.00), C2, "IT", 60.000.00), Ca, "HR', ss000.00, (4, IF *, 620000), Cs 'Grnenc' , 20000 00) 5 Guery OF SF rm Affected Hysql > Select ¥ frac Company 5 depanierent pe SS.000.00 6200000 Froace | %0000.00 Stagle-\ine quesy with grouping functions average salory fer each department's NUS! >SELECT department, AUG (salary) ASavg-Salary Froo employees GROUP GY daporterest depart mend | ongesalany | AR $200-000000 a 61001, 900000 ea reneeo 2 rows see (0. v0sec) B) Find the ‘lol Numbu g’ tnglo.ges sm cach cepe ont Hygil> SEL por ment, COURT (employee—iel) Ac Num employers FROM employees GROUP BY cepa ments ; [deportes aumaemployees HR | 7 i ey E Fieance a z a ea (0 005e Mysil> stlect cigastenns , rt Csalayy) As rox salary torn employes grap by dopasteunt; [deportnent | Max salary | He 55000, 00 a7 6200000 Fingace 30000 00 2M 1 Set 0.0 sey) tela salon expetitoe fp cath ciporienet Hysy|>SELET department, eenployees | sae at | 1222.00. 00 ps0do.00 A100 00. 00 iE Finonce aa ae Bwws ig set (0.00 sec) SUM Csalory } Group BY depaytenut ; 4s totol_salory From ® Execute DDL Commonds Mysql > create database college 5 query ok 2 mw agiected Co.rsec) Mysql > Use college; datbase chacged Mysq!> Create fable students Shidentid tet primory key, Hrel_oame VARCHAR (50), last nome VARCHAR C50), age Int grade CHARC) PD Gury Ob 6 0 apbekd Cocos) ~- Fabel created My Sq1> desc students 5 | Field [type a Key | Oefaull | exh | Shdentid | int No”) PRT Woe rst qom| vagcmeiss) Mes | NuLL | Last_ nome ee Yes. | NLL a Mes s| ~ oe | chor Ct) | 4es | mee | [= peat lee ay smws in cel oo aus columa ‘adress fo the 's TABLE students addwess VARCHAR (25s) 0 warings:o MYSq) > desc students ee TyPe ex va Student _ id ia t tome | Norco. N | uc hw | last nome | yi oa a Xe NUL grade a ‘ with addvess varchan(ass) | YE NOL ‘6 to set (0.0 xc) MYSq)>—- byModiqy He see Q the ‘addres ' columa to accommodate lorger values BOUS ALTER: TABLE etoacat MODIFY addvess, NoYcho » Csp0); SYR) OF 0 oes onecies te 63 sec) Recorcls: © Duplicates © woramgs:9 ae Mysql > desc Students; [Bers | type [No 4 [eget | Cave gd [ms wo | per | nun | | tet nome | Narcho + (50) MES NuLt | Hast nome | WerchanGa) | ses nul | age | ing YES mu | Ockire ss Varchortse) | Yes nu | Gyo wy se (oosec) © Draping ab — Drop tre “grade' colum ftom du’ chiden’ table colueny Mysq!> ALTER TAGLE shideats DROP COLUMAL cynde Gury ol , 9 wus attecte Co4 sec} Reorde: D Dupliates : © wonings :0 MYSG > dese stidents; | i | Fed Type }uet key | depot Texna | student, int NO. PRI nu | ee = ome vorchayin) | YES Nu Mi ie. 5| ne i oO _ ites ae wu Vorchor (509}) Ye ia 5 Yow m set © Owpprg tre ene table Mysjl>DROR TABLE students; | Query Ok 2 WwW affeectd (0.03) Musql> desc shdent 5 “EReoR ¢ Table college. Shudeat’ decent exist Ereuk DML cOmmores Mysqt> create database library Query oF 2 Ww apgected Mysqi> ue library ; datbbax Chonged Mgsql> create table books C book-1d md prmovy key RHE VARCHAR C00), usher VARCHAR (190), Publi cali. Yea ENT, price DECIMAL 00,2), 34 Guery OF 6 wo Ahhecked (0.00 sev) Husqi> Inseo} mt book values ("The Greast Gatsty 1, "F. scott THagerald’, tas, va) (2,’TviN a Hockingbrid "Harper Lee’, 1460 15-20), ©, 1984", * George Onvell’ La4a.a.gay, ChE CREED Mt pie 113 989) G4 se The Cadchey m tie Rye, h.9 Salinger ', 19151 Jit); Query Ok © OW Obbece ted. (0.0.2 se Lel's exeude some Common D Ht J select statement to yetvieve data Mysql > select ¥ From books 5 author Jboxial He poe Be | 2 | Te Grek easby Fst Bizgeald 2 |. killa Mock trgtshed | Nayper Lee | lacy, Jane fusten 4 hae ond Pee judice erm theRye! 9 5 vow mo cet (o.0sec) 2 veppte Mysq!> UPDATE books Set Price = 12.94 WHERE He = 1994"; Guery Rows Ok © RWS Affected torched + 1 Chonged Mysq!> selec © trom wooky Prox ge owed [publicattonyeay | Price Laos jae ago | 180 tua | aaa 1313 aed ae — Statement > modify dota. ig Warnms +9 covnmennds Mysq) > [ Austicotio yen] tres book _ id] Hite author Auaicato-yeor| rice] ei ibiia Grea. Anes | d.scot aguas tars |izaa| ees | | \a60 | sco Hare sh iti tagind | Harper Lee 4 Bel 3 \aau George dowel! ws4a— fie | | 4 (ale ond Prejudice © Austen Wwia W]e fire catciny mis S wis m sei (000<¢r) @ Iasest statement to add ~= lnsentamend book yeand Mysql > taser? mts Valwebooks (bool id Bile, ousther , pobliakees —4eoy, price) values C 6,’ The Hobbit, “T.R.R Tolleien” 1939, 4.209); GUY OF 4 VOW afteted Mysql> select* trom books 5 1 book id] Ate autho wr | ALp\icatis.pow] Pree | | 4 The Greate (atslay | t Sautt Ftogevald Was 1299 | 2 To bill Mock rghrvid Hovper Lee. ta6o0 heen | 3 aay Yeorge onwett ay \ 4 Pride ond Prejudice Tomer an a S| The catcher MMe 55 ect ec | {cual 6 | The Hobbit | | lo | T.RR Toiken | Qa ag Ow Set (0.03 set al Hvtertag dota » IAs dh ¥ frac tooke where publication_yeay bookid | HHte autver __| Pobli cabier.if To Fill aMeckmgbrd | vovper tee) 1960 | | ii || | = | Tre atcha m the mye | 3Dsattoger | fast [tia | ic 7 2 You m set Co.aset) @ VPOATE staterrart with where clause = updo Hu cuties q' the catches mm tre Rye” My cql> update books sel author =‘ Jeroms Dovid Salinger * ushere Hie = 2 Cotche Aru eye’; Query ok 1 vow orcad (0.01 sec) Rows motched: 1 chonged | 3 wsovningsio Mysql > stleet * trom Great Cakby fF scot Fiizqesald a eae 099 2 To bill ottace reg bre |Horpen Lee, 160 158 2 (934 George orwoll tang Ray 4 | Pride ard Prejudice Fane flusten 1s es SJ The catcher mtnityd Tene Dovid Salonger tas It ‘all 6 The ae TER Tolkien ta39 1499 SOS ae is 6 rw m | Sth Co. ot sec) @ VCLETE Staten) to remove dota Delete Mysql > deiete trom books where Hie ‘Pride ond Prejudice tre yeoord gr “Pride onl Prejudice! Guery oF 1 vow affected (0.01 sec) Mysql> stiect ¥ from books; bot id) ttle —=s«|sauthoy —_——Publigatsayeay| Price a The eyeate Gatsby | F. scott Fitagerlad 2s 2.99 a Th killa Hocking bid) Harper Lee 1960 s-sD 1aa4 @eorge orwell 1949 129 Fes Theartcher mH fay | Jerome David Sater as wag, ‘ Th - Hobo T-RR Tike 1933, 4.39 @ eExease DEL ovd Tcl fommondr Musqi> create devobase comprny 2} Query oF 7 vod opfcted Mysql> use company; database Chonged Hysql> create table employees( employee id Jn) Primary bey, Frsi_nurme varchar (63), lose-none varchorcso), salory clecinal (40, 2)) 5, Suey ok | vow abectd C0.005ec) Mgsql> rasest into ennployees vaires Soha", "Doe $2000 .00)_ (2. Nantes! Snath’ C0000) , G > Bob’, Jomason’ , ¢so60 00) CH, TAlice |" Willian’, ¢2000 00); Query ok 4 OWS abyected Co 00Ge0) Lets exeate some commm Del md TEL Correnorck, BD GRANT staleetnt +o Provick Privileges: ad TOM celest privilege cn ’emple yes! dalle tos uses Hysq)> create user rss ideatiied by @ aay": 3 Guory ot 1 OW BLtecked C6 03 set) Mysq!> grand Sectect on employees to vss: Guery oF 9 wows Offected (0.0 sec) iar WM fy remore PRIWEGES revoke otlee privie§es om eonplayess' ably froen wee Mus N> revoke select ra employees from 165, Quy 6K Oo \ud° Affected TCL commends GV GOMMIT ctaterun 1p mate dhonge Perment Mysql > comanty Guery oF 0 Ws ajerted (b.01se2) G Rollteack statemint t undo Chora My oqi> dele from employees ushere, employer id= G5 Burry oF 1 YO offected (6 on6ec) Hysq!> voll back; Suen ek 0 mus oected (0.00 sec) MYST!) select * fom employees; Peers g ere Peenplsyeei oe tat-aam | saosy | ae] Om do areeaats 2 Tone | Soni 6000.00 is Tohasva SS 000.60 | Avi tliang 61000. 06 © lok table ~— lock Hee ‘employees’ fable om share modes Mysgl> felect +t lock fable employees — reod Guewy ok ( rod offurtd es strom Dea ha eae employenid | Banrrve Loat_ nome salam a i, Dee. 5000.00 2 Tone Seni Hy 0000.00, 4 Gob Terao ‘es00n00 4 i : \ | sate wi Lliemy 62000 00 HWS IM Sek — (. 0050) Ha sql> insert cs mty employers value 2 Raja", “Tagere’, $1000.00) ; FREOR TG (4090): ‘Talole “ernplayee wos loceked With o READ Loch md eon) vibes Pdated © Ampecnint the Neskd MysqI> create data base Query ok 1 vow Hysq!> vse school ado base changed Hysql> create dable shide shident_ gore Guery ok Husqi> tnsent arte 38), CAthanlie ', tw, Bury ok Shudan_id ‘a Alice Bolo Chaylie Baba Eva 2 3 4 v & 5s vow m ey Nested Query Masql> seety “Shunt id Fr shidints Where ayecetd \archow (60), Yow ofheeted shilert values (1 Davies, 1 YOU opfected C0. 1500) Mysql> select trom students; Shudeat_aom: 1 Shedeat_ nome score __ sare > (selec Aug Cscarey fromm shudints) 5 Queries sChool 5 ats ( Studecid tot Prim ory key, store 1at) 5; (0.0K) Alice’ 8S) , 253Bod sO), as), Sieva', #0) ee tidied il Shidiet nome | score Be Bob a2 4 Oovid as . Eva, Ay Baws Mm 4 loooed Mysi> create Feble courses courseid tat primary very , CO Rome varchar Us}, Yashructe’ varchar (60) )3 Guery ok (ws o4teded (ose) 5, Values (2 Mathematics", “Prot. Seth) Hysil> mses) ante Wot 2," Prysics’, “Prog, Johrwn"), CB. History", “Frog « JehosoaYy Cu, “computer sitence 4 “@roh «Willies! )5 Query Sk ( yoo axtected (o 0 S809 Mysql> select © trem courses Course nome rot seni Pro}. Toho, Prog Dowts 4 Comparer scioe Pra}, Wilttorny Guery de Urns afgertd Ca, coset) Hysal> create table envotiontats (enrollment iat primany ley, strdentidymt , Come ia my Gums oF | Yow offected. Mysql> Msert it eaypiiment Values CC a aad) 7 eae) CH 2), GS 92) 5 (642) (42,3), (83,3)5 Gury de | WW appealed MYsqI> stleCl* trom enrolled s fenmimet_id [stdin id | C1 cee) iP ana -fhen —— Nested query + Find Courses UaTth mi Studints — enrolted Mysql > selecl couseid . Course nome, tmstructsr From couses Ushere — courst_td IN C setect “CONE _id from anvollenats, Cstidlent id) so)y Morse j Courst_ nome | wnst nshuctor | pa Mathenaties | Prot. emit Z Physics Pat Tohnsn Group by course iad hou ing Count F create views Jor @ parhawlor table Let’ create a simple able Aomect evplet crak a cole d views yr Mot fable create database compony 2, Nysq Guery of 1 Oud aptected co.mec) Mysql> use companya; database Chorned Hysqis create table employees employe sg. Tot povoamy Kay trstonene varchar (se), lostaome varchar (50), departene =a4 Vanchar(so). salowy decimat (0,2); guery oF 2 vow Offeeted Co.tsec) Mysq) > insert onto employers values", “Aice', ” Soinnson | HR! $0000.00), (2, 'Bob', 'smitn’, “IT *, 60.000 .00) | (Charlie “Brown , WR’, SS000 00) C4,‘ Dovtal’, “waver "57" €2P00.00 ). CS, Eva", ‘Powis’. “Finance’. 3000.00) 5 Quewy ol 3 ww appeared acer) jets create foo view bo He e O Views {yr Ermployers me 1) Depart cect Cree a vies Shoring Employees om pe * (1 depast nent Create VIEW viWLit_ deapattment As, Select ¥ trom employees, Ushire department = {1+ Guery ok 4 vps Chfteckd (9.0se0) Now, you Con query Hrex vrs data tram tne “View- A depod ment * wren) _ = select Mysqi> selects from view it depetment, [empioyeeid | Frst-none | Lastaome | departrnni | salary a fob cenit IT | 60,000.00 a | favid Hiller a? £2 000. 00 DOS Mm sel Corse) Mysql > stlect* from employees 5 ere: f ceployerid | tietcome | last ame | chparimnt | soby fee 3 Alice Johnson HR 0000.00 2 Gob Smith aT | 60000 00 2 | done Prown HR 5500.00 | | es David Miller av 62000». 00 s vi rs zy | Evo. Davis, Finance, 0000.00. S rows mM ‘stk (0-o8set) ® — create a view Booty Employees Udit salowy ors 60,000 Mysql> creat View high-sclawy-emnplajees Ay select * from employers where Sala%y > 6000000; Beith) Gh Aion witches gain | Hysqt > selett > tren vreLd-Nigh — salary — employees ; employees | —ftnomne | lasteome | departenint | Sato: 4 Dav d Miller 7 62000 00 oe fa Davis Finance | 40000-00 2 rows m set (0.00 sec) © iemprerrert Laceks for a port cubs Sable Mysql > create databax Buiscen ; i queny OF | wn ojected Hysql> use buisness ; cata bax chonse d Hysql> tases ttn creole table produucts(product_id let primony fy, product mame varchar tse) , quoeHty lat yy Suery oe | wD ag pecttd Mysql > incest tote pretucts values CI leptop”, w)_ C2, Prome” 90), (3,'4ablet |, t8)5 Guery ovo aifectea — - Bain a +vansactian Begin; == stlef ond lock @ WW tom the products’ table with fx updete select © From products wher product id= to updo te; Frodustid Produc nome quantity Price 2 Choy 3 10.0 00.00 = perform ame Operations Withio tne transaction , fer Mysql > Burry OF | your offertd Rows matched s 2 Chonged' shew update — prodie’s produc td s€tquon Why = quantity «| (0.01 sea) 1 warnings 10 Hysyl> serect* ¢roon products 5 Productid 2 prauct ame Ghaiy Soran phocre “Tablet Lop bp quontity a 20 fs lo Once 10900.00 20000¢.00 110 00.004. oo M0000. 06

You might also like