Sql query to delete from multiple tables

แชร์
ฝัง
  • เผยแพร่เมื่อ 22 ธ.ค. 2024

ความคิดเห็น • 121

  • @Stelios.Posantzis
    @Stelios.Posantzis 3 ปีที่แล้ว +6

    Best quick intro to references, referential integrity and cascading deletes for SQL beginners I've seen so far

  • @bruh-vp2we
    @bruh-vp2we ปีที่แล้ว

    Thank you very much, spent ages on the internet trying to find how to do this until I found your video on TH-cam, it was a lifesaver!

  • @shivShaktitech
    @shivShaktitech 3 ปีที่แล้ว +2

    Sir in this year's u had thought us sql big thanx for that, I have one request sir please release videos of no-sql for a change take it to next level.

  • @CRBarchager
    @CRBarchager 3 ปีที่แล้ว +2

    6:20 This is also a really dangerous query as it only tells you the affected rows in the Gender tables and don't tell you anything about the other 4 rows deleted from the Students and Teachers table.

  • @jan5310
    @jan5310 3 ปีที่แล้ว +4

    You could also make a before delete trigger using instead-of trigger on the parent table which deletes the child rows first.

  • @danieljust295
    @danieljust295 3 ปีที่แล้ว

    Very clear explanation with real case scenarios.

  • @jacksparrowcapitan3232
    @jacksparrowcapitan3232 3 ปีที่แล้ว +13

    As Many people asking please make more videos on SQL

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +4

      Hello Jack - Absolutely, please let me know if you have a specific question or a concept in mind that you want me to cover. All the very best with everything you are doing.

    • @simon-white
      @simon-white 3 ปีที่แล้ว +4

      Hi Venkat, I'd second this. Your SQL videos have been invaluable. I always direct others to them if there's a concept they need to learn.
      The main thing I was missing is more detail on the DBA side of things. Particularly difficult to find good information on design considerations for indexes - all the different types, when and why to use one over another, how many indexes to add to a table, how many columns to include in a single index, how to effectively test them, managing them in ETLs, maintenance etc.

    • @jacksparrowcapitan3232
      @jacksparrowcapitan3232 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspotHi Venkat, As you have covered most I see some topics on Normalisation like BCNF, 4F, 5F are left.
      This is just an example so if you can cover any leftover from the current list it helps a lot

    • @phanichaitanya8829
      @phanichaitanya8829 3 ปีที่แล้ว +2

      Please do video's on SSIS, SSAS nd SSRS in detail.

    • @statusking-nc5ug
      @statusking-nc5ug 3 ปีที่แล้ว

      Please do videos on ssis Ssrs ssas

  • @saedibrahim7391
    @saedibrahim7391 3 ปีที่แล้ว +1

    Thanks Sir, You always give perfect explanation.

  • @Akmabedinkadersafi-O
    @Akmabedinkadersafi-O 10 หลายเดือนก่อน

    Best channel, best vedios on every topic that i learned. Going to complete all videos and practice them😍

  • @hitendradeshmukh4043
    @hitendradeshmukh4043 3 ปีที่แล้ว

    Thank you sir. The way you tech and the way you explain the topic is awesome it's directly hit into the brain. Once again thanks sir 👏👏👏👏👏👏👏👏👏👏👏👏👏

  • @fin3125
    @fin3125 3 ปีที่แล้ว

    Based on your example is cascade delete faster if you are using FK? I am thinking it would not have to recheck the FK constraints again on the parent delete

  • @akashkhan6013
    @akashkhan6013 3 ปีที่แล้ว

    Which one you suggest? soft delete (isDeleted) or hard delete?
    Is there any method to track or retrieve deleted rows?

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +1

      Hi Akash - Good question. I always prefer soft delete over hard delete, just in case you need to undo the delete in future. Most data these days is soft deleted except where regulations doesn't allow that. If it's a hard delete, I don't think there is an easy way to recover deleted data.

    • @simon-white
      @simon-white 3 ปีที่แล้ว +2

      You could use an After Delete DML trigger to store the deleted records in an audit table, or just use a temporal table.

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +1

      Thank you Simon, yes, temporal table is a great option. Thank you for your time.

    • @akashkhan6013
      @akashkhan6013 3 ปีที่แล้ว +1

      Thanks both of you. 💕 I don't know about temporal table and DML trigger, but surely I'll do a research on them.

  • @kiranmr7804
    @kiranmr7804 3 ปีที่แล้ว

    Best ever tutor at TH-cam please share all in one video on asp.net n c#

  • @djjiang3718
    @djjiang3718 3 ปีที่แล้ว

    Thank you Venkat ! Good stuff as always !

  • @MrXyzAbcdQwerty
    @MrXyzAbcdQwerty 3 ปีที่แล้ว

    Hi Venkat, how about disabling the FK constraint(s); deleting the rows; and enabling the constraint(s)? Please advise.

  • @justkidding0212
    @justkidding0212 3 ปีที่แล้ว

    In your video @7:36 you are deleting the child records first and then the parent record, so why do you need to remove the FK first?

  • @benterrell9139
    @benterrell9139 3 ปีที่แล้ว

    Golden info for newbie like me. Marvelous

  • @padhujangam1761
    @padhujangam1761 3 ปีที่แล้ว

    Your teaching is awesomely understanding.

  • @mihirsheth3676
    @mihirsheth3676 2 ปีที่แล้ว

    Hello. Thanks for this video.
    But I am working with a huge database in which more than 30 tables are referencing the primary key of a table. In this case is there any alternate way of deleting entries from child table without writing explicit 30 delete commands for 30 child tables?

  • @dmitrikonnov922
    @dmitrikonnov922 3 ปีที่แล้ว

    Did I get it correctly, that cascading policy should be given when we create a table and is not changeable afterwards?

    • @chaddaifouche536
      @chaddaifouche536 3 ปีที่แล้ว

      Everything about a table can be changed afterward with an ALTER TABLE (as long as you don't create a conflict by this action). In fact this video showed how you could add the "ON DELETE CASCADE" by dropping the initial foreign key constraint then adding it back with a ON DELETE CASCADE specification.
      Of course for those kind of policy, it would probably be best if you thought about it beforehand and imposed it from the get go (you should modify your schema anyway).

    • @dmitrikonnov922
      @dmitrikonnov922 3 ปีที่แล้ว

      @@chaddaifouche536 Thank you so much for your response. I'll try it out right now.

  • @gag97
    @gag97 3 ปีที่แล้ว

    Wat if both primary and foriegn key on the same table i.e.. a primary code that will be a parent for another primary code...plz reply sir

  • @Techworldtutors
    @Techworldtutors 3 ปีที่แล้ว

    Hi sir, faced one question in interview like how to show only top 5 salary record in the result.
    They don't want top 5 command and something else they expected.
    Please help

    • @gagandeepgogna
      @gagandeepgogna 3 ปีที่แล้ว

      @sandeep kumar Please write "select salary from table order by salary desc limit 5;" I guess this should work

    • @Techworldtutors
      @Techworldtutors 3 ปีที่แล้ว

      @@gagandeepgogna thank you so much, will try this query

  • @shravyachannel559
    @shravyachannel559 2 ปีที่แล้ว

    Big thanks to you sir, miku possible aithe ee course ni Telugu lo upload cheyandi sir because non IT students,and Telugu medium students kosam videos cheyandi sir,vallaki enka easy ga avuthundhi sir.

  • @vkgupta
    @vkgupta 3 ปีที่แล้ว +1

    Awesome. Your video always gives good concept. Whenever I face confusion then I use to watch your videos.

    • @vkgupta
      @vkgupta 2 ปีที่แล้ว

      Hi Kudvenkat, someone doing Frodd with your name. Please reply

  • @Melodychoice601
    @Melodychoice601 3 ปีที่แล้ว

    thank you so much for such nice explanation. Finding it very usefull

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว

      You are very welcome and thank you very much for the feedback Abhiram. Means a lot. The following is the link our complete SQL Server tutorial. Hope you will find it useful.
      th-cam.com/play/PL08903FB7ACA1C2FB.html

  • @omkaaaar
    @omkaaaar 3 ปีที่แล้ว +1

    Great Video! Can I request you to make video on following features of SSMS 1) SQL Jobs 2) Profiler vs xevent profiler 3)Database Tuning Adviser
    Thanks 😊

  • @ENGFREEMAN
    @ENGFREEMAN 2 ปีที่แล้ว

    Many thanks sir, but can we do same action with access database? Or do you have any advice?
    Thanks and regards

  • @ChrisAthanas
    @ChrisAthanas 3 ปีที่แล้ว

    Great explanation and examples

  • @sriharshav9908
    @sriharshav9908 3 ปีที่แล้ว

    When a record from parent table is to be deleted... Can we update a default value to be updated for the columns in the child tables instead of deleting them?? Can you explain that if that's possible?

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +2

      Hi Sriharsha - Yes, the related records in the child table can be updated with default or null values. We discussed this in detail in our SQL Server tutorial. The following is the link to the video. Hope it helps.
      th-cam.com/video/ETepOVi7Xk8/w-d-xo.html

    • @sriharshav9908
      @sriharshav9908 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspot Thank you sir, that really helped...

  • @akashmurugesh3509
    @akashmurugesh3509 3 ปีที่แล้ว +1

    Hey there sir. Big fan of the works, would really appreciate if you could also teach us advanced sql server. Thank You

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว

      Hey Akash - Thank you very much for taking the time to provide feedback. Many of the advanced concepts are already covered in our SQL Server tutorial. The following is the link. Hope you will find it useful.
      th-cam.com/play/PL08903FB7ACA1C2FB.html
      Please let me know if you have a specific concept in your mind that you want me to explain. All the very best with everything you are doing.

    • @akashmurugesh3509
      @akashmurugesh3509 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspot Thank You sir

  • @raghavarora7734
    @raghavarora7734 3 ปีที่แล้ว +3

    Hi Sir, I love your content. Also, please make videos on SSIS.

    • @ManishKumar-qx1kh
      @ManishKumar-qx1kh 3 ปีที่แล้ว +1

      Please like his comment if u also want separate video on SSIS.

  • @jankichalise904
    @jankichalise904 8 หลายเดือนก่อน

    Awesome content. Keep posting content so that we can continue lerning :)

  • @ankithsimha9073
    @ankithsimha9073 3 ปีที่แล้ว +1

    Hi Venkat. How to find out number of weekends in given month. How we can do that? Thanks in advance

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว

      Great question Ankith. Was this asked in an interview? I will record a video and upload soon. Thank you for asking.

    • @ankithsimha9073
      @ankithsimha9073 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspot Thank you very much for response venkat. Yes in interview this was asked.

    • @nihar4713
      @nihar4713 3 ปีที่แล้ว

      You can loop through no of days in a month , then use IF DatePart(WEEKDAY,@Start_Date) = 1 or DatePart(WEEKDAY,@Start_Date) = 7 SET then increment counter @count=@count+1

  • @NONO-hz4vo
    @NONO-hz4vo 3 ปีที่แล้ว +2

    Removing FK constraints or enabling cascading deletes isn't really using a query to delete from multiple tables.
    The last example is more work than just deleting the data via multiple queries. I was hoping for a cool trick where you could use a delete force command or something. I don't want to spend more time to delete.

  • @imadabab
    @imadabab 3 ปีที่แล้ว

    Excellent video. Thanks a lot.

  • @saikatbanerjee5867
    @saikatbanerjee5867 3 ปีที่แล้ว

    Only one key from composite primary key as foreign key- is this possible in sql server?

  • @ravishankarreddy460
    @ravishankarreddy460 3 ปีที่แล้ว

    Hi Venkat,
    Can you please do a video on parameter sniffing and what is the best approach to solve parameter sniffing problem?

  • @sharbashisdas7603
    @sharbashisdas7603 3 ปีที่แล้ว

    Please make a video on Grouping sets and Roll Up function with multiple tables joined!
    Great video appreciate it!👍

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +1

      Hello Sharbashis - Grouping sets and roll up is discussed in our SQL tutorial for beginners course. Please check out videos from Part 101 to 105.
      csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html

  • @naveenakasapu
    @naveenakasapu 3 ปีที่แล้ว

    Hello Sir, every topic you cover is something Motivational to me. I have a question, suppose we have multiple duplicate entries in the table A with identity column and also have foreign key reference constant with table B having multiple duplicates inserted into table B. Now how to delete duplicate rows from both the tables without changing to cascade

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +1

      Hello Naveen - I think I understood your question. However, just to make sure I have got it correct, can you please email me the sample tables with data in excel to kudvenkat@gmail.com. I will try to record and upload a video as quickly as I can.

    • @naveenakasapu
      @naveenakasapu 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspot thank you sir, nice of you responded very quick, I will send all the details in an email.

  • @abdurrahmanhakim4612
    @abdurrahmanhakim4612 3 ปีที่แล้ว

    what if we want to delete master data but don't want to lose transaction data?is it possible?if not, what is your suggestion?

  • @techthings1986
    @techthings1986 3 ปีที่แล้ว

    It is specific to Microsoft SQL or applicable for oracle also??

  • @C300AMG
    @C300AMG 3 ปีที่แล้ว

    700 like from me and a sub, im starting to watch all your vids, gg for work 😊

  • @ecclesiastes2000
    @ecclesiastes2000 3 ปีที่แล้ว +1

    Why you didn't deleted the HR depatrment?

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +3

      Hahaha......no specific reason to be honest. Hope I did not offend you by deleting the IT department 😀

  • @mohammadanas4377
    @mohammadanas4377 3 ปีที่แล้ว +1

    Hi Vankat,
    Can you please make video on Temporal table

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว

      Hey Mohammad - Temporal Table is a great concept. Thank you for asking. Sure, I will record and upload very soon. Great question Mohammad.

    • @mohammadanas4377
      @mohammadanas4377 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspot thank you for the response

  • @jalaluddin1753
    @jalaluddin1753 3 ปีที่แล้ว +2

    How to write a query to display the most repeated value in a column?

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว +1

      Wow....Great question Jalal. I will record and upload a video as soon as I can. Thank you for asking. In the meantime, the following is the query.
      CREATE TABLE Students
      (
      NAME NVARCHAR(50)
      )
      GO
      INSERT INTO Students VALUES ('Sara')
      INSERT INTO Students VALUES ('Tom')
      INSERT INTO Students VALUES ('Mike')
      INSERT INTO Students VALUES ('Tom')
      GO
      SELECT TOP 1 NAME, COUNT(Name) AS Total
      FROM Students
      GROUP BY Name
      ORDER BY Total DESC
      -- If you just want the value use the SQL query below
      SELECT TOP 1 NAME
      FROM Students
      GROUP BY Name
      ORDER BY COUNT(Name) DESC

    • @jalaluddin1753
      @jalaluddin1753 3 ปีที่แล้ว

      @@Csharp-video-tutorialsBlogspot thank you soo much sir

  • @LuigiZambetti
    @LuigiZambetti 3 ปีที่แล้ว +1

    Anyone knows if exist some way to add intellisense code completion and auto-format T-SQL code in SQL Server Management Studio?

    • @clmhxll
      @clmhxll 3 ปีที่แล้ว

      If your willing to spend, try checking Red gate SQL Prompt. The best intellisense and TSQL formatter I've used so far.

  • @Kelmebrahtu
    @Kelmebrahtu 3 ปีที่แล้ว

    Hi Kudvenkat, I am a new to SQL SERVER and recently the msdb database is in suspect recovery mode and all the databases are in recovery pending and SQL AGENT is not visible on the instance.My challenge is I can’t solve the problem as the file path after the sql server upgrade from sql 2016 to sql2019 is not recoverable as I tried to rebuild the msdb database.I moved the msdb and renamed it to make it easier to rebuild the msdb but to no avail.Please if you can do a video on msdb suspect recovery mode.Thank you! Keep it up you already helping plenty of people like myself.
    Thank you in advance.

  • @gregorytaylor2749
    @gregorytaylor2749 3 ปีที่แล้ว

    Thank you very much sir for this excellent tutorial!

  • @raygan3
    @raygan3 3 ปีที่แล้ว

    Hey, can you record video about all kind of table joins (inner, outer, left)etc.

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว

      Hello Szymon - The joins are discussed in the following video. Hope this helps.
      th-cam.com/video/wW4xcQ3FFp4/w-d-xo.html

  • @AnilKumar-bd2yt
    @AnilKumar-bd2yt 3 ปีที่แล้ว +1

    Kudvenkat please post more sql related videos your sql server videos is awesome.

  • @devgupta1000
    @devgupta1000 3 ปีที่แล้ว

    Using a function in where condition can impact query performance. If you are playing with big data

  • @sasaman5416
    @sasaman5416 3 ปีที่แล้ว

    Thank you!

  • @AnilKumarP4U
    @AnilKumarP4U 3 ปีที่แล้ว

    I watch all your videos.. great content. Can you please make Azure Synapse Analytics series ?

  • @Ashish7041
    @Ashish7041 3 ปีที่แล้ว

    Great info. Thank you for this

  • @wamsampath
    @wamsampath 3 ปีที่แล้ว

    good explanation.. thanks sir..

  • @afzaalawan
    @afzaalawan 3 ปีที่แล้ว

    Excellent..

  • @Venkat640
    @Venkat640 3 ปีที่แล้ว

    Thank you sir,,

  • @geetsoneja4044
    @geetsoneja4044 3 ปีที่แล้ว

    Hi venkat could you pease make video on fill factor and table partition

  • @brijenderkumardogra7343
    @brijenderkumardogra7343 3 ปีที่แล้ว

    Thanks Bro.

  • @rockyabdul8524
    @rockyabdul8524 2 ปีที่แล้ว

    I have one doubt. Anyone can explain? He added constraint again. But where he took that constraint? Because drop constraint I could understand. But add constaint where he took?

  • @FelixNkongho
    @FelixNkongho ปีที่แล้ว

    Please I need a T-SQL script to delete multiple or all user databases in a server/instance

  • @missionit2822
    @missionit2822 3 ปีที่แล้ว

    Thanks for sharing

  • @dineshbabu1420
    @dineshbabu1420 2 ปีที่แล้ว

    While deleting tha large data log size is increasing even its in simple recovery any solution for how to limit the log size increasing??

  • @jalaluddin1753
    @jalaluddin1753 3 ปีที่แล้ว

    Please sir upload video on if absentees of a particular student greater than certain condition then automatically alert message sent to that student that you are going to be dissmiss ( as.net mvc , sql server)

  • @davidringo4672
    @davidringo4672 3 ปีที่แล้ว +13

    Oh wow, the organization must be seriously downsizing if they are deleting entire departments 😊 Good explanation though.

  • @learningislife2934
    @learningislife2934 3 ปีที่แล้ว

    I am big fan sir

  • @jalaluddin1753
    @jalaluddin1753 3 ปีที่แล้ว

    How to use sql view in asp.net mvc?

  • @MrAbueslam
    @MrAbueslam 3 ปีที่แล้ว

    dear sir, hur man send email to customer email when his subscription come near to ending, thanks

  • @mylifemrinmay4371
    @mylifemrinmay4371 10 หลายเดือนก่อน

    Thanks sir

  • @syedmujeebh4401
    @syedmujeebh4401 3 ปีที่แล้ว

    Assume I have 15 columns I need to exclude only two columns in select
    So writing 13 columns takes time and increase size of query
    How to make short and concise

    • @Csharp-video-tutorialsBlogspot
      @Csharp-video-tutorialsBlogspot  3 ปีที่แล้ว

      Hello Syedmujeeb - Good question. I don't think there is an easy way to specify an exclude list other than creating a view with the columns you want and selecting from it or using temp tables which is more tedious than just including the list of columns you want.

  • @manjunathbadiger57
    @manjunathbadiger57 3 ปีที่แล้ว

    Thanks

  • @sidieudelphin1685
    @sidieudelphin1685 3 ปีที่แล้ว +1

    Hi Kudvenkat. Thanks for the video. Can you please make a video to show how to insert into, select delete and update several one to many tables. For example a table student, teacher, address, phone and email. Both the teacher and the students can have several phone number email, phone and address. Thank you

  • @akhilramineni9129
    @akhilramineni9129 ปีที่แล้ว

    Hi Venkat can you make a videos on Snowflake Please with real time scenario's ? Please sir

  • @muhammadafzal237
    @muhammadafzal237 3 ปีที่แล้ว

    Nice video

  • @sravankumar1767
    @sravankumar1767 3 ปีที่แล้ว +1

    Nice explanation

  • @geesysbradbury3211
    @geesysbradbury3211 3 ปีที่แล้ว

    Misleading title - altering the foreign key (which you don't always have permission to do) is NOT an "sql query to delete from multiple tables" like you have in oracle...

  • @sbepari79
    @sbepari79 3 ปีที่แล้ว

    Can you please teach us asp boilerplate

  • @shariatishahed8115
    @shariatishahed8115 3 ปีที่แล้ว

    good

  • @siddharthapandey2711
    @siddharthapandey2711 3 ปีที่แล้ว

    Hi Sir, I'm a 31 Y.O. undergraduate and unable to get a job because of my graduation status. I'm an OCA with good SQL knowledge. I'm stuck with 20K salary for the past few years. I've learnt alot from you. Please help me.

    • @danieljust295
      @danieljust295 3 ปีที่แล้ว

      Why don’t you deliver dinners to IT companies and leave your business card in those companies, maybe someone will like your attitude and you will get better job.

  • @croydon21H
    @croydon21H 3 ปีที่แล้ว

    Not sure what the goal is? "I should be able to cascade delete"? If yes, then it means I don't care of the implications or best practices, but I simply love to delete anything that comes in the way :)

  • @sikendongol4208
    @sikendongol4208 3 ปีที่แล้ว

    Cascade Delete
    Child First then -> Parent

  • @mattyice3322
    @mattyice3322 3 ปีที่แล้ว

    anyone thinks the intro music has a Sopranos theme feel? Either way awesome

  • @MiningForPies
    @MiningForPies 3 ปีที่แล้ว

    Delete cascade is a terrible thing to be adding, especially on large databases. You give users the ability to wipe out data they might not want to.

  • @mr.RAND5584
    @mr.RAND5584 3 ปีที่แล้ว

    Gender its just M and F.