You are on page 1of 1
Ss se) SQL KEYWORDS KEYWORDS DESCRIPTION ide 2 new coun a extn ate Example Aas new clare name ‘ADD fal patess aa named Uses ADD emat adres varchan255° SQL KEYWORDS KEYWORDS, DESCRIPTION Deletes atm trom aol Example Removes the fst name colar ROP fromine ur sale coLUMN [DROP COLUMN fret name areata anew consti on an exing tnt wits ope eater any Grain hetese ADD ‘anata ned neon es CONSTRAINT — | (Sana SuRNN (Osuna, ‘a, sts o ecole a ab Eenttsinte in al pa tbe ave Example Ais 2 em bolean etme DROP Example: Doles a atsses names DATABASE ‘webstesetn [DROP DATABASE webstesou: Remover a delat ale fora etn Example (MySQL) Revove the deta = satcton inane courant DEFAULT ALTER TASLE promt ‘ALTER COLUMN name DROP DEFAULT DROP acer Tabie | ALTER TABLE cen DROP Example: Removes re wer be D0 aerovs bola rap DROP TABLE urs Example 2 Deletes eros cnn Eanes ene [Checks for the existence of any record ALTER TABLE Gens ‘wn be sauna eon oF DROP COLUMN approved; ‘more records are returned Exampl: Ut y delete wih a el charges we ata pet ties carn ‘anes pecarge'cetnan Exerc infe ser biate ne sate alante eae ALTER: ‘column ‘incept_date’ into a datetime" type, Exists see a ‘coLumy ALTER TABLE wre ee naa ‘BHERE EXITS (SELECT del nae — ‘deals dealership_d AND finer Renens fate sey vale povensge «10; trate pasted canton Example: Rear ewes win a noner Spectacle sls dee a oneal waka han te tert he tm AU Soccer ample Selects data tem the user tbe SELECT fen pare, sure, 8,90 FROM SELECT aes anger Frou wer RM es manages WHERE aksno> ALL (SELECT tke WHERE STS SELECT Proucane Ft se ine dope = Fou regu uses area maagee ae, ranager AND Pca) sadn sop concions win viene nue ued ora a WHERE caveat 9 Sthendler mate OR conatcne Example Reus ever ccaeain {Satan Unies Rngoon Enact ‘AND SELECT * FROM users, SELECT FROM evens WHERE country = 'USA’ OR county = HERE rox cou Unis Kon iw Unt rg OR ‘hb noon conon county = Rusa OR cain =A neslnegrenciatcns SELECT Frontiers ‘BHERE county (USA. Unted prodoes tober hove econed eodoat, Mugu. Wat ay teva canto more as 8 didnew stole SELECT nae Example anon voce FROM products MSERTINTO INSERT INTO cars (make, model, toe, yen VALUES had MERE produc « any eLECT Soon 28) Soded FROM ordre VNERE Gy > “etter emety NULL vues rare ntact ana, Example: Rear vers tathavert gen “a smu Soom noe: eee am fexcor rou subscrptons column {WHERE contat_number IS NULL: as ‘SELECT north_east_user_subscriptions: Bonnie “The reverse of NULL Tests for values nat a IS NOT NULL ieaae enue FROM tor frentemety/ Hu rete Used with ORDER BY to retum the data in b-congocser dcr grace tei spiae uke ‘Sate eae win no ase Example Apples Bananas, Peaches, eee ee roca "WHERE fre rane UKE ion Ssh nore ft crema Runs tue 2 ect DOESNT moet e Example Selects sc wih rity Conanon ‘erwoon 100 805 160 Example: Retums tue # the user's SELECT" FROM sot Nor ‘exe sue end wis WHERE quantiy BETWEEN 100 AND 150, cerneitbimanaen amples nieve ‘WHERE fst name HOT LIE so! BETWEEN NOT between 100 and 150. Altematively, tage Not Kyworshre meres he Used ari WHERE in aa tage ad eau vue oie ne sh ‘wonear conto swe Lc (Example: Retums users thet live in either SELECT" FROM tt or Setar archos WHERE quanity NOT BETWEEN 100. SELECT * FROM users aN ‘HERE cy = ‘healt OR Manchest ramet een aetna ‘Used to sort the result data in ascending Sueen (@efault) or descending order thecugh the: Example 1:Retuens users and their OS PO sameibes sera neato ORDER BY | Example Ree tian nats ‘pane aed on he naar ot Nterpion, SELECT" FROM counties SELECT fs pare, une, ORDER BY name serpin case CASE WHEN stereo 107168 ‘etree whee ow unber See frets tho passed coaon Example: Retin te op counties, OMEN cust SETWEEN 94ND 19 wien ou RoWNUM — | fom'hevounon ie, SELECT FROM cous ELSE ive WHERE ROWNUM C= 10, ENDS att ele tee Used jo select dais from a dasbase, which ts constant ats eva whch xanole: Sect of columns fom al Example 1dySQL): Makes ste any users ‘SELECT SELECT * FROM users; CREATE TABLE wer, timane caine tom ee ee ae vena) SELECT a sre, sumer FROM ues ccomce seein eae SarsanEL€0r cep gn vans : ‘SELECT Example Creates a backup table using example ysl} Asa nec ater sree conan oor wo beable as en oren ete SELECT NTO uteeBaca2020 ALTER ABLE were Cope ana rom one unl ana wae t Crates & new cis tania SREATE, | exam tnysaty crass snow SELECTINTO | Example Fe coun ton te Sntecase rnd eos ‘Cwhich would be highly key), (CREATE ATHERRE anions ‘SELECT DISTINCT country from users; nari ‘Allows you to return a set number of Seen eteeee deen ‘SELECT TOP ‘Example: Returns the top 3 cars from the (CREATE TABLE user CREATE . nee fret name varena 255), name vara), eres varchar, » Sete atau value fora calunns Example ySQL} Crees anew table Eales Posie win naa nar cans coat vas of ayaa (CREATE TABLE produce rae vachr(255) DEFAULT Placenlse: vail Yom date DEFAULT GETOATEN) » Example 2MySAL} Tho eam 35250, ALTER nara SET DEFAULT Placatoter ALTER aatable from SET OEFAULT (ETOATEN: DEFAULT Example: Removes user wt 3 ueer6 DELETE sen DELETE FROW wees WHERE user = Usa ni ORDER BY a eur etn sescending ter Example: Rassin, Peaches, Baranse, oss Desc SELECT TOP FROM cat sed alongside UPDATE update existing aimin sie ample: Unite teal nd guty seT ser ble SET value = 1849, cuniy =? ‘SOME leertalto ANY Used alongside SELECT tort 2 et Tor Example, Retiree Ses tone SELECT TOP 5* FROM veers ‘Simiarto DROP be and of eng he fae snare, he ates ony heat TRUNCATE, Example: Epis the seston bl, ut TABLE Tobie the ble oat nt TRUNCATE TABLE sssons Comics he eats rom 2 rere SELECT sistent andre oly disinct ace Example Reus the ies em he eens UNION Sra aubecrbore ole. SELECT FROM events NIN SELECT et tom subserba UNION ALL, Toca os UNION nen cite Example MySOL): Aa urigue fanerart tothe Slur wen est & few ures ble ratnnor NULL, UNIQUE ene vecha(25) NOT NULL, ‘uwaue » Example 2(MySaL}. Anos on exsin9 ‘elon toda UNIQUE cans ALTER TASLE wees ADD UNIQUE Uae eit dan stabi Example: Udates he mieage ad cove Due valves fora vote wih an uenaTE POATE cre ‘SET mileage = 7950, serdcedue = @ sed alae ho INSERT INTO koywors Example: Ms anew caro the eae ane ‘SET mileage = 28500, sensoedue = 8 INSERT INTO crs rae, motel. ye) VALUES VALUES (Fou Fens, 201) tars results ony etude data nen rose akon eoneion Example: Ret oer wit que WHERE cima em ” HERE quay > 1 COMMENTS Ee Ta =a eres au eau Ta a =Rere UALS) tne erd ot nolne wi be ones SELECT FROM users mle nes uml re closing characters nave been Found Myatt ows of deta am he users aie SELECT* FROW users: ‘Tie apoer sleet query. heh dent SELECT FROM tests merce CREATE TABLE users Fes pame varchan255) a STRING DATA TYPES NUMERIC DATA TYPES DATA TYPE DESCRIPTION Feng sing which an conan Isr, uber ane special eharacors CHAR(SIZE) The sze pacar sas re manu singing fem 255 ae eos ‘vast engi tng aro CHAR, VARGHAR(SIZE) | Nwihamoiminsing lobe BINARY{SIZe) | Sis OHRONAHW Eran Be DATA TYPE DESCRIPTION ome) | Soe nsger win a signed range of ‘S280 17, snsan inlgoed ange oOo TWwyINT(Si26) 25 ee Hae sane scte te BOOLEAN Sane a2 800 VARCHAR(SIZE) | Slr ®C1HHO ms Hae bran me elds snany Large Otte L085) win TNYBLOB: masengh of 236 bya. ‘ets 9 sing win aman eat TINYTEXT 25senaraces Use VARCHAR mstend Seite totes much tse TEXT(size) Essien Ann tte aoainy | SaRlnara Holds anay Large Objects 61085) wih MEDIUMBLOB —Snauiengh of to 777 215 yee tonetext | USsigerise cnc LONGBLOB | Sacinghert ieee 8b ‘Astong object nat ony nas on vale ouefae upto a rant a 65535 ineead Thnk ENUM berg smiar ‘STU rado ones ni ope (CREATE TABLE seis (clr ENUM re ‘fer byl‘) ‘Ase tt at san hve re set ater sch yosetne pion fine d Tatininat deans fk ET (4, DecvetGu) Sra smarto iT exeosons ‘mth repe YN Ti ty Unda =) DATA TYPE DESCRIPTION ‘Astrpe ate ¥YYYAIN-D0 forma, with DATE, Siapere ano tonsToasot ore Agate gn YYYENILDD nhs fomat wh supported ange rom DATETIME(fsp) | 7559 2 stsng DEFAULT and ON UPDATE t ‘AU Timestamp, wien is a ote {he Unt epoc 1970.01.01 0b0900 UTC) Tue ae suppores range rem “gret-o1 000001 UTE t 2008-0708 TIMESTAMP(fsp) 21407 UTE by aacng DEFAULT Chasen TIMESTAMP ana OM UpDATE CURRENT MMESTANE othe ‘coum detokion Neutmatcaly 2 Avis inhimmess format ath 3 TIME(Isp) ‘expen ane am S080 Ts ‘yea nrpoed enact 101 to ‘Asma nage wih a signad ange of {2768 2767 andan anagned range SMALLINT(size) | ford "358 Few Bee aera -Amecian teger win sane range of MEDIUMINT(size) ‘sien 677215 Hee sue ‘Aredia teger wih gre range of InTisize) sel arge ono 42a, Imocmum slows sepa wish whe Br INTEGER(size) Same 1 -Arecian teger win sane range of Seana 20%005e77 007 and an wsigied BIGINT(sizey fargo rom o wiaucsrursvouseneTs mmaxinum alowed copay with wich ease, ‘Aoning pont nner aie be Pocaan oye ntaeer 01034 FLOAT) Brom ssisenecas yest BOUBLED tu behest he ‘gfe ae ser there paraeter ae he rumor aig ator he aeomal p's fey be spare DOUBLE(size, a) ‘An raced pont rubor vere the ‘ots mmtarotagte etsy ease \urmesooma pansy ned DECIMAL(size, 4) foram DECIsze, d) Samo as DECIMAL OPERATORS ONS sien oda =yestkea) Ec kee) OPERATOR DESCRIPTION OPERATOR DESCRIPTION + aaa a Baise AND zi ‘uttect 1 Braise OR . uty a Braise excuse OF 1 oie % Moto Cole rel Nel Ue) OPERATOR DESCRIPTION | = restr than or eal © Brwiso AND equate Braise OR on FUNCTIONS STRING FUNCTIONS Palette easly} DATA TYPE. DESCRIPTION DATA TYPE. DESCRIPTION psc | Sngesesnmescnamea as | mrtednaermstioon ee eo | Neen darm aif hn ie CHARACTER — LENGTH Sere oo CHAR LENO ASIN [Retums the arc sine of the given number. (Aisne oe arom concer | at an | Ragepenee azo concar.ws | Stszmnuns tes nwene ns eee ae FIELD ‘postion of 4 value within alist of values, ~_ EXTRACT Nonmmersoeio-oy a cinene eumaraber vate FROMDAYS | Tate HOUR anne tne exression sit, ou tare HOUR atu se ho tom given ct. ‘eum Last Day Set lsiay ot te mnt tne given LASTINSERT ID | tines stabs eur thes LOCALTIME Ge he crertios date ante LOCALTIMESTAMP Sones Locairme Compares he? pen expressions they NULUIF sree NULL ees ote Re MAKEDATE | Crsase3 date and tums basa onthe Sonyearendnunborot ape wes SESSION_USER | Retin ne curetuseranshosinanes MICROSECOND eum meosecond ta gente or SYSTEM_USER | sane assession_user mare tyra mnt han mer VERSION Saas me carmen cre meat MonTH etimaihe month he en dae eer) MONTHNAME —Seboe smectite mn ie gin RARE BEECHIETION uae treo or more characters Now Saree LOGALTIME Example: Fda vas wn sunanes frag non PERIOD_ADD Ate aNen pander manteio He SELECT FROM utes * WHERE svar LIKE aon PERIOD_DIFF __shmetne arn between 2avn Example 2 Fal ve wth smanes por ssa non SELECT FROM uees QUARTER | Retineine yur quarto gn te HERE cty LIKE Sane euuna in aso of gen tine or SECOND one Eines oan nie character Example Fina vers gin SEC_TO_TIME | ®etimestinebseesontneghen scons. . Scorn wih a3 cha cowety SELECT? FROM uses STR_TO_DATE | Civses ate anreturetbated on te WHERE ety LIKE” _obeter SUBDATE Same a4 ATE SUB ‘uote ie ent (69 0200) 8 ‘SUBTIME tine or dletme (05 00] and ru he Share SYSDATE ‘Same a8 LOCALTINE me mura ae am aon tet TIME_FORMAT —Reumstte gvensne nine aventomat TIME_TO_SEC | Conves and ros atime ino seconds TREC Retina ihe ference been 2 gen TMESTAMP Sens om dire vi the gwen TODAYS paseo rm'0D 00-0000 tte gon eae WEEK Returs he week number forthe gen date atu he waka unas fore geen WeeKoay ine WEEKOFYEAR | Retire ine week number fr gen date YEAR eka yearfrom he gen te YeARWeEK Sergeant vaeumtertrie [Eguai to ay singe character inh et. begonea wind Hort SELECT? FROM users, WHERE fet name LIKE Uh Example 2 Fins a users wih fst ames (chapisT) baginag etre between SELECT“ FROM user smeLiKE Tob! Example3. Fda users wi tat an re LKE Maa}: KEYS FOREIGN KEY CESSES comers sonsan eh Conaicate Koy int Oe) tosname varchar a int sel Foreign Key nt erat varchar rosucl it (Foragn Koy nt Sond agent bgoed Sit (CREATE TABLE order PRIMARY KEY a), FOREIGN KEY (ser) REFERENCES use, FOREIGN KEY (product) REFERENCES prosucisi » EXAMPLE 2 (MYSQL) PRODUCTS ‘ADD FOREIGN KEY (oH) REFERENCES sere id Candidate Key int sesenpton te stock sunt wt Pree oat En PRIMARY KEY EXAMPLE 4 (MYSQL) EXAMPLE 2 (MYSQL) CREATE TABLE wer AcTeR TAL wee ‘ne NOT NULLAUTO, NOREMENT 00 PRIMARY KEY nan etna arena 25), lastname varchar28s) NOT NULL rss varcha255) oma vrenazs). PRIMARY KEY (a) x Peeters) VIEWS DATA TYPE. DESCRIPTION (CREATING VIEWS: CREATE — cess INDEX ‘ACTER TARE une, DELETING VIEWS (BRR mOr Ae som DROP VIEW priority_users; Blo) ST) ORDERS INNER JOIN LEFT JOIN id first_name Lastname address | email ~¢@-: @- : SS F mee eee | one somon snaom WS|ZEi = @® ap me | sem sense mn ve | ome | oem |mrmine im | on ORDERS : ‘ne ‘ eo | om | 1 : 7 : ‘i ee = 1d name dssroton | stack sount pee oD : on 9 | ont |e ' | 20 yee || aol ener | a or | tamon |e ° | ae sa ras | | orm | ty ° wo a | J = | 1 | ae 2 | fm we mess | yee . | 20 sr | tamoe | mm | ” | aw a ‘SELECT orders, uso feta, users sumame produ name 3 INNERLION vers on ose ute = wees INNER.JOIN posits on odes product = product DN sae ass eS ae 4d firstname, sumame | product name 2 cae | ‘sro rae. 7 | sev] =| ee ee dl

You might also like