Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
29 views

SQL Commands

SQL

Uploaded by

venkata jaswanth
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)
29 views

SQL Commands

SQL

Uploaded by

venkata jaswanth
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/ 10
Chapter - th SQL Commands % SQL es Structure query Jonge e Gnok %& helps to. Storing , manipwabyg and retriewtng Qhoko. Stored) in relational dlataloase - SQL fas many Commands. Dra there Commands Are Classified Sao fetypes bored On Ther nabere. DY DDL »- Data Definition Langucage 2) DML %- Data Maniputarton Jongsemge 3) BCL, s-’ Bato Control Language wy TOL Tromausor Convo! Courgya sete N) DBL t- Data peftniten lon » __ SeFinivion Mingus. 5 DDL Akins the “Conceptual Schema provictiag o Shots betaeen the Jogos nd the physteal Shudture, of the database _ Beste Commands of DPL Gre Comenond chescipton ee Gaitee Di CRERIGs = = Te Creares Ge Rew table soe ay ALTER 5 Te mockdies the exacting tate. 2 Shucure. ty proe a? Te cheleres an’ enttre toble an ce Catalase. © scanned with OKEN Scanner Commands = Te TABLE Statement “S used + Create O new table tng “the table Hag Os sc table Gavolvss AMER : > Cresting oboe Een and eadh ~Colume's Gato yrs. Synray CRepte TABLE tabble_name ( columnt ctatatyos , columar dlatutye, column a Gataryne, PRIMARY Key (Menten Ont or mere columas) Example 2— ERIE Teste. ene Regno numb Clo) , N&me — varchar2. Cis), Doe bere Fees pauenter (9,2), Corneraatin Char C4), 5 prienary—ieay CRegno) Ceeme Trae she Keyword followed by the table name, An open POranttusts , columa_nomes, and Gatatyos fer thar Cotumn, and followed by a Closed Paranthests - — > Fer cach Column , the Colume a GRIN Alas fetole RaNawton re Ee er > Column dlefirition Sepavatead fo, = Heve 4 Commas th tobe must Aave orsenst One Column > SOL Command Shout endl oxi o GentestorG, ) > This Gcample Creates G1 empty STLDENT table abc dooks Sake thts: Regn | name [ pee | Fes | ALTER Statement + the table “Garbo modifredd or changed boy using the WER Commanet Syeae 2 UTE. TAGLE ~~ Table_name } ADD C Columal dlakatypr . Column 2 datatyre ) + * PER TABLE Table name Moorey C columni ctarakyre, column cheetatyp) + Xe RLTER TABLE Taboie-name Drop (Cotumnr datatype, Column iakekyoe ) > Geomple— & Diree Tete StToDENT ADD Caddrag varchare(s0)); —> Table adteredl Cable boots become) Regno Name DEE Fess Conbraation asidress jw plreR TABLE —sTUdCAT monteYy Caddres varchora(eo)) > Table ‘altered . Citere Increase Re Stace Of Column clots, from 3040 10) ae ptree WOBLE sroDENT Deop Coadres) —= Table tered (he Column aalras tq fhe table Studer 3 removal) Regine Rome pop Fees Contetnokton @ scanned with OKEN Scanner ) DRop TABLE > he SQL, DROP TALE remove or delete. He table Talole- Name 5 Staremetc as usect TO Gebet ton + Drop Wee example = DRoP THLE > Table dropped + Syntas STUENT 5 2) DME CDaka Manipulator Language ) dhe daka manipulation techeques eluson , ep clation , noc licater = DML prvide dake Gakeceton . Easeran , oh of clara - > Fay of tie base Commancls for DML Gret= Coramond dkseapton RDetaues Certara records fom one Disses Bec or sere tables > Creakes © record —> Modifies retarcls Te deletes yetords Enso updiace » Deere wD TNSERT The SOL TNSERT INTO Sraremur %& Used 4p oda new Tous of clara to G table the dak ofoase = TNseRT INTO TRBLE_NAME VALLES Sy © values, value vrata 95, Bei- Enger karo Stuclen calues act ingert Anke 'Stunenr \cadues’ C100; John’, 15-Aug-22, ee : Hopes ,cEGA); ‘ ‘Soxe0 . SCOR); —> Sunras t- faset toto StvDE! ‘ynju',' a nto. ENT Wales COL, "Yajy", "26-Nov-98, > SQL SELECT Statemene ts usedt to fetch the dato from @ chakabare tate. Sue ~~ Gom talote-name ; Seter « fom srodenn sy able te hewtng He eanpte !- € Constcter the. steven fodourag rrecencs ) De = _| Regno Name \ Fes Conbnaaton | too John: tS-Rug-4q Hooves CEGA IO TOFU Qo-Ntay-98 Soeos SEGR | ak) Vpdate = _ absitty 40 Change dato through Ts SQL provide the LepATE Command: 3 The) SAL) CPDATE Command Used “ho mecktly or updare Gn abreachy existing FOws of o Aable - > Sysray 1+ UP DO Su- Column_name = vols % Update — table_name Al HERE Condi on Rcample 2 “Updike STUDENT Sur nome ='ckosh' where no = loo 5 a> 1 row Updaredd . Ancl STOBCNT table, becomes, i «9 «| pow, Fakesh |'s-fug-94 @ scanned with OKEN Scanner ww) DELETE Command = Tn Sol on alreudy extsing fom talotes through the OE yous are TeMoved| of DELEre Commang, Syntact- DELETE —Toole-name uthere Conchitten: Cxampie:- Deere STUBENT Where ‘Regno= 1O1 2 row “dered - — Hee stuvenr table buoy , | ' Name| Doo | \Condstaastton (90 | Akah |e-nlg-tq] Mooosl CEBE 2) BCL Crate Comet longuage) Ty These SOL Commancl cre tied for Prroviclinge Secunty fo Gutoboare objecr- Command, descriprep GRANT > gives Privliage ffestiy [ ppecenteston user- Revoke > Takes bark puvilages qroted from Users ia Hy cL CTranscutton Contet longuage ) > Tt Anclude Commands 4o Conhol he -hensuctsons fn G Gukakase System - 2 The Commonty Ure Commancs dre. % Commrr —> Tr ts Used to Sove all the tranigetion elated) Chee eA . go to the Gass — Syntoet— Comnart eed : at) Rorrencie —> Sometimes ave had one removed «the useful ‘Yecord Therefor, mb ah oe tux have Gm Option of rolling bas our ont > Syntax .— ROLBACK” 40 Spor ‘harsaeeton! & me Ofher Commands Used SQL Gre 2) DIStTEner .- the SQL aestrncr Keyword 46 Used in Conjuncion asin “Seicer Graremtar, fe Uroanate GW The upti care yecords SS fetdoag- Onky cantigere -vecords « a There, moy be a Sttaation when You have mauttic Chey trcote records ta @ table. lathite fetching Such YeCads, DISENCT Ktyeunds hulp: to fetch only Unique yeeacls Instead of fetching upticare records Syade Nn SELEGr DISITNcT — Column_naee 1, Columa-2 --- FROM TABLENRME > Exanpl STUDENT Consider the STUDENT ifsreatssaicenc pL table haveg- following fine Comsinaition records “Ramesh | cee | anesh | seen Shreyo | ceen \tnuths ceen > Vow deus Use BrStENCE weytoord wettidhe, Serer Query Gad See Re Yasutrt= SELECT DISTINCT. COMBENATTON FROM STUDEN oRDER BY COMBENATION ; @ scanned with OKEN Scanner %) where Clause > Sar were Cloue % ay oh Ss Conctttvon white erlang “the clato. From Sinyte. 4oble or Joining with muitiple tables ze ’ sefiel then Only —> TE given Condon ts Samisted voards Speatic value from “the table You toute use Ulnere Clouse to Filter te records Uching Oly — Mecessary Teeerds cused fy to Spedly o we —scthe WHERE Clouse % Ree ONY Used M7 SELECT, UPDATE , DELETE Staremenr Che~ Syntav t- SELECr Column t, Columar -.., Column n from Table name WHERE Conckiion * Studs 1 . TAS REGno 1 | #86 Ene [2 84 Snehs | | Soee Sample Sete name, reqno , fees fom Stdenr ULHE RE vegno = HOG) ouspuk i : Reqwo | Nome [FG] Lise | Re « SQL AND Gnd OR Opernters Oe uses! to Combine Matttple Conditions Ctesed fo Cheek, muttipc Concktien) fn, SQL Statemer > There fore Catted HNO Gad OR Operators are Conjunttve Operaters Conjyunckive Ope D> AND 2 OR erasers 8a SQL DANOI- LF both the Gretttion are fue hen Se yetumy fue Walue. AND Operate % sed Sin WIRE Clause to Cheats muttiple Corctinens tr SQL Statement + Sinraz i= SELELC Columat, Coluenna «+ Colma Rom Tale name KIHERE CConcttion 2.3 AND CConcktieq2] . .AND [Cone Bent eet SELECT REGRO/ NAME FROM StuDENT WHER FEES’ < ISt00 ANDO CoMBINarron = POMC’! STUDENT | — ae et REGNo | Nem [Fees domarnatron | [eee NAM LOO | Vthan | 16000, 1 | i | tor \tbine Lot | Witch} Mowo) Peo = lor | Neaal 8000 Pemc | 103 | Yashu| tooo] CEBR ill Qubper tetole be Bee 1 OR _Oerater 1 The CR Sptrater %s user SeuDeNe oo Combtne mulkple Condition “in SQL Staremear . + TE Any one Conckiion % truce then T% Yeturns tue \eaue- [Constder .aeowe Input tobte] fei- SELECT Column! , Columns, - Where SY From Talble-name J Ceondsivor 1] OR CConchtiton 29:1. On Clonditig Ne] @ scanned with OKEN Scanner Colenn M i Reample !- SELECT Reso. name from Oey i Gineee | Page seca 6Cc, Cotes: Mo Dakotype fa SQL a ») NomBper cn Nam Cubpur — Fabl |Reane neue 7 Used 4p Store numete Value tq 0 Held Gluma oo | —> Te may be Deamal ,%nkeger Or eal Acimborrs - | cell ac General Syntax 1 Momeer Co, d) ceva + dhe 8 Spectre he 0 0f falas ctnd ‘Sl! oeper By CSorting he dora) Speadie the nundar of digits 4o nghr of whe. Uesoat potak Oxia Marks MuMBER C3) ele LOL, 28, Seo ee. Res eRa ==) ave Nomaer (2,3) ei 78-985 93-235 = The SQL OR! By clame % used to Sort Re dara aq ascending or clescentling ovdler- boxed on one |more Columns Systay- Se tect column Jest FROM Table-nare, VERE Caneition ORDER BY Columal , Columa2- Coleman (ascj CDESS ext Consicher the Studien table bowng she following yecordst- reo - | 2) CHae:- Used to Store a Character type , Sin @ Column - Syntax: CHaR Csrae) + Wlheve ‘Stae represents the maximum Cass choraue )} [Beano | ANE nundoer (Ob “Choracrers Aa 0 Column 1 ey name CHae CS); eats bindu, akash jute Ran eee ar rss ae BD VaRrcHar [varceer 2 '— — \ 493 nosh “ye as Used to Stor & Character Hype Gare 8a o} [vmoe | teneh | Column Alphanamete, Senar- VarcuneCsme) [varctner Csire)s ext dara, VarcharrCso} ek'- 32, sth cross , — > sder ~ fom Siudinr ORDERBY NAME SC; feegno ame | i “gonesh” —ayaate i 2 Te a Vos | gonuh ) Dare nga Soha | _. Te es tesecd Jo Store Clare tn Columns - URE, | exoesh | Ry Seontird ‘lare-tommat Sa Sau 4% PRz mehr {_teer | Ramesh exi- Saka t= dlob DATE ex w- 1S— May — Asoo as Selec _* fom Stucleer ORDER BY NAME DESC, PREGNo it | me DESC: Tot | Ramah | vigoy |) Mahesh) rau | ohn | | 1He3 gosh S)TEME:- Tr % used to Store Hm 20 columns. the Gtanclord time ~formar an SQL % fh-mm-ss Syoroe i= SWidy tte TIME: ey t- o1- 30-455 @ scanned with OKEN Scanner Pe} Longi- Te % Used to Stern Woven tie Srangs of Upto AGw Sire, Re Synrors- desert pon LONG Konstaker “the Ckantnation table :- _Repno | Mame [phy [che [rom | Cs [total tot | ojyay [so | as | 60 | a0) SS tor | Banu 6O | #0 | so | 60 | eto | 52-5 Structure of Sar Commands § 83 | Tarue |.ss .| ge, | 4g | ss|) 225 | se-2s = Any SQL Command % & Comrnarion of Keyes tome Gdw [eo | ao | as Go} a3s] sat: Tole fen anat Clouser I eat D COONT Euncioa: r Name £@om Student LIHERE 0 = Log Tre Query ceucer Prom, WHERE are Ky Syntax '- Selec CounrC*) from ‘Sect nase | 2 The tne query rituns! “EL OW « oT cares é > Mame Studer % 6 tablenome fe eee he Ccarenation eee tele — Commatey > Mame and regno ore the Colomns + ‘ > The equal ss Gn Operate, and IF As 2) AMGIO Punesion t= . Se doe Sanray :- Sever ava & fom ekaminasion > Here Select, From ore mandictay 40 ullece eagles clrplay & table. Dnd UlHERe I Spite —> The ee ee 2 ae Because Wt TS Used fo Schau “Perticalor Conclition - D> somo Syntax t= Setecr Sum Coby) Prom tkandnation | — The Aber que Yuumy :- O95 4) MaKo Syntay t- SQL. Functeons + VG ae retems average of IN, tprorog ni \ Ss. Cc 2runcnata, 2D Cowrty S Tr vetuwy no-of rows. deer mas Cosd from TRE above teeny Pettus 79 o> MIN C3 i- a MING STE + mrictmum vale of bo WH MAKO > * maximum 8 Sqnraxi- Cater min Ces) from Retures “Gum 04° waluees The aoe query reums SS @ scanned with OKEN Scanner 1 manjula | Mar Seaucement + GRove BY Syuex SELET Cotas, Columaz - -- Columns from —talole nome Cuthere Constetion J Spreaat Group by columaly Colusad 5 C Here table nome hema bangulon Stadhu | Mysore Morade beingatos Selearrowesiy Room location where tig Sywec- Salear name. ctty from location Group by OH; Ge SQL Combatants: Constreinrs y NoruLe Description Ensure thar ao Column Can't fore rut Necaderes, Crouves that wit value tm o column ome abefdevere dantqrety iclensdied eaeh row aa Clataloase table - uniquely tdeurfieal eaeh room “ia Or Offer dutabae table 7 2) ONTOvVE S) PEMA. tcer Wy Foreran. «ey BECRULET s)Deraucr Provides o chefautt value for a. Colemn when aon 4s Spedtieal © 5) CHECK Ensures thes OL value, 2 O Calama Stussty Cerrain Condition - VY NOT MULL Conthroaints 2 = = efoue Columa Cor hotel Mure volures Ba ahen & Column % Clefmnedt oy Nor NULL Then the column become mandatay Corn i ex t- Creare talole PRoover \ © peda td Waveho C16) Nor NULL it pace, Rumber C10.2) Nor NULL } Type char Cts). | Seal fe har Cte) Hen we: declived Rar Predurtd ang) price Column 04. 0 then ese Fed Colurnin foe becomes onandleutory Columns / Computsary Columns. @ scanned with OKEN Scanner Q)LNIAvE Constedas |= > Ths Conshatats enscere Same value wa the Spectre Conbazts appted fo fave the hue NO FOWS Columes - > UNTOVE that Columa ensures that ae YOU% have Re Same PIO value Create table Prout © pre cher Ca) uNtaue» Ayre Char CAD, price nunbe C5.) ° De 2) PRIMARY KEY Comharats: SA pimoykey 5 6 feted tokich Umiquely Glen Each vows ta & clarchaye toble —> By Pela He, Column ts Nor MOL Te debiaes the Colaren ay o Mmanotakony Colurnn ie, the columa can't be ett. blank - mothe Mara Adcl ta thes coltma mat be Cartque- ey CREATE TREE PRoODLLT © pry warchors Cio) PREMARY KEY Type Chor CH), Ma foee nurdoer (5.2) dy Constrotinrs = #) FORETGN —KEY > ® Forergn-Key % Used to tam, Heo table toguhe a Column whose Volte Cre sR FORETGN-KeYy %s PRIMARY KEY of Some devved form “the offer tale. | 6) CHECK Constrosets Cenc TRRLS FRacename PRODUET c PID Worcharr Co) PRIMARY KEY TYPE Char C4), pRrce — RUndarr Cs.2) >: CREME TARLE ComPANY Company-td char Co) primaykey - \archori C50), C prokite rp Varchar2 Coy > 5) Deravir Constraints | 5 The DEFROLT Consramss rwades O Ole foc vratue fo G Column. cohen the Ensen Faro Colum ownor Providt @ Speekfic value CREaTe TABLE PRODUCT . PID Char (to) PRIMARY KEY \axchar2 (10) , Prockurnome Price. Numb (Si2) DEFALUC Le80-60 3 Rete ased to establish « CHECK, Conttrotats We apptted to He Condon thar °5 sa a coltemn Adownot mreet the be placed *0 ke The TRvE [EAS dora placed = TE O value % Cannot condizan , Colamo . @ scanned with OKEN Scanner exr- CREME TABLE PROD C pro chart) + ame — warehor C1), Pesce naam (10.2) CHET Corere) A)TRRLE — Conshragnts :— <5 whun, a Combenenteucpsmedmpe © Ge od Columns of the —toble, te Ts Cufedk™ @ table — Consthagar . > TARE Conghetars Ore Clefened arte endk of she table ex:- CReare TREE TRRLENAME Ceeare TARE PROBLCT ( PIo char Ch) | Producrtype . Warchar2 Cod, escripton \corchar2(1S) Permeany Ke f i y key CTD, predudtype) ds SQL Toing: - >The SQU TIN are ULed 4to febehy [vecerve data from two or ero Holle, tycaged Onl Soin Conchitian cohich Is Spear MRERE Conehirion , Meg), tae SQL FOIN Tepes © TNNER JOIN TE Tetons yous cohen there a a math In noth terloles . webeens st rows Frome a LER TOTN = Te Jefe table , even % Reve Gre no marches tathe Rg he tabole. From the (3) BIg Tori Te returns all rows igui- Xabi, even Md hes Om 00 matches faq Re -heft- table. 4) Full Torn 32 Te returns YOUWs cohen there ts & Math tm One Gf the able. S) SELE Torw:- Tr ts Used to JOIN the tebe to Ftsut ©) CARTESTAN TOIN.— Er 7s Used to SEN Er vekums “the Cactestan Product of the Sets Oh records from THe “Heo or more “yoineat table. S CARTESTAN TOIN Feprtsents _ every You of One table Conneer sestth every Other” vous OF the, setate . ) pervitages AND R - 2 PMV lages!— Te clefines the Acces igh Provtded fo G Ceser on O clatabage objecr | swe Hype user to D> Sysvem Pyivilages:- hes cetlous the CREATE. PIER, Or DROB AArobare object = 2 Objur Pridlagest- Ans llousthe User to Cxecure , SELECT, TNSERT, UPDATE or revere dato Lom Clarabase Objects to which prvlage apply . @ scanned with OKEN Scanner

You might also like