0% found this document useful (0 votes)
5 views

SQL

The document discusses the fundamentals of databases, specifically focusing on Relational Database Management Systems (RDBMS) and Structured Query Language (SQL). It covers various SQL commands for data manipulation, including SELECT, INSERT, UPDATE, and DELETE, as well as the properties and functionalities of RDBMS. Additionally, it explains the structure of tables, fields, and records within a database.

Uploaded by

VICKY BHORE
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
5 views

SQL

The document discusses the fundamentals of databases, specifically focusing on Relational Database Management Systems (RDBMS) and Structured Query Language (SQL). It covers various SQL commands for data manipulation, including SELECT, INSERT, UPDATE, and DELETE, as well as the properties and functionalities of RDBMS. Additionally, it explains the structure of tables, fields, and records within a database.

Uploaded by

VICKY BHORE
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 67
classmate 5aL J WL _ structured query _Lanquag 3 DatLa— collection of meani ngfull information —# Database -(08) = ee ——=-eolNection of meaningful information that can be _| i Stored_im__one_place_is_catied as _dotabase u Tk_is melecronic form, C computerised foxrn)} ———saved_in computer = coord, excel, notepad, Pdf, natett a pams_ =—Dota_Base Management system -——_=|-_Sitre__the data in the firm of Fil Bay cai vests “Be Ants steel -| There is _na_-velobion bla _t.30_table ae | gpams — Relotional —Dota Base _Maragement Syste =.—Large volume of dota stowed t! ——= Steve the _dota__in_the form__of table . | + =| there: (aod Wee” could -nct_he elation b/w table B_ Properties of RDSMS_ . ‘ f —Doto insert _,delete_, update based _on specific ___| condition } Accept tine _SQL__queries. ~._ tvansaction control —_ Ddota_s\naxing——________— Slo chich fellow this properties _\s__Glied RDBMS _| : — | eae oracle. 2> MySQL 3>_ sybase. Ss 4) _Sevver 5>—dba s>_Mssal_ Scanned with CamScanner P el Sau a Sevustured_ “query Language sion cated [= || aye _oviginal ver. of San (Standard 2 query —tanguage}—} Ss _ SEQUEL (Structured English | quay language) = sei isa langusge —eshich _is used im RDAMS fo | “commnuniciies dente [=] Se. statements are used tn _petform—tasiss_—sutt et ata on a __d@__or_setvive dota —_ | form de ex manipulate data al rabies __-t+' -ig= Geol. lecdinn data column _( field Atbibutt. Row _C Records ov _fuple + ©. Rewrd or “Tuple _sy “roan + gach rows _ of table called as record ox} ol Field_, column name__oy attribute ¢ e] _— Table having acon _called Fiel adtribute. : — | column_( field) = st” related i 1 | Scanned with CamScanner SQu_—_Statements_+_ _select_ = | Insert _update. _4)| Delete. S Types of Sal Stoterent = | ODL + Data_definition language _DmML+_Data_manipulakion. — Langage |_ycL+ Transaction contol _stadefpot Language — =4 -pefine__stracture 2 _gchi iy}cxeate = tx eat nec table in—an_existing dB. | “column, _yename _toble_,—data_type 4 size _changy |_ to medify structure. t iy Drop _= 4 Dap. | tabie. toternent carn used tn_xemavesl defete o_| | ___tyurncade, _quiers —cremees OL\_-rocoS__freen_ioble. _ without lagging the individual _sraca deletions _ Cro delete permanently ) > 3 _pename + change __the table name. i Scanned with CamScanner Scanned with CamScanner = Me opade = update existing data _colthin oo 4oble_ 2 melete. - delete all__yecords from a_table, the | spate fe tne _xecords remain —_|_ 4) select - xetvieve data frm the de the seled statement is _used te_-foxm ____queries__fox_extyatting infomation out | of the d@ S>_ merge - _upsert _opexotion _C insert ox update) IE 6) c ALL, coll_a Pl | SaQl_or Java __subprogram.—_| _#_Aecls Toble = contre) _concurveng 32 De _= _‘Doka control Language __Grant__-__1o_inke give _pexmissioy = ____}_- — = Sives__user's__acceSS__privilege te dB_ | Tape |) Revoke._=_ssithtraso use S__aqccess___pyivileges __}- | Sven —by—asing —the— sgattl—cammand TCL = transaction Control Language —__— commit = tt__saves__all__transaction te __the 4 —_stnce__+he last __commT__ox_Reilpacky aA RoliBackk — Tt undo the transaction that have iE not been __rmcdlified _tin_the da. + Scanned with CamScanner Scanned with CamScanner 5 | owt Dar “pata_yetrieval_language_/Data_query laogusse| | Yekrieve. data _-from __d6 server. | at is a set commands __sahich_are —used_to—__— | perspose {ike aggregate function. _____—__ 3k. manipulates the Asta te de@__for_displsy p= “ty oat DeL_, for accessing the_dota_it_uses —_ _—_|_ the _pmi__command thot i ELECT, 0. select ~ select command alincos _dB__usevS_to __rebvieve the specific {information they desire. |__ ftom __an operational dB. I : i s£LecT__clause has__rnany__optionsl__clauses__are_a: | Follows | clause Description FROM [at is _used for electing a table. mame ina —_d@__ | WHERE ZL specifies Ghich yeas to yvetrieve __| group py | Th is used to arrange _the_data into ~ Groups... fn nae ——__|_ Having __] at_-selects among tne groups defined _| — 2 by__the GROUP BY clause. | ee {ORDER BY [ah_specifies an_oxdey_in ahich tn schon] | __|_tine x00. re Kf AS | ah provides an alias whith can be used. 4p temporarily vename tobles oy column Scanned with CamScanner [Tear cmmands | J _t Dal oML [Daa query Data mani puteieon Language, Language Select |_,tnsext L>U pdote_______|._ Revoke. > Delete © pact Plan. ! > lock Toble Ql ‘What oe cee -1>_SQL__can_execute queries _against__a_d@ ty. SQL_can create, insert, updote records. i Sal mab sebiee Aide ee dp i WW). sQu_carn Creade _Stered procedure — exes aes in do— __v).. SQL_ com Sek permission om ishles , Procedure views: Scanned with CamScanner Scanned with CamScanner i syntax. -_ CREATE TABLE _emp_(. eid number cs), | ——ename__vyarchar_(20)., emob_varchar 414), | joe sal vay thar C63, ecity_vardhax 253} _ =|, The _syntax__create_an_table ‘ermp" that contain. But |S column __eid, ename, emeb;-esals ectye =._Where _eid__is_of type number | integer 4 coil | held __avy___integer. LE =| he ename,emob_ esol, ecity are columns || are of type vaychar 4—il\__Inold characters _ | £__the max. length of these field 1S 2014,¢25. ——= | The empty "erp" table will ee Jteok like _ 1__this. 1 erp | [eid ename [| emob | esal | ecity == Scanned with CamScanner 4p pescrtee folement _use_far_desibe—the list || sa Desc —s colurnn dee” _fonr__speci: fied table. | __yoe_can—_Use— | amne result otlh__are __retureo. 0 —_— = wiakement tn get —Solinssing —infa : T ____ = || pesofibe — SS ot uy) H colurnn jii)__ Datatype —ef —columo- __ lh) __ with _do_size precision £6 —puimenic __| 1 * dissntsee __senle: __-syntox:—_Dese erp saa\ename ‘ ~_ either Desc sr —SESr jhe _Stateres! ] Tatler desc. table emp —it_is_tesks (ike thi em Seale] PK | wulleie Wate] ommrent: 1 re ___ [rable calummn | atakype_[lensth Precision umber - Ss eid emp = ename| varcher2 | 2° = h——|~emeb | varchar. | 4 = : . pesod varchar] z : = 1 eekty | varchar] 25 = = = Scanned with CamScanner Scanned with CamScanner INSERT__INTo —‘he insert inte _stalement _is_used de insert ness] “tors ima table cana ing satay — insert _into_ Peseta -, 2Sal ,ecity, }—Vvalues C1, ‘mchinit,scoo., coceo pune) insext _into_emp (eid, ename jemeb esol, ecits values _(2, ‘Rupali' s4i2 , sooo ,£ ys ——insext__into_emp (eid ename,emeb, esal, ecity) values (3, ' pyiti’ , 39900 | ¢o000) wwsext _into_emp. volues C4, mobini!, sc00, gonoo , ‘Pune! |_After_inserting dota ___the_emmp table eo | tins emp eid | ename Scanned with CamScanner Scanned with CamScanner i “iatiename | = shis__syotax__seletk al\_the Fields available in the! | tobe. ~—__= | flex execoting this — syntax coe get result __ emp | [eid ename | emob | esol ecity | 1 mohini BGeo Goose pune I 2 gapali | eae = mun | {| [3 pith gace | ceooe | pune =| x ose want _ts_sulett particular data or + |__-powticulay column __we use follosing syntax} syntax _+:_select__enlyrn_—_ename , H fyom___emp. —- 4 b _=|_aAftex executing this syntax ae _geb ~esulk + | enaqme mohini Rapals pity | AAU y | ern Scanned with CamScanner Scanned with CamScanner chissmate Oz—O0 oa (i CL —The_ahere _chuse is used to filter _yecords. __ } =| The sheve clause 18 used to _ extyad__enly __] tinese records thet ful \fill_ a _spedfied = condition. a yotox + elect _ename , ecity sory ___ermp ————_}-_____—ssheve ide ae Hl =}, After executing this _syntax_oe get result t (Su)ee eid | ewame fecity | i ’ 2 | Rupali | mam | L Samtax + elect ok from __emp where esol = Go000 emp_toble [ed |] enome | emob | esal | ety [eed mohini | 8600 | cores | pune LL priti gee | eee] pune | hele. + )-the here _clause_is_net_onty used ‘yn __Select__stotement_, jt is also used ___in__updodte_,_Deleke__staterment etc. ____ 2) rh can not_be used in _Aggiegate funtion Scanned with CamScanner Scanned with CamScanner r Te | “#_peveTe aS = ae delete _stalement is used tn delete _ Siig, records in__a_—_table =. Sample__Table+ | emo. - eid | ename | emo | ecity peas 1 A 37 pune socee | S000 F z = B 98 mam | gooce | ooo . Soe 33 paki | 700°] 000 ] «| D go | aah | nay GooO _=| =o dbiele 1 whole _table{tse Use syntax ase ____syntax_+ delete _from__emp =) his syntax deletes all ~rooss im emp toble __ without deleting the. _toble. a eid [eran emeb | ecity| esol [etre | = 7 4 = | [ [ey __To delete particular _‘yecords fren _tohble we | use the syntax as fellow |__syntax: delete from emp chere _ecity = ‘pune’ t seen — — ename | emob ecity e@sal | 33 nun Goeoee | = Deihi 7§0€9 | Gooo b "Scanned with CamScanner EL Update. ae ——=;The__updade _ staternent ———}—£xisting _ vecerds \ syntox_s__Updote emp _——_}—_Set__esal_= gonoo_ | —__a@heve__emob = 99 _syntax: update emp = | P - I ek ___ecity_= ‘pune! | | colheve _ename = ‘8 | 7 - j T | —_By—exenting this query ce geb the vresul | | a || emp | i eid [ emame [ emcb | ecity | esal i 1 A 97 | pune | So0ee Il 2 8 98 Fane | Gocco I ac 93 Delhi goooo ais go pane | ait ot Ts sult I L __syntax! update _emp = {} et esol = 7ooeo caheve__esah_i. [ed | ename [_emeb [ eaty | esat [emoen pane | 200° | sos° mum | Goose | Goce Delhi 75000 4000 pane Toove | Gooo Scanned with CamScanner Scanned with CamScanner Not_null i syntax_+ update emp set__esal = 70099 ohexe _esal_ is not null aid | ename | emeb] ecity [esol [emarm | 1 A 97 pune | 7ooco | S900 2 ep | 3% mam | 700°0 | Goo i 3 c oS Delhi | ooo. | 4000 e Oo OO 1 4 D go | Pun oOo" Gor I I == Operators 17 Ayithmetic 35> _comparisioy >| Sai _prithmatic apevotors {| operator ‘Desri prion | it + |Add | = substrac * multi Ply 7 Divide | __syntax_+ select C_esa\ 4 _eincre Scanned with CamScanner Scanned with CamScanner | total ~ sal 55000 66000 — {| 79000 | G00 e.. substract trom, syntax: select_Cesol - eincre)}_as emp Sok Sal i 45000 55000 j10c0 | 6000 Multiply ermultt QS50 000 000 3eo 000 68S 3000 050 600 @e0o Divide frm iia Soe Scanned with CamScanner Scanned with CamScanner 2) Logical Operator | i operator | Description I & AND | \ OR | Not | cord) | cond’: [ANDER] ORC] = a o a mes ia t a F F +I F aie F T | 5 F FE e { | i cond” stan , | T F = | re a i I @ | AND syntax > Seleck t from emp colbeye _ename = A amd _esal = Sagoo | Result: LI etd | ename | emo ecity | esay | e\noern {| 1 | A 37 | pune | Some | Sova Scanned with CamScanner Scanned with CamScanner |_—— —_ Syntax: seler £0 __emp cher _ename=A oR —_esal= 50000 ;__ ‘Result: eid| ename | emob | aity | esal | eincers | 4 A 3ST pune| soece| Scoo | |,_NOT- syntax: elect a #xorn__ernp. clnexe__not__Cesal_ = Socee) 5 | Result. | eid | erame] emct] ecity [esal [eincre 1 8 32 | mum | ce | coo 3 © | 93 | Derhi | 75080 | ove 4 D go pune} null eoo JI ae Comparison _Opevokny aes. © Totos | Description = Equal to > Greater than < __ Less than >= Greosey than ov equal to a= Less than or equal to in j mot 19 a Between not Betdeery Scanned with CamScanner Scanned with CamScanner ———|_ syntax :- selech ae xem _ ep. = iL here __eid = 3 3 Result: : [eid ename emob ecity esal__eIncrer 3 < 95 Delhi 75900 {O00 = ol Guenter than (23 syntax: selech Ae L fom erp ia I ober eid ams | Results I eid fMame emob ecity esal eincre 4 D 30 pane all 6000 lee oe ere oe _|-syntax+: _select_ae from emp cohere eid < | Result: I [eid [ename [ emos | eaty | esat incre, [ ay A 37 | pune a || 2 | B | 38 | mun | Goce Goso | 3 & 33 satis ceo | Scanned with CamScanner Scanned with CamScanner Greoler_than or_euicl in (72). oa “syntax selec a = ! jo ror erp where eid >=] 5 Result: . a eid | ename | emob | ecity | esal | etnac i A a | punt | sSoose Seso 2, & 38 ‘mum | coos Geos 3 | «. |..99..| dam [W520] 7 Gore < D go pane nu Gooo a Less_ than or ~ equal __|_ syntax + Sereck_# y | From __erp. ohere eid <= 2 3 qj 1 =< - | __Resalts 7 Teid | ename | emob | ecity | esol | eincee I 1 A 37 __|_pune | Sere | Soee I 2 eo as mary L Soest. Ggooe oll Tn + It displays pasticular seb _n€ values. Of chal 1 syntaxs select a J from emp _ esinere esol JH (S0000 » Cocco) + | || Results : eid Jename | emeb | ecity | esol sUancre, a 1 4 A 31 pune | Soro gece g008)| Gore 2 ai a Ee, Scanned with CamScanner Scanned with CamScanner ——;-syetaxs_seled ——— where esa net. i__Cs00°o , COCO. from emp | Result T Ted [ename | emoe| ecity | esol eimcre | I 3 q D ge pave [| ull Gooe | c 33 meni | TSO00 qooe | * | Between - possible range _of value. “syntax g “select i fom emp _oshere, esol between Ge0e0 and _7ooosi} eso4 elncre, A 97 pune So0co seco 6 93 mut Geeee] Goeo ename| ened | ecity | esat | wince] 7s000 [| dove Scanned with CamScanner Scanned with CamScanner S@.__ Operator Whe Like _operaiay is used in a _1aHel te__search for a fied 5 4 _fer_a__specif a, | -Ttis_ case sensitiv l | —There__are tue _coildcaxds often used in Conjunction ith Like operator M% > + unknown length of Ling -— . + _sepresent zero, ane_ov multipk chawden, = sone Unknown _charader ee * Tt __vepresent. a | L Like operator Description |_1>| cust.name ‘ax’ [Finds any values trot star: 2) cust.mame ‘Za* [finds any values that end F splcust mame x orn | inds_an alue ot ha any position —4>|cusk-Name S47? | finds _any values that lave “¥" ST | \n__the second position, | s>|cust mame fa-%? | finds amy value Io fee es rare, ates 3 arad ~)|cust -wame *q7%0? | finds any values thot ca Scanned with CamScanner Scanned with CamScanner = __syntax_+ selec ae H from _emp \ clhert__ename _tike Sa” Lsyniaxs eleck | fer trap y —______ahert_ename_tike fx u ! stax: ___seleck ae - £2 _emp epee —_eibese_ensame like —“—a 25 | 7 lL suntax: select ae | fraro__emp. where ename_tike “zn-? 3 [Disha] faam___emp. : I where ename _Like {-077; lakash] syntax __Seled | from __emp. : | cohert_ename. like ©S-- 4-5 __Syotox + __geleck A 1 frm tmp tohert_ename _tike “MAL? s select Scanned with CamScanner Scanned with CamScanner Date function ample table. emp eid | ename [emob | esal 1 Abhi go SogoD 2 Bes | 31 Goore ; 3 cid | gp JE00o 4 Deepa | 93 goes j s Era 34 gooco i G Fan 3s nail | aan | There _are__five types of agyregake functions: —__ “4 Min. 2> max. i 3>—sum d 4> Average S> count min a _syntax_: Select min _Cesal [esox from) emp | ‘Secoo ! | Tt display min._value fom table onty é it_comes__twice., stil) also it display ie. (min value of column) é . Scanned with CamScanner Scanned with CamScanner classmate . oS Max 3 syntax: Select max_Cesol). eS from __erP. SUM =| tt done additio x syntax Select Suen _Cesal) = one Soom Avg Th _give average of all _secex 2 “syntax: Select avg_Cesal ose from__emp. count - syntax: Select count esal} esot form _ernp 2 This _query__count_al\__3ecords fem _esat column ___except _tinan mutt _watue syntax eleck count C4) $x0m__emp this. oe aciuding anu esat G Scanned with CamScanner Scanned with CamScanner are_trao_characer function [Leharader fancion] y 2 _Manipul Lower, Upper. swnit cap. Substring astrina: case manipulation - omey 3 “. | _a\l__the chayacker__disploy__in_smalll syntax: select Lower _Cename) from__ernp. Lower _ename Ashi bys. cid deera Scanned with CamScanner Scanned with CamScanner nls \S=case manipulatic ive . _—_— FP — | scatar fun’ seleck__upper_Cename) frarn__ep. red SR | : ‘Upper ename | ASHI 1 BrPS orb DEEPA ERA FUN soba toa emaining——_ character _ave__in_smal1_tetter_ _syntax + Select init_cap Cename) f from _emp initcap Cename) Abhi i Bies | cid { Deepa 1 7 Exa Scanned with CamScanner Scanned with CamScanner ae i concok > ll + Te commed two column operator from __emp leh ename | ©!) ow] pb) E | substring . C substr) potterin/stving 5 Xi» 3 C Hh I ____stayting__charader____length of String __| ____paitivn_of_stying___from _thot_starting. character DoR Preduck -rp O1-03-Aelg | TV12356F234L4149 Abhiit | 9t sachin | 3t Sandip | 9° ming Be Rabul Scanned with CamScanner Scanned with CamScanner classmate a4 h Gt Ri 8 aot L>e laet \ “4 Ei Wax_1_seiect cubsty (tename ig) Sor emp. Subsix Cename)> Avhi sach sand mina [—_{esntax +_seteck_subst_( kom : £yern dual TE string is mct_in oracle do, still oe find pea substring, Sobshing Ckamat’ 1/4) Koma an I Tr I k. syntax _selech _substy C'abbiiit 4.4) I from _emp. I | => Lait |_syntax + Select _substx _Ccabhiiit! -3 3) a Scanned with CamScanner Scanned with CamScanner Dual = dummy toble, emame (474) > lensth net take In -Ve concat _ _ operator ~7 H => To tenntd tao coramn _-S3ntax + select substr Crvi2gse723414149", 3.9) 11 ubstr_(C'Tvi23s6793414149' 2-33 An 2mp 123S567234- 149 | “to doin _first mame 4 last name syotax + Select _first name \\_tast name fmm __emp Select substr ( product name, 3.9) | fi substy _¢ produch name 14,33) as product nom 0.__fror__emp Scanned with CamScanner Scanned with CamScanner a S> Date Function —1) | Momnttls pees] ~21|__add_. months 3> { mext— doy &> last ~ da S>___syedote. fey estore Li month — bebo eery | | (syntax. setect —monthn—beliten.—(si__-Da8. 1 | - frory__emnp 3. | i | > 24 I i |_syotax +_select__add-month C doi,3)__ I a £0 __emmp 5. = >__01- 06 - 201F __syntax : Select add -rnenth ('o-o1-2012' 12.) — fxure__eynp dual 5 t i —> 01-91-2018 i ie: ne a Scanned with CamScanner Scanned with CamScanner classmate. y | syntax: seleck next-day (‘17-0 1=2020' , fridoy) fom___dual ; => 24-01-2020 syntaxs_seled next-day Cdoj_, friday. £21) __e rnp | 4), Last ~ Do} syntax select _tast-doy Cdoi,feid i from __dual |_syntax : sel ect__tast-d fxvm__emp. sys__dote _( dake £ time} Seletk _sysdate. fr duck Scanned with CamScanner Scanned with CamScanner a i “Constraints —— Ee = constraints __ove__used___ for __ applying. eule_duying | —— dota __insextion _by "| = 9p constraints axe used to_specify sales en | |__data_in__table | Pl aaa ecard See og ose at a mimag_key_= A —combinalion of anor at | ——4_ontque__uniquely_identifies each row_in take, Ba uo nique - ensures that al|_volues im_a __} cow ery __once_diffeverst_________| NOT ULL = Ensures that a _co\uen ave _a_NULL value | Sy Forel gn—key- uniquely identifies a coco/secord ee _ _ncthnee to ble! = | F>.—composite_key_= Scanned with CamScanner Scanned with CamScanner |p. does wo ct_acceph__duplicode_g uli values — _3t 1S the combination of nique + not null Key Eada table _\nas__oniy one _P- constrain’ you! yvecord is uniquely identified . yAtax 2 _exeote table emp (eid number _____ename_ varchay_2 (20), emeb number cio). | esol number_ce},eciky varchar 2 C2 insext_into__C 1, ‘A! 97, sooee , « pune’) 2 — —— 3 1 * ae ail x Bs 2 + eid ename | emob] esol | ecity 1 A 37 50800 pane 2 8 98 | Gooco man iis e 93 | tooee | delhi I Unique tt does nok accept __duplicote_volue 414 accept multiple om __nat\t_values syntax; __creode _toble emp _Ceid number __emob_number_10), ename varchar esol nuynbery_(S), ecitby Varchar. setver accept only one null yolue. Scanned with CamScanner Scanned with CamScanner the unique constraint _ensw /— in_a__cotunn__ave diff | =A __PRIMERY KEY constraint —autorneticalty L _a___UfNtT@UE constraint. eS | __However_, care _can nave many _u) t pey_toble_, bub _only _one PRIMARY SEY —____ constraint __pex i TORRE RES | |] eid ename | emob ecit | 1 A 91 ham 2 8 a8 pune I nu c 34a adhi D go pune. Tt__does not. occept___nuli___value Tt accepts _duplicote Values. yntax + cyeote table __ernp (eid number ¢ ename _voychaya.(20. Net Null, emeb. ecity Vaychar2 C203) wet nay Scanned with CamScanner Scanned with CamScanner tesert into emp (4,97. 8,5 7 ) chesmate — checks, 2 . It_check the condition before insertion 4 —Tt__is__used__to limit the value _vange thot canbe placed im __celurnn =| 3£ ee define creck _constsaint ona sing) —columyn___it__olltews._ only __certain _values__for . thi colunon.. syntax: _cyeote table emp _Ceid numbercs), ed | ___number cio) , ename _varchar2 (207, €s! number cc) _checls__(esal >= 6: | ___ecitty_vaychay 2293) default _va\ues__fer_a_column.. The default _vatue coil) _be added to all records _1F no other values is specified. |_syntax + cveoke table emp Celd number cs)_, _____ ee _nurmber_(iol, ename _vaychay 2.629 __snumber_G).,—ecity vorchay 2 c20}___| default‘ unknocn?) ‘cette wa ae a Scanned with CamScanner Scanned with CamScanner create. _toble emp Cetra 59 primers x3 | ename_vaydhay 2.(20)_ nek AU» emmelb num bey Cs) uniquel esal_number_Ce)_checly —Cesal 7600! a _ | var char2 cre) default unter esa”) —_£§£J—_, _£xample_ Coppiying all__constraints— sx __columy | —_. Let_see__how many yecords ee pass ——————__| PK roku __ unique chew default al eid_[ ename | emob esak city t at | A OF GSOO pune 2 B&B 98 Ggoos mun, | 3 c nat TS908 unknown xl G D a8 #0000 mary, x{ Ss | naw go BSc00 ues x] G6 D 7 Sgoco_ UNknoN S| ale 95 bce nay. Mao: F ge 7oceo unkneen = | a a | Scanned with CamScanner Scanned with CamScanner -A__foreign key is _a_tield Cor coll? of fields) in—one—_toble that __yefers to the primary ke | Foreign key, . itis used for _mapping velotion bla tas0_4obl in__anothey table. The__toble__containing F-_is_catied child 4 —is_cal.led__-veference__or_parent_toble —4_the _toble _cantai ning_+he _candidde_kcey P15. of __parent__toble_is__acts_as Fk. of child__toble _syniax + create table order _Coid number 5), oname varchar 2. (2) ,cid number (5S) ore fexemces__c us’ i i ale 1_cush Cparent) order @hild)_! Ta cname |_ccity oid | oname | cid 1 A pune Aor Pd q 2 8 mur Jor mob | ¢ | 3 c Devi 13 | ner | © ~& D Cheam 104 \op S e | mun os PD 6 F pune = Scanned with CamScanner Scanned with CamScanner usyntax + cname Berni snumber_cin}_>— "+a pk —_C cid_, Cname_, cmels)_)+ BPR e yuan __one__colurann, akan ta Ca mera | Cost | cid | cname | ccity emob { 4 A pane 31 {| a 8 mun 38 | 3 c pune 30 I | ©. D demi ® [a— | S E Goa 56 O- F wagpuy | 6D | te l (Sy G solopae | Ge) | Scanned with CamScanner Scanned with CamScanner DD _( dota definition language) add__cemstraint_, vename _column_,_change- doin type, data size. pe_tobise (Gadi eee mn ina table we use this syntax, smtax : Altey toble emp Add __Cesol number C63). a_To add more tian one column use _tihis_syntax. Scanned with CamScanner Scanned with CamScanner EE eet erento SeeeeeeTE 7] classmate, ete ME co cage doe ape = ain k I syntax + alter table _emp- | ty Hatter sin Socte cc sewver | me aces __sywtax s__Altey table emp sedi fy column __empnam inserting records. t 2 then size canna: | cay only__increase__Size > Add constraint The add nstraint command is used to rate __a__constraint__after a__+table The __fellooing sei adds a constyais n “pK-pexson" that is pts. constraint en _~rnulti elurans _C TD 4 Lastname). user defined sntax+ Alter table emp aad” ______Add__constvaint__Pk~ eSon__primary ree Cay act MameenGeyae syntax + _Altex__table__emp —__ 4 ____ Add constraint —_uk_ emob. unique_Cems wy toble emp E Add constraint chk-esal chects Cesal7 Soce Scanned with CamScanner Scanned with CamScanner classmate, 2. Drop constraint = = . -. The drop _censtyaint_ eee “used is delete a unique , pk, Rik or check constraint ma “syntax: alter table emp — __drop _constxaint us — emoh + = =| To. drop p.m use — +—tnis_eyeta syntax: Alter toble__ emp al i drop eer oem ______d Rho __dixpp— re cers “this -syntax___ | eyntax “Alter vos emp ao ‘| dyop_constraint chk —esal 3 ____ a a 4 a\ bey e emp __ modify _ename not siti _ Alter he modify ect syntax+ a “hie _emp Add constraint emp-pk. pray RY (eid, enome, est ) Scanned with CamScanner Scanned with CamScanner 2, Lavap yee : [=| the drop _toble— Tcanctbraink is_used Pe aga) —Sxisting table 1 f\ Spuseetn Ue. re. Sere ———-Syntax+_Drop__tobole em p_3 she__tyuncate table eee ak ead the _dota inside __a__table_, bot nsb__the tab) qrselt. = ill | _syntax_:_Truncate table emp s Sample table __i emp | etd tname | emod esol | edept am 4 yusuf 3765S | SSooo cse 2 al nik 7705 | Goose mech | 3 amit Bee0 i 4 shivani 7424 | Ss sachin 8553 { G priza | 7865 A t okash Oso ft tc. le. obh 2 nik ge | isamte My | Scoayeop Te 12 - pooia. Scanned with CamScanner Scanned with CamScanner Scanned with CamScanner Scanned with CamScanner cse mech =T = S civil al edept count. cst a) 4 | —eolpmseiect eer ——__| ~~ coumt (edepty f10r__emp_ grup by edept 5 count (edepty Scanned with CamScanner classmate gtoup_by products S | olp | || : peoduct | maxcsates) | {| PD 20000 {| mob 40000 ll \ap GooCo —2) Gx up _by__clause_ “eno different columns _ Pee cota celect ede toca 49~_emp. geese eyelets esa 1 se,a50%) 1 Q. Q 4 |_O/P Scanned with CamScanner Waving clause Having clause decides —csbich__group__in be | displayed after _gemexating the _yesuits 1. “group bj! _clause_ + yt Filters he group _by_wesult by using — | aggregate — —functions __Cgroup function)" colpere___dause apply 01 _befnre _ginup by Clause. | -——Having___clause _apply__ors after _gynup hy claw H ——— syntax :_seleck _edept_, count Cedept) Syom__emp _ l group_\by _edept naving___count_Cedept ) 273 3 I edept cse mech Yk {| 1 2 4 | 3 S 7 | [$s a | 7 t—} fs (song asa eal a Hl elles ar - I : Boe i oe { iG ee : ee Scanned with CamScanner x BSoo0. gvo00 x . Fae Moca _to__dispiay tine duplicate ~vecords |_s 2 Select 7 potax zs. edept ses Sypup_toy__edept having count Cedent )> 15 be : dept i cse we mech ch at Rar j a__qury_ Fey___he«o__te_dis ploy dept. \igiest Salary _2 7 Fria Take Scanned with CamScanner Scanned with CamScanner oe 3>. “order by clause —The— in ascending _order__by clause Sorts the anata ia or descending order. ae soxts Phe svecords in DESC. in__descending =| se ._defautt | —Xecords. keyword i order. ascending. order by used __4n_ so’ ee Ascending—_ordey_—> _A-2 O-3 Descending __ovder_—» _Z-A 1 J=0) 2 Selech ae £ From _emp order by__desc_ 5 4 £ Highest to lowest JHE (A | | Lsyntaxi__Select _& i fyom__emp 4 order by esal a: ___Lowest ii 1 +o. = T)jsyotaxt Select Highest = iui i Frorm__ernp = ____ovder_by esol; —from _ ____alhere ee - —_having — eid rd _edept = 7 € count Cedept 14 7 Ts ac = _ovdes by edept desc 3 [te alt Scanned with CamScanner Scanned with CamScanner ~ avid clause» Having clause { L-gxoup_by clause § then filter tine _grpup_using group Fup aageeqate f {a> Having clause use sbenntmeniaiers after group _by clause e + use tay we must have to | |_caqreqate function in} _us¢_aggregate function] coher. clause yo_having clause. ieee =} atocbedebedaebe ch Scanned with CamScanner Scanned with CamScanner -——3#._Pseudo__colummns prank d — fy Aes) tas oxdex by esal desc ovoe B S000 Booco 0000 TS000 75000 S000 Geceo Geceo Ssoco Soovo " 4ooco qo aeceo Ie 42 iz 4oo0e 1. eres Yanko) MIN] WU! | oo}! P j= ~ | 0 cannet change. 7 Scanned with CamScanner Scanned with CamScanner Br egqntax: seleck emp + % , Yownum | from emp clas | where Youwnum <= 16 ; for a Le si I order by esal desc Younum wvesid I gooco 1 AG {| BSova Fy AE 1 Bocce 3 1 7 1 H iL L I DaAUeX4 ___ ener query outer _query =| first Teenie marke queq kmail xesults 4. further generated _vesult acts as a up during _outey_qurent_ex __ syntax + _select_max_Cesal) t ee | eye _exnpl es aso (“oa Fa | here ___esod_ <_______+ Cselet _maxcesal) Toner grom__emp) — Scanned with CamScanner Scanned with CamScanner 1 Fiyst _execute_the inner_4 wey —Cselect max Cesolj} her __emp_) | t 2 O/p_ok this __i.e._govoo_ei!|_be ip of | outer __query_i-e I iN select _max_cesai}_ yor emp colnere__esal_< goooe O/p_of outer Query iS 85000 Seieck max(esal) fvorm__emnp __ - ieee esol < —— pH) Geteck max cesald | from _emp 7 wlnere_esol 4 — .____C select _max_cesatd ES > erp )__ t ;— _ ©. Second max salary using moat jn fb _Seteck woaeteseegy foe +} «a | Ave __ emp : = winere__esak_ mot jn Scanned with CamScanner Scanned with CamScanner select. * __€rorn__C select eid, ename, esol, dense-rankO— over Corder by esal dese) —_________— Scanned with CamScanner 4 second _max_salary 2), watyd ynax_ Salary, - cath max__Satary 4 ‘th __smax_ salary Whok_is__diff- blo rank 4 dengrank (Tie op eget Solg es |_ Syntax: selec 3 for _Cseleck_eid, ename_, esal_, dense.xai | over _Corder_by__esol_desc})_as_yanking - i fxm ___emp_) | wher __vanking <5 | | 1 isp Piaj—s4_tnighest tot!" highest solony | synkax+ _selech te frovy_Cseleck_eid_ ename_, esal dense __ Yank ()__over_Corder_by esal desc as, “ranking __frorn___emp’) | colnere__Yanking___bekeoeen_C3 and- a 2 _visploy a4 highest, 7! highest 498 highest f———_—_Solary k »—Syntex: _serect a ss |_________frorn_(setect_eid_, ename_,esal, dense. *ONK.)_ ov ex_Covder by esol dese) an ing fern eine) — | _apere_ xomsing in _(3,7,9)_ Scanned with CamScanner y YOENUM - — PSeude celymn xl y -seond—tovestsalay = syntax: Seleck 3p — fim selected jename,_ es [- +—_—tams over _Cavder_bby_esat}_as_ranking— 4 £0 _emp, /———ohure_ranising = 2 a) [fH tost__thvee _xecords ' whertrxrownurn <= $4 ______, ares dese. qeutetere: avr oA lo ‘| pe BS ————— wre fet s 105 seo 2 403 807 | [108 4&o § wq D408 | i ee Os wS ff SOs| - | 401 10 * cd | | | 1 | . | a i— | aa ei Scanned with CamScanner casemate a = A—join clause is used to combine xees fren ——|tmo__ox__moyr_tobles based on _a_retoded column bia them. ; Fr ed fo_Aisplajing— dakar mma ——o|__piffexent types of Sei yoin SS | there ores4 different Aypes of the joins in Sa (toner) Join. = ——Bttumns_srerards_that have matching values LA beth _toble: LEH Covtery doin = oe ———Retwnns_ol\_xecords fmm the left table, <_ |__Aine matched vecords fern the vight table ns _a11_xecords fromthe right _toble, & the matched records From ne Wefet. Fall Covser) Soin é z : | WOS__OU_yecerds hen there ig a _ Motch __in__ either left ox paght eo hiebe Scanned with CamScanner te, i ane _ outer join y|_ Inner join d a the ma record acc {| cust oxder cid | cname ceity | oid | oname | 4 A pune 101 PD 4 ti B murs 102 mob 2 i {3 c pune |ie3 PD 2 | 4 D pune 124 Lop 4 | S E myn, L dos] Hed | 3 tes mob | 4 tax: select _«-_ Cust. crname_, order.ona for cust Poney_join order - i on__custid = ordex_id 8 mob : L < i S. ion bei pam PT aa Scanned with CamScanner Scanned with CamScanner __ syntax: select ak 7 from cust _ — . | Innex_icin__order___ E| , on__cust.cid_s__ordexcid _ | oy = given by 48 engi I if cid [name | ccity [oid loname | Cid aoe | I 1 | A | pune! rea | cap 1 : / I 2 B mum | or mob 2 / = B mum] 103 PD a al I | Bic ole | CO a g [73] pane [anno [a {. at D pune | toc] mob q syntax. Select He frorn__toble 1. Annex _ioln__table 2 _ On__tobletA_= toble2-m Scanned with CamScanner Scanned with CamScanner Janex join on—table1.4 isplay the _rnatching _recerds fron i tob\es 4 _rernaining records frm eft side tok \e cust order i | a cid [ cCname | ccity gid_Joname [cid | 1 A pune 401 PD 4 { | . Q mum yoru Mob - t | 3 c pune 403 PD 2 EI 4 D pune 104_|_ Lap a s € mun os HDD 3 ¢ Fe Deihi | joc mob 4 i 7 q pune 107 mob | 2 8 Hf pane a) ee Lap Ss | 103 pp | uv } Vo Lap Wz aN mob 13 Scanned with CamScanner Scanned with CamScanner ae _cust. cid = oxdex.cid __a left uteri — | ] a 7 ] cid | cname]! ccity | oid “Toname, ee | 1 A__| pune | 104 Lap | 2 8 mun | to mob a 2 B mum 403 PD = | 2 B mur | 107 mob a | 3 c pune | 105 HOD 3 | 4 D pune | 101 PD q 1 au D> pune | 106 mob 4 | Ss E mum | 1c8 Lap S e F sdhi | nat | nav nail z G pane | _nuit nal | ull 4 | wy | nul 8 H pane [att | nat 1 { | } i Right outer, A019 xt __display—_the matching _vecerds _frarn_both — tabres _§. Saas secords fam, xight_side- table - ——- al yntaxs__Seleh ae - from __cust ___tight outer join order _ on cust. cid = _ordey. cid — Scanned with CamScanner Scanned with CamScanner classmate cname | ccity 7 Pune | 14 Lop z e mia} Ac2. mob es iS MOEN || 408 PD (| = 8 mum | io7 mob 3 S pune | jos HDD a = pune | 101 PD 4 D pune Joe mob S: = mur 108 Lap nv nay nuit 123 PD ite null nul vo Lop 13, nut naj) "1 nob Full __outey join syatox_+__select 3 from cust o/P id | crame | ccity [ oid [oname [cider] 1 A pune | 104 Lap A 2 B mun jou mob a 2 B mum | 103 PD 2 y 2 B mum \o1 mob 2 3 c_|_pme Atos HDD a | q D pune 01 eD q es D pune 106 mob | 4 | 5 e mun 408 lap Ss Poh Deni nul nay f¢ LT Gg pune nal ult U ele pane | nail null oi wc Nui) A404 PD n | aol naw fan | No Lop [a2 13 | nu nun uw mole 3 Scanned with CamScanner Scanned with CamScanner classmate, -C¥OSS__ loin = tt is __hased on _cartesina product 4—syntax_+ select ae seta t fram cust — ef oss nin Orde + 7 O/p_- ak ill display 4xs = 20 Yecords Lt __caill_mapped one, record to other cust _cid_is mapped ity 4-@: csith to, 102, 103, 104 10S Mow _4o_ioin _snultiple fabble_2 || jocakion | i tocia | jocname | cid ci i | 1001 : ‘| i 1002, fi ‘003 | oot al, = a oe 4 Scanned with CamScanner P | chaste 5. ¥ 5 ‘ . eee k __seleck_cust.cname, order, oname, location. loomame —~ |__eyern cust - ee cname oname jocname B mob youry B PD many ic une a a wpp_ | P Td self join ~ _-koble _Soln_coitl itseié is cotled self join. ®& eid mid - 1 4 : od a 3 : q 3. eS q = C2. ————— -——, eid Frame | mid |. a 4 Amit 4 fe 2 abhi 3 oo Pane 4 vi 2 . Scanned with CamScanner as_e@ropname syotaxs Taek es fname | eo. Frame 4S rangrname So £vorn emp 1 | = _—_— } jnnex— join —emp. p+ —___—— | on 24. mid = e2.0id | | opp. | {| crmprname mngy name | Amit nik || abhi ___ Shivani 1 nik obhi | | i i shivani shivani | | Totexview Al pifference bie alter Aggregate function __¢3-4__ques.} Ubstring like _operador, lin operctar , blo op Soin. CS ques.). How te join _S tobles ot nore than 5 tables? Hous -to__display _table__infermation _ How to dispioy dup Neate records 2 Cgrmup a)! Hows__t»__delete _duylicate Yeords pdake salaries of OL) __emp with 10%. Scanned with CamScanner Scanned with CamScanner classmate ename | esat — 4 A 000 =A 3B Goccey| em | c | go000 | e 2 40000 2 7. — | odd vecordls. || eyntax: updete —ernp. | ek ename_s_t abhi? 7 : “tp _copy—_ tbe table? —_______—_-—_—-* _=>|____cxeate_table _emp1_as_- Select # from _erap——~ i OR og (gnsert_inte_emp1_Cseleck & fram. emp)————> I ‘i : an) Sek _ operators —Cunion intersect “nin anjenall) t T q +19 ference bla "ranks ¢) 4 —dense=¥ankC}———+ fe ooo | 25). How _to_disploy —duplicode.— _xecords by youid ¢ Pe er oH Scanned with CamScanner Scanned with CamScanner | k ph ——<$<$——— eid ename emob edept : a AA 1 m9. ~~, = Tae 2 Nv 3) tt 7 inc | 3 a ae mech ao | 4 Pp Eas ce ine | 5 g 84 zt TAR G Rg 95 mech “AG F Ss 96 cse ans Eu aut | AX 3 a, 38 Leth [ |_syntax : fied ge I from emp ~ 4 colhere_yocoid a nt inset et __max__Croid) from ernp_ group by _edept) O/p_ of _ gubquery, AS I ese | tt mech L civil I TAR Qne Bhe RaW ; i GAD see | Gar { 7hG Sor . 8 Lo pete i ©/p__of__subquery is CAG, AE, AT, AH) _ Scanned with CamScanner classmate usente emp-backup_as__stect A from — Weve A= 25 Scanned with CamScanner Scanned with CamScanner

You might also like