Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
53 views
SQL Hand Written
SQL hand written notes
Uploaded by
prudhvi30.etl
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SQL hand written For Later
Download
Save
Save SQL hand written For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
53 views
SQL Hand Written
SQL hand written notes
Uploaded by
prudhvi30.etl
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save SQL hand written For Later
Carousel Previous
Carousel Next
Save
Save SQL hand written For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 17
Search
Fullscreen
aruc war (uNKedin)- Nore l GAUERY (TELEGRAM). What is $0.9 we * SU IS stand for structured guery Janguage. * This database language is mainiy designed for maintaining the dara yelational database management Sysrerne. ° Sqh is Standard language fer Vecessing And Manipulating database. —Lypes_of S02 Cornmands: Dot Dew Teh. bara Derminen | | dave ryanipvanos!| | vara conneot | [reenzaction prea ial stan LANGUAGE PaNtgeh INSERT Geant UPDATE Revoke Devere Roresack SPVEPOINT ATUL 0 mMAR CLINKEDIN) ~DDL COMMANDS: Dor (Dara DeFinition Language) used fo change the Hructure oF the tobe I'ke creating tne foble, altering #he toble Deleting tne rosie. All phe Commands in the DBPL are auro Committed that means It permanentty saves ail the changet /n the darabase. 1. CREATE : this command jt usted fo create Q net. dafabare or tole. Syntax : CREATE TABLE robe. name ( Column datatype, column dararyre, Columns datatype , Is Example: CREATE TABLE Employee Employee/0 Int, Firstname varchar (255), lastalame varchar (255), Addretfhine Varchar (255), City Varchar (255)2 Alter fhe ALTER TABLE statements jn sfrudured Query Language allow yo add, modify , and delete Colurnns of an existing tagie « dSyntay : ALTER TABLE Cable-name ADO Column_name cararype Example: ALTER TABLE Employee AD Email larchar (255); GR ALL TTS LN TE 3- Drop TUL Km. INICED AL AIOTES GALLERY (TELEGRAM). Tre DroP Table statement ts used fo crop an exirting table jna databace. thif Command celetes both pne structure £ Kecorde sfored jn rable. fyntox: DROP TABLE rable name; Examele if DRoP TABLE Employee | emer rcremserncmeeNMSC SSA PEN ACSA NCPR TRREA EAR te 4. TRUNCATE A truncate SPL Starement it used fo vernove al) vows ( Cornplete dora) From a fable. it jy similar to DELETE Starernent With no PINERE clause. Continue —» ATuh eomar (Linneoir),a. Syntiye: TRUNCATE TABLE oble. name ; Exampie: TRUNCATE FABLE Emproyee } [oes Arh ele eet eae eee | DML _Commanps : 2 INSERT sa SOL INERT trarement it a SQL query It jg used 10 insert a single or a multiple verde ina table. Syntax: INLERT INTO ¢able_name values (valuet, valued, value 3..); Hampie: INERT TO STUDENTS (ROll_ AlO, NAME , AGE, CITY) vawwes (1, Yadnyesh 19 , Poné); | UPDATE. The OFDALE starement is Used ¢o modify the existing yewords jn a fable. Syntax? UPDATE Fable-name SET cojurnn] = Valuet, column 2 = = yalue 2,... IAIMERE Condition ; Continue —_, ATUL WIMOR [LINKEDIA ). CAb — EXampte: UPDATE Custpo meré ; ; iy SET confactiame = Yadu , city = Pune’ IAINERE CustomeriD = 1015 3-_Deceré The DELETE statement js used fo delete exketing rewrds In @ table. Somme Deere From tobie_name [WHekE condition] ; Example: ‘ ” DELETE FROY Cy stoners IAINERE CustormerNiame = yadu ANU aun ww). “AICTE S GALLERY [ FEL A 4 GRANT It i used fo give user gecess privileges to a databace. Syntax: GPRENT SELECT , UPDATE ON rMy_ TABLETO'SOME_ USER , ANOMER_ USER; 2 REVOKE Pris command wWithdraos the user't access privileges given by using the GRANT command. GRANT SELECT, UPDATE ON) My TABLE TO (OME_USER, ANOPHER_ USER} Syntox: Revo ELECT, UPDATE ON) MAY_. TABLE Peom USER! User 2; Larue kumar Cemceorn). Bi 4TCL Commands 4. Conmat Commit a Transaction. The Commit Command faves al) the transactions ¢o the databose Lince the lash COMMIT or ROLLBACK command. Syntax! COMMIT; Example: DELETE FROM grudent LINERE AGE = 20; Ceranir ; Sener TELGRULERY ( TELEGRA! TF any evrer eccurg with any of qhe LL grouped Sfaternents, all changes need fo be abosted. The process of reversing changes if called vollback. Lyntex: ROLLBACK ; Example : Devere FROM spudent WERE AGE = 20; ROLLBACK ; ATUL omar (eink EDIN). : &SQL SORT NOTES The S@L yeserved words and characters ave called operators, whith ave usted With a WHERE clause in @ ft query. [ere Name clats __|owwision | cry 10} VYadnytth toth 4 Pune 102 om loth c Mumbai 103 Sani} 10th D Pune [ey Ronan Jorn Bb Pune [les Atul tor A Deni | | Joe Yadav loth L e [Mumbai Student Informoarion Fable. | LS 1. _AND OPERATOR "ne S@L PND operator }$ used With tne Where clause jn the £92 Muery - AND operaror IN $42 yerurns enly gnose records wonrtch Satisty both the conditions In fhe £42 guery. Continue —> | aru roman (ommerra)—_ Guery 2 2 ” 5 i Sevecr *FRon gry dent Keke alame = Yadav “MriD City > ‘nfumbai"s Ontput > Koli-alo NAME CINsS Diusion city 1oé Yadav Jom c | Mumbai fn above example rhe sg) statement returns only one value cause in given g¢osle and thelr iy only one Stident Who has name "Yadav" f he belongs 4o mumbai. Note: Thue if all the conditions ceparared by AND Is True. . R 1b $< PR (LI KEDIAL, = ‘ OR OPERATOR. OPERATO ALOT ES ileRy (TELEGRAM). + Phis operator disploys rhe yewrds yohere either one of the conditions londitionl and Condition? evaluates 7o True. « The OR operator elispleys @ yewrd if any of the conditions Leparated by OR is Tyue- Query > SELECT * PROM student WERE Division 2"C "OR City = “petri” Ovtput> Roll-slo_| lame Class Dison city. jor om [oth C3 Mumbai 105" aque loth a Deni 106 Yadav loth c Numbai Continue —> LAruceomon(erniEDIN)- ye—<— Jn qne above example phe <9! ttaterjent returns phree values. Cause Given qoble have #wWo Sudentt tho belongs fo C Division one ts From Delhi. Alte: TRUE iF any of phe conditions separated by OR it TRve. 3. Between! OPERATOR: Poe Between operator In fa. shows pre record within the vange mentioned In the SOL query - The operator operttes on qe numbers, characters, and dare /¢ime operands. Query > evecT * EKO Student WHERE Roll_nlo BETWEEN Jo2 HxD 10uS wm PR [ LINKED Ial ). Outpur> Zoltato | alame Class Oinsion city. for Om loth a Mumbai | 103 JSQnil joth dD Pune 104 Renan jo B Pune.__| In phe above example ghe £4]
> Query : ELECT * PROM Grudent WIMERE CITY LiKe LUy.)s Aruc Komer [t Output: Alor ES GALLERY (TE ERAT, [eon lo Alame class Division! ary. | yor fadnyesh foth Pane foe on toh | rfumbal 103 Sant) lorh Pune toy _|_ Renan Joth Pune 106 Yadav Jor Mumba Bh Firsr Query yerurns all alame of Students starting from Y. In second Gyample yeturnfall the records t2ho have setond Letter 15 UV: ¢ren any Combination oF faster. 5-_Alot OPERATOR _ Alor operator jn SGL thowS those vetordt from che foble woneve he criteria hs not-met. Alot operator jr used with Where Clause in a SelecT query Query : Seuccr * From Students Were Nol city = “Mumbai”; Alame Class [ Dinsion! a i Yadnyesh Lahil Kohan erul eumak (LINKEDIA ).> in the above example yerurns Phose Ludent yetordst fhoste tno are not from mumbal. Pris query athows yewords of frudents Aaving city orher pnan Mumbai. 6+_IN OPERATOR kshen we want 7° chek for one oY Moye than One Value in @ Single JGL ery » 49e use IN Operator ith the WHERE clause ing f€teécr guery- 16 Keo MAR ( LINKEDIN, Oe Nee a —| i Query : Levecr ¥ Feo Srusents wunere city jl "Detni" Pune"); Outpur: [gon-alo | Name Class Dwsion | City. Jo} Vadnyes? Jot A | Fane 103 Sari) jor” Dd Fane 104 fonan ton & Pune a [ tos Atul fot Deini In the above example yerurn prose ffudent yewrdsS ¢hose who are From Delni and pune. other dhdent vill nor displayed:| SQL COMSTRaNTS SHORT MOTES PART -3 komen cinkeDi~) « AOTES GALLERY (TELEGRAM KEYS i DBM. A key it an Attyibure ov Set of attributes phat uniquely identities any yeecord ot ¢uple (one you) From the fable. DEémo_TagLe eme-ia Alame Adhas- no | Derr Id Jol Yadnyesh 2952 Y562 3221 ) lor vedgat 4334 2260 1220 2 103 ahi} 9525 21U) 3663 3 104 Rohan 9692 1258 745% 2 st 105 ahi) 19994 $214 3698 li i | 106 Siddharph | 1234 S678 9622 4 aul Kuma CLiINKEDIAD.O- Soper Key 2. Canclidate Kay 3). Primary Key 4). _Aiternare key 5). Boreign Key 6). Composite Key. 1. Super key P duper key iS @ combination of all possible attributes phat can unigely identify phe 7005 Cov peuple) in pre given relarion. 4 Soper key ig a Superset of 4 candidate Key: * & fete can have many Soper keys. eB * A Super key may hove addittone attribute that avé nor needed for unigue jdentity. Super Keys : From Empleyee Table (Fig//). 1. (Emp-is} { panar-noy { Dept_Id} { Gmp.is , Athar_no} & { Adhar_no, Dept.id} 6. { Gmp_id, Adhar_no, Dept. 1s} a { Emp-1d , Jame} & C Emp-id, Adhar.no, rlame , Dept.Id } ete.2 _Canaidate Key A Candioare ds an attribute ov 6 of an attribore Which can uniquely Identity @ tuple. A Candidare Key ‘tf @ minimes Seper key; or q Super Key with no redundant attributes. Candidate Keys are not allewed fo have Note values. dare Keys: from (A91-1). 1. {Emp_ ia} 2 {Adhar_ no} 3- {pept_ id} 3. Primary Key A Primary Key is one of dhe Candidate key choten by the database deslaner fo Uniquely Identify the fuples in the relation - ic eumne (LINKEDIN). E P The Value & prmary Key can never be aluec. > Me Jalue of primary Key must af ous be unique. > It define column is o mandatory Freld. 2 Primary Key do nor have supliicate value. > Primary kay 15 not compulsory bur recommended. Lriasy Kegs? From (679 1-1). 1. (émpe. Id }OU of all Candidate Keyl, only One get’ teletted as primary key , reraining Keys ave Known as Aternare Keys In the Employee cable : ° Emp.id Is best suited for Primary Kay ~ © Katt of the artrbures ike Adhar_no, Deptld are Considered as a altemare Keys. Altemete Kegs: Fyom (Fig 1) { Adhay_no} 2 Lept— is} 5° foreign Keys A Foreign key is: aaa Key ased fo link (00 fables fogether « * An attributes (or set of attributes) gn one fable pnat relers +o the primary Key. The purpose of qhe foreign key Is * fo ensure (or maintain) segerentlel integrity of tre clara. foselgn Kegs: Fyem (6251-1). 1 (Depts ,}_ATYe KOm, LINKEDIN ) « Aah sean POLE Ar Key ghat has more fhan one attyibeter fs known arg ComposHe Key. Ir }'s alre Known as Compound Key. ° A composite key can also be made by the combination of more ~rQn one Candidar key. ° A Composite Key Cannot be null. Composite Kays: From (£1911). ' {Dept-td, Emp- Id}
You might also like
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6127)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8215)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2923)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Tóibín
3.5/5 (2061)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2641)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2543)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Yes Please
From Everand
Yes Please
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel