Advanced SQL Tutorial | Stored Procedures + Use Cases

Поділитися
Вставка
  • Опубліковано 25 чер 2024
  • Take my Full MySQL Course Here: bit.ly/3tqOipr
    In today's Advanced SQL lesson we walk through how to use Stored Procedures.
    Link to SQL Code: github.com/AlexTheAnalyst/SQL...
    ____________________________________________
    SUBSCRIBE!
    Do you want to become a Data Analyst? That's what this channel is all about! My goal is to help you learn everything you need in order to start your career or even switch your career into Data Analytics. Be sure to subscribe to not miss out on any content!
    ____________________________________________
    RESOURCES:
    Coursera Courses:
    Google Data Analyst Certification: coursera.pxf.io/5bBd62
    Data Analysis with Python - coursera.pxf.io/BXY3Wy
    IBM Data Analysis Specialization - coursera.pxf.io/AoYOdR
    Tableau Data Visualization - coursera.pxf.io/MXYqaN
    Udemy Courses:
    Python for Data Analysis and Visualization- bit.ly/3hhX4LX
    Statistics for Data Science - bit.ly/37jqDbq
    SQL for Data Analysts (SSMS) - bit.ly/3fkqEij
    Tableau A-Z - bit.ly/385lYvN
    Please note I may earn a small commission for any purchase through these links - Thanks for supporting the channel!
    ____________________________________________
    SUPPORT MY CHANNEL - PATREON/MERCH
    Patreon Page - / alextheanalyst
    Alex The Analyst Shop - teespring.com/stores/alex-the-analyst-shop
    ____________________________________________
    Websites:
    GitHub: github.com/AlexTheAnalyst
    ____________________________________________
    All opinions or statements in this video are my own and do not reflect the opinion of the company I work for or have ever worked for

КОМЕНТАРІ • 188

  • @LukeBarousse
    @LukeBarousse 3 роки тому +223

    I like how you run the code (before it is fully complete) to show the error messages you expect and then show how to fix said error messages. This really helps with understanding SQL and helps with understanding troubleshooting code in the future. Keep up the content, Alex!

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +20

      So glad to hear that it's helpful! Thanks for watching! :D

  • @ContentRoomB
    @ContentRoomB Рік тому +84

    So far partition and stored procedures are the 2 videos that I found difficult. But I've learned a lot from this series. Thanks, Alex!

    • @chaayoub5360
      @chaayoub5360 Рік тому +6

      me too i didn't understand it

    • @blessedbay344
      @blessedbay344 Рік тому +7

      I thought I was the only one

    • @sheilawanindya
      @sheilawanindya 11 місяців тому +4

      same here and still try understand

    • @vasQpr2
      @vasQpr2 11 місяців тому +7

      Same, it’s comforting seeing other people who have the same struggle😅

    • @leksdic
      @leksdic 11 місяців тому +13

      Keep it in mind like a macro. Like with a macro you type a set of actions and save it under a name or button, stored procedures are like that but you save it only with name. When you want to do the same job again simply EXEC the name and it runs. The advanced step is to give it variables with @ and then it runs with the variables.

  • @colourNika
    @colourNika 10 місяців тому +23

    I was slightly struggling with it to follow along so here is the steps to actually get the same result:
    1) You write a stored procedure: drop table if exists, create table, inset into and select - finish with GO (you can also wrap the whole thing in: BEGIN (all queries) END
    2) Run what you wrote (all of it)
    3) Exec [store procedure name]
    4) Modify - add parameter
    5) Run the whole thing again ( I mean the modify query)
    6) Exec [store procedure name] [your parameter]

    • @yvemarie6514
      @yvemarie6514 5 місяців тому +2

      Thank you! I was really stuck on this query, and your comment saved me from struggling too badly.

    • @yanpaucon1043
      @yanpaucon1043 3 місяці тому

      Thank You 😘

    • @AutumnFairytale
      @AutumnFairytale 3 місяці тому

      Thank you!!!! Was seriously stuck and frustrated.

  • @ezehconfidenceadaeze6189
    @ezehconfidenceadaeze6189 10 місяців тому +5

    Thank you Alex. Your videos are literally the best. You came down to the beginners level and walked us from ground to top.

  • @romanvasiura6705
    @romanvasiura6705 Рік тому +12

    Cool. This lesson was much more harder than previous one.
    I'll check for myself what means "@" and other stuff.. Definitely I'll rewatch this video again.
    Thank you for this interesting lesson.

  • @maheshmagadi
    @maheshmagadi 3 роки тому +4

    Thank you very much Alex. Your videos are adding much values in my learnings.

  • @mathewsjoy8464
    @mathewsjoy8464 3 роки тому +3

    Please keep these style of videos coming,very insightful!

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +1

      So glad to hear that! Thanks for watching! :D

  • @sia_ibk
    @sia_ibk 3 роки тому +6

    This was more intense than the previous sessions.

  • @BigA3guy
    @BigA3guy 2 роки тому +1

    you explain this so easily. appreciate this!

  • @Tuuuuusssjjjjjjnrnfnnfnfn
    @Tuuuuusssjjjjjjnrnfnnfnfn 3 роки тому +7

    Best UA-cam channel for Data Analysts!!❤️🔥

  • @danielalcivar6395
    @danielalcivar6395 3 роки тому +17

    Thank you Alex, your content is so useful. I was waiting for your next advanced series. Do you think you could show how to make advanced triggers?

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +9

      Good idea! I'll look into that and see if I will add it to this series

  • @Mahshadn
    @Mahshadn 3 роки тому +1

    Great content Alex! Keep up the good work 👍

  • @ScorpusMugnes
    @ScorpusMugnes Рік тому

    this tutorial changed my mind am now on the real track for the progress thanks alex>>>

  • @edricnes5882
    @edricnes5882 Рік тому +1

    Superb explanation and content, keep it up Alex!

  • @LearnITskills
    @LearnITskills 3 роки тому +4

    Great video! I've worked with SQL a few times but I still got a lot to learn. This was very helpful!

  • @pahadianalyst
    @pahadianalyst 3 роки тому +1

    You are very 'on point'. Very precise

  • @anthonynkem
    @anthonynkem Рік тому +1

    Yes Alex, Nice work there!

  • @maximillianquaife-larsen3799
    @maximillianquaife-larsen3799 2 місяці тому

    Thank you I’ve been confused on this one for ages

  • @pablosalazar9978
    @pablosalazar9978 2 роки тому +1

    Super video ! Breve y muy práctico. Muy bien explicado. Muchas gracias !

  • @saltech2024
    @saltech2024 2 роки тому +1

    I subscribe straight along the way....
    Your tutorial is awesome

  • @creedroshan
    @creedroshan 2 роки тому +2

    I appreciate the fact that you used The Office names here

  • @reazulkabir6534
    @reazulkabir6534 6 місяців тому +1

    stored procedure is the most difficult one so far, but explained very well

  • @tech_and_wellbeing
    @tech_and_wellbeing Рік тому

    Your Tutorials are amazing

  • @Sthriven
    @Sthriven 3 роки тому +1

    Hey Alex, thank you for providing quality learning content for the community.

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому

      You're more than welcome! Thanks for watching!

  • @MehmetMustafaICER
    @MehmetMustafaICER 2 роки тому +1

    Thank you Alex, it was really a good content.

  • @tomilolaomowumi7156
    @tomilolaomowumi7156 Рік тому +1

    I am definitely rewatching over and over until I fully understand it

  • @janetl4221
    @janetl4221 3 роки тому +4

    Hi Alex, I am a huge fan of your channels. Recently I am looking for a job of data analyst.
    Could you please show us some behavior questions which might be asked frequently during the interview session.
    Again, thank you so much for your videos, it is really helpful to me.

  • @naveonleo
    @naveonleo 3 роки тому +5

    Hey Alex, Can you show us (a) how to compare two databases and their tables for gap analysis using Python -
    (b) and also how to compare text file data with table data using python assuming both have similar table structure...
    would appreciate your work and contribution for students and learners.

  • @mmusciano
    @mmusciano 2 роки тому +1

    Thank you very much Alex

  • @bijaydhm
    @bijaydhm Рік тому +3

    Thank you very much for your excellent tutorial video clips. I regularly watch these clips, and they are incredibly beneficial. I am new to the store procedure. Any help creating an SQL server store procedure connecting two servers would be highly appreciated.

  • @josephj1643
    @josephj1643 2 роки тому

    Seems more like how we write a function in python. Thanks for the video Alex.

  • @veronicab2096
    @veronicab2096 3 роки тому +4

    Great tutorial! I had never seen anyone using @ symbols in SQL code before so I wasn’t sure how it changed your code.

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +1

      Thank you! Yeah this was a fairly simple example of using that - it can get quite complicated! A good place to start though 👍

  • @user-ic4dn4el8d
    @user-ic4dn4el8d Рік тому

    I am following this series from beginning and now this is the first video that i find difficult to understand 😐 still learning....

  • @eastlhama
    @eastlhama Рік тому +1

    Love the database from The Office

  • @anupamnaidu8555
    @anupamnaidu8555 9 місяців тому

    Thanks buddy very informative

  • @alcarajo61
    @alcarajo61 6 місяців тому

    Hi Alex,
    Thank you so much for sharing all this info and Kudos for owning now your own educational SQL platform. O hope this content doesn't disapper!
    If i might give you my 2 cents. i think parameter should have his own video or maybe making this one longer with a specified section for parameters.
    Bye!

  • @vmdcortes
    @vmdcortes Рік тому

    Awesome! Thank you!

  • @nkunam
    @nkunam Рік тому

    Thank you Alex.

  • @yixinzhao7721
    @yixinzhao7721 3 роки тому +1

    Really cool!

  • @rajkumarpalle8217
    @rajkumarpalle8217 9 місяців тому

    It was nice video and easy to understand. Thank you so much

  • @FAWZAAAN
    @FAWZAAAN Рік тому

    Thanks. Nice explaination

  • @guilboy
    @guilboy 6 місяців тому

    Clear explanation 👏👏👏👏

  • @life.assistance
    @life.assistance 3 роки тому +1

    Thanks for this channel

  • @krishj8011
    @krishj8011 2 роки тому +1

    excellent tutorial...

  • @aaronl0387
    @aaronl0387 11 місяців тому +2

    Hey Alex great video! I was following along and wondered what the differences are when using Postgresql as I tried to run the stored procedure and it didnt work. So how would I be able to create a procedure temp table in postgre or would I just have to create a function instead?

  • @nwenweaung8516
    @nwenweaung8516 2 роки тому

    Thanks for sharing

  • @anthonyd9043
    @anthonyd9043 Рік тому

    Thanks Alex

  • @jahanzebkhan1716
    @jahanzebkhan1716 3 роки тому +1

    Please make video regarding difference between Stored procedures and views.

  • @nuhazainab4796
    @nuhazainab4796 2 роки тому

    Thank you 🙏

  • @princessnwofor8957
    @princessnwofor8957 2 роки тому +1

    Thank you for the video, i have a question;;;in 2.54 when trying to create a stored procedure for temp_employees, you did select * from #temp_employee, are you saying to create the procedure, we have to first add the select statement to the query or are we creating the table first then inserting the select statement before we then create the stored procedure?? sorry im just a bit confused and appreciate your response

  • @Thle009
    @Thle009 8 місяців тому

    Thank you for a very informative series. Regarding the Stored Procedure modification, how do you save the modification? Doesn't look like it auto save, and the save options will save the SQL form and not the procedure itself.

  • @thatguybryan6192
    @thatguybryan6192 9 місяців тому +1

    It's funny how most SQL tutorials I've encountered use the employee names from The Office haha

  • @zroburn3567
    @zroburn3567 Рік тому

    This has been an amazing tool to help fortify what I have already learned. My question would be what would cause the opposite to happen? I pulled the code from your GitHub, ran what you ran, and made the same changes. I did this under SQLTutorial instead of Master. Would that cause this to happen?

  • @saxenavedant61
    @saxenavedant61 Рік тому +1

    Thankyou🙏

  • @VizWithVictory
    @VizWithVictory Рік тому

    Thank you Alex... Could we get questions on SQL???

  • @hovardlee
    @hovardlee 3 роки тому

    You have to also notice potential parameter sniffing issues when you design your procedure.

  • @aaronwong5882
    @aaronwong5882 Рік тому

    Thank you so much for the tutorial. I really appreciate it. I have a question. After I add a parameter to the procedure and execute the procedure again, the result is the same as the procedure without a parameter. No error or warning. It seems that my parameter didn't come into effect. What should I do? Thank you!

  • @user-lj5et7zs1z
    @user-lj5et7zs1z 9 місяців тому +1

    You have not mentioned that after modifying the stored procedure we need to execute it in order to ensure the modified stored procedure is the one that runs when we do EXEC Test_Employee

  • @adrianbarisano
    @adrianbarisano 2 роки тому +1

    Great video! Could you make one explaining more in deep the Parameters in SQL?

  • @niklasmartinsson3719
    @niklasmartinsson3719 Рік тому

    Thank you so much, this video was very helpful. I think Stanley feels a little young however. 10/10

  • @yasfarfan
    @yasfarfan 3 роки тому +6

    Hi Alex, hope you are having a good time
    I have a question for you, I have found very helpful the store procedures but in a data analyst role do you think it is also important to learn how to create triggers and functions? thank you

    • @AlexTheAnalyst
      @AlexTheAnalyst  3 роки тому +4

      Depends on the role you have - in a previous role I was in I QA'd a lot of that stuff, but didn't write it a lot. Some won't ever touch it. Good to know in my opinion.

  • @abhisekgupta4678
    @abhisekgupta4678 4 місяці тому

    I tried relating it to a function how it takes arguments and you can use argument in the function block so whatever you pass as a parameter while calling the fn will replace the values in the function.

  • @awimbley1336
    @awimbley1336 Рік тому

    I will have to review and practice this one many times. I was asked in an interview if I wrote stored procedures. It was not something I did. Now I will practice based on what you have shown here. Also, how do you reference more than one parameter. Do you add another Where clause, use AND, ?????

  • @coder3123
    @coder3123 Рік тому

    I'm looking to optimize where clause using udt and if I can switch from using (not exists(select 1 from @param) or exists (select 1 from @param where value = mainqueryvalue)). Any suggestions?

  • @guneyfatma
    @guneyfatma 4 місяці тому

    Is semicolon required to seperate these two code blocks? I see examples with semicolons on the net.
    Also, on some websites, Go keyword is used at the end of stored procedure. It is also not a compulsory thing as I see.

  • @user-nn9ru4xh1c
    @user-nn9ru4xh1c 3 місяці тому +3

    When I try to insert value into #temp_employee it says invalid object name 2:33 .

  • @queensam6868
    @queensam6868 Рік тому +3

    Stored Procedures are somewhat complex. In what context would we need to use it?

  • @theabdulhaleemabass
    @theabdulhaleemabass 5 днів тому

    how did you do the refreshing?

  • @uchindamiphiri1381
    @uchindamiphiri1381 7 місяців тому

    this lesson is abit hard but i will gett through it

  • @TheTalkalotboy97
    @TheTalkalotboy97 Рік тому

    Will you be doing Triggers at all?

  • @rehamfakher9802
    @rehamfakher9802 Місяць тому

    what would happen if the parameter @jobtitle already has a default value like where jobtitle ='manager' then we excuuted the procedure like exce temp_employee @jobtitle = 'sales man' does it keep its old value or updates to the new one?
    thanks in advance

  • @user-ih7ot7vl8u
    @user-ih7ot7vl8u 7 місяців тому +1

    Do you have the data analyst courses in uedmy, please share it

  • @HP_Divinia
    @HP_Divinia 2 місяці тому

    Thank you for creating all these great tutorials. I have followed along with all of them and have learned a lot. However, in this video, when executing the following last line:
    EXEC Temp_Employee @JobTitle = 'Salesman'
    My results only showed the message (1 row affected)" without displaying the actual rows affected in the EXEC statement. Any thoughts as to why?
    Either way, your tutorials are excellent. They have propelled me further than the Google Analytics Certification program has in regards to SQL. Thank you once again for your invaluable resources!

  • @gauravkhalegaonkar9379
    @gauravkhalegaonkar9379 3 роки тому

    Thanks Alex for this tutorial. I just have one question: Why do you include the 'GO' statement at the end of the select statement in github code?

  • @JamesAndrewA
    @JamesAndrewA 3 роки тому +2

    Awesome as always! Do you have an open email for questions? I just wanted to know if this side project of mine was decent for a portfolio project. I checked out your discord, but I didn't know if that was an appropriate place to ask or get responses as I don't know the background of anyone responding. Or if I asked in your discord would you answer?

    • @JamesAndrewA
      @JamesAndrewA 3 роки тому +1

      Also a friend of mine who is at SWE at a big company said a lot of firms are moving away from stored procedures for hard coding. Is that true? I know you are planning on making some python courses, will that be covered? He doesn't explain things very clearly as he likes to sound super smart by being super technical when talking to me so I have really 0 idea why his claim might be true.

  • @rudeboy6285
    @rudeboy6285 Рік тому

    What the... this went a little faster than I expected. Lost track after you wanted to create the Temp_Employee 😅
    Time to rewatch

    • @rudeboy6285
      @rudeboy6285 Рік тому

      It took me a re-watch to understand. I just need to practice the alter procedures to understand it a little bit better 😄

  • @fc1984fc
    @fc1984fc Рік тому

    After you run the Temp_Employee stored procedure, where does the table #temp_employee get created? I can't see it under Tables in the db tree even after refreshing.

  • @aldrinpalcotilo4098
    @aldrinpalcotilo4098 Рік тому +1

    even i refresh the stored procedures there is no data appear in stored procedure where did the data go also i created another data temp _employee i cant see the data in stored procedures what shoud i do?

  • @Diabolicdreams13
    @Diabolicdreams13 3 роки тому +3

    Hey Alex !! Just wondering how insightful it would it be if you could post a video comparing the Google data Analytics Certification and the IBM data analyst certification

  • @avcrabna4004
    @avcrabna4004 3 роки тому

    H1! for someone who is looking for an entry level data analyst job and has recently finished python for everybody course on coursera , is IBM data analyst professional certificate course better or the GOOGLE data analyst course? please help

  • @jag7450
    @jag7450 10 місяців тому

    where can I find the #temp_employee table you created within the procedure? I could not find it anywhere

  • @karina3440
    @karina3440 Рік тому

    How could I do to alter the procedure using mysql? I didn't manage to adjust the syntax.

  • @juanmanuelarevalomadrid1937
    @juanmanuelarevalomadrid1937 4 місяці тому

    Hey Alex! there is any way to make other video with different example I know this is an advance video but I don't get it, is so confusing and frustrating. I feel all I did was copy and page and yeah I get the result but still lost with this, thank you

  • @muhamadhishyam750
    @muhamadhishyam750 7 місяців тому

    Hye guys, great video as always. I just wondering, why i can't find my stored procedure although i already refresh the 'Stored Procedure ' folder many times. Hope someone can help me. 🙏

  • @alwaysbemotivated2010
    @alwaysbemotivated2010 7 місяців тому

    Hi Alex, I am stacking in the initial creation of Procedure. Making error in the code when executing it.
    Its not validating to Employeedemography word, showing invalid

  • @louisefarrugia2787
    @louisefarrugia2787 3 місяці тому +1

    After modifying the temp_Employee i dont get an error it just shows me the info again. Am I missing something? I deleted and tried again multiple times. :(

  • @edimathomas-cr4km
    @edimathomas-cr4km Рік тому

    Great tutorial. Practicing this on azure and I keep getting this error: 'CREATE PROCEDURE' must be the only statement in the batch. I don't know what it means. Can anyone help?

  • @tinah426
    @tinah426 Рік тому +1

    Hello! When I create 'Stored Procedure', it is created in the Master Database, is there any way to stop this?

  • @maheshbiradar374
    @maheshbiradar374 3 роки тому

    Hello Mr.Alex,
    Please make videos on projects that make job seekers portfolio strong.

  • @sheilawanindya
    @sheilawanindya 11 місяців тому

    Hello. Can someone explain what '@' means? when, how and where Do we need to attached it? Thanks before.

  • @wizzard211
    @wizzard211 2 роки тому

    Difference between stored procedure and an SQL script? They both seem to have same purposes

  • @temiojuks5134
    @temiojuks5134 Рік тому

    I supplied an argument and when I ran it, it gave an error. When I tried to exec the procedure and I don't add the parameter it works.

  • @darrenjonathan3923
    @darrenjonathan3923 8 місяців тому

    deos anyone know why my procedure temp_employee appear in the master system database instead of in the SQLTutorial database?

  • @pinkly4532
    @pinkly4532 6 місяців тому

    Once modified, I execute the parameter query but I get an error that states that I 'Must declare scalar variable "@Salesman" ' . Can anybody help ?

  • @user-re4ip5ms9w
    @user-re4ip5ms9w 6 місяців тому

    When i modified mine and execute the Temp_Employee i didnt get the error message and im a dummy all i need to do is execute the modified procedure so and now its working

  • @mathathomanaka7108
    @mathathomanaka7108 2 місяці тому

    I was mid-training and i lost the training video threads for SSMS its only My SQL now, can anyone help with redirecting ?

  • @mathewsjoy8464
    @mathewsjoy8464 3 роки тому

    Can someone explain when to use MySQL and when to use SSMS

  • @jaibhagat7441
    @jaibhagat7441 6 місяців тому

    I think storage procedures are like functions in (c++,python,javascript) correct me if i am wrong.

  • @lshbySareena
    @lshbySareena Рік тому

    Where to add this. Actualy i didnt understand it.

  • @samuelraj5613
    @samuelraj5613 Рік тому

    Done