Sql Server delete syntaxRestoring SQL Server databases - tips and tricks?SQL Server — optimization techniques for rebuilding very large tableMySQL Large DELETE with JOINsSQL Server 2008R2 Migration to new Platform - What Steps Required?How to group SQL Server files for restoring databaseUser-shared queries: Dynamic SQL vs. SQLCMDOrphan records after delete statement in stored procedureSQL Server 2012 Import Wizard appending new data onlyMigrate on-premise SQL Server databases to Azure SQL DatabaseThe MS documentation on FILESTREAM makes it sound like it should only be used for archiving unstructured data. Am I misunderstanding this?

The origin of the Russian proverb about two hares

Live action TV show where High school Kids go into the virtual world and have to clear levels

Java Servlet & JSP simple login

If a Variant Human is Reincarnated, would they lose the feat and skill proficiency they started with?

tabular: caption and align problem

Russian word for a male zebra

How to safely destroy (a large quantity of) valid checks?

Smart-expansion of a range to a list of numbers

Electricity free spaceship

Are polynomials with the same roots identical?

What is the color of artificial intelligence?

Increase speed altering column on large table to NON NULL

If there's something that implicates the president why is there then a national security issue? (John Dowd)

Amplitude of a crest and trough in a sound wave?

The usage of kelvin in formulas

What would be the way to say "just saying" in German? (Not the literal translation)

Is Lambda Calculus purely syntactic?

Why did Intel abandon unified CPU cache?

Ability To Change Root User Password (Vulnerability?)

Separate SPI data

Grep Match and extract

Did Apple bundle a specific monitor with the Apple II+ for schools?

Has there been a multiethnic Star Trek character?

I've been given a project I can't complete, what should I do?



Sql Server delete syntax


Restoring SQL Server databases - tips and tricks?SQL Server — optimization techniques for rebuilding very large tableMySQL Large DELETE with JOINsSQL Server 2008R2 Migration to new Platform - What Steps Required?How to group SQL Server files for restoring databaseUser-shared queries: Dynamic SQL vs. SQLCMDOrphan records after delete statement in stored procedureSQL Server 2012 Import Wizard appending new data onlyMigrate on-premise SQL Server databases to Azure SQL DatabaseThe MS documentation on FILESTREAM makes it sound like it should only be used for archiving unstructured data. Am I misunderstanding this?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I recently faced a delete syntax I was unaware of.



delete #fooTbl from #fooTbl where attr ='some'


The Official Microsoft documentation states:



DELETE FROM [database_name . [ schema ] . | schema. ] table_name 
[ WHERE <search_condition> ]
[ OPTION ( <query_options> [ ,...n ] ) ]
[; ]


i have some perplexity about the command I wrote:



  • What is and what is needed that parameter before the delete keyword (In my example coincides with table name)?

  • What is the best practice?









share|improve this question




























    2















    I recently faced a delete syntax I was unaware of.



    delete #fooTbl from #fooTbl where attr ='some'


    The Official Microsoft documentation states:



    DELETE FROM [database_name . [ schema ] . | schema. ] table_name 
    [ WHERE <search_condition> ]
    [ OPTION ( <query_options> [ ,...n ] ) ]
    [; ]


    i have some perplexity about the command I wrote:



    • What is and what is needed that parameter before the delete keyword (In my example coincides with table name)?

    • What is the best practice?









    share|improve this question
























      2












      2








      2








      I recently faced a delete syntax I was unaware of.



      delete #fooTbl from #fooTbl where attr ='some'


      The Official Microsoft documentation states:



      DELETE FROM [database_name . [ schema ] . | schema. ] table_name 
      [ WHERE <search_condition> ]
      [ OPTION ( <query_options> [ ,...n ] ) ]
      [; ]


      i have some perplexity about the command I wrote:



      • What is and what is needed that parameter before the delete keyword (In my example coincides with table name)?

      • What is the best practice?









      share|improve this question














      I recently faced a delete syntax I was unaware of.



      delete #fooTbl from #fooTbl where attr ='some'


      The Official Microsoft documentation states:



      DELETE FROM [database_name . [ schema ] . | schema. ] table_name 
      [ WHERE <search_condition> ]
      [ OPTION ( <query_options> [ ,...n ] ) ]
      [; ]


      i have some perplexity about the command I wrote:



      • What is and what is needed that parameter before the delete keyword (In my example coincides with table name)?

      • What is the best practice?






      sql-server t-sql delete






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 8 hours ago









      s.demuros.demuro

      594




      594




















          1 Answer
          1






          active

          oldest

          votes


















          2















          What is and what is needed that parameter before the delete keyword
          (In my example coincides with table name)?




          Referencing the table is a possibility due to the fact that you could DELETE FROM with an INNER JOIN.



          A simple example of deleting from #footbl with an inner join to a different table



          DELETE FT
          FROM
          #DifferentTable DT
          INNER JOIN #fooTbl FT
          ON DT.attr = FT.attr
          WHERE FT.attr ='some';


          Whereas this generates an error due to not specifying what table to delete from



          DELETE 
          FROM #DifferentTable AS DT
          INNER JOIN #fooTbl AS FT
          ON DT.attr = FT.attr
          WHERE FT.attr ='some';



          Msg 156, Level 15, State 1, Line 45 Incorrect syntax near the keyword
          'AS'.




          And this also works



          DELETE #fooTbl
          FROM #DifferentTable AS DT
          INNER JOIN #fooTbl AS FT
          ON DT.attr = FT.attr
          WHERE FT.attr ='some';


          In short, you need to specify the alias/table to delete from if you are referencing multiple tables, but you don't have to when you only reference the one.




          What is the best practice?




          In terms of best practice I don't think that it matters much for the single table. Aliasses can be useful as to make adapting / reusing scripts easier.




          Some more examples in the Microsoft documentation



          D. Using joins and subqueries to data in one table to delete rows in another table



          Using the table name twice



          DELETE FROM Sales.SalesPersonQuotaHistory 
          FROM Sales.SalesPersonQuotaHistory AS spqh
          INNER JOIN Sales.SalesPerson AS sp
          ON spqh.BusinessEntityID = sp.BusinessEntityID
          WHERE sp.SalesYTD > 2500000.00;


          Using an alias



          DELETE spqh 
          FROM
          Sales.SalesPersonQuotaHistory AS spqh
          INNER JOIN Sales.SalesPerson AS sp
          ON spqh.BusinessEntityID = sp.BusinessEntityID
          WHERE sp.SalesYTD > 2500000.00;


          Both serving the exact same purpose.






          share|improve this answer

























            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "182"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f240135%2fsql-server-delete-syntax%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            2















            What is and what is needed that parameter before the delete keyword
            (In my example coincides with table name)?




            Referencing the table is a possibility due to the fact that you could DELETE FROM with an INNER JOIN.



            A simple example of deleting from #footbl with an inner join to a different table



            DELETE FT
            FROM
            #DifferentTable DT
            INNER JOIN #fooTbl FT
            ON DT.attr = FT.attr
            WHERE FT.attr ='some';


            Whereas this generates an error due to not specifying what table to delete from



            DELETE 
            FROM #DifferentTable AS DT
            INNER JOIN #fooTbl AS FT
            ON DT.attr = FT.attr
            WHERE FT.attr ='some';



            Msg 156, Level 15, State 1, Line 45 Incorrect syntax near the keyword
            'AS'.




            And this also works



            DELETE #fooTbl
            FROM #DifferentTable AS DT
            INNER JOIN #fooTbl AS FT
            ON DT.attr = FT.attr
            WHERE FT.attr ='some';


            In short, you need to specify the alias/table to delete from if you are referencing multiple tables, but you don't have to when you only reference the one.




            What is the best practice?




            In terms of best practice I don't think that it matters much for the single table. Aliasses can be useful as to make adapting / reusing scripts easier.




            Some more examples in the Microsoft documentation



            D. Using joins and subqueries to data in one table to delete rows in another table



            Using the table name twice



            DELETE FROM Sales.SalesPersonQuotaHistory 
            FROM Sales.SalesPersonQuotaHistory AS spqh
            INNER JOIN Sales.SalesPerson AS sp
            ON spqh.BusinessEntityID = sp.BusinessEntityID
            WHERE sp.SalesYTD > 2500000.00;


            Using an alias



            DELETE spqh 
            FROM
            Sales.SalesPersonQuotaHistory AS spqh
            INNER JOIN Sales.SalesPerson AS sp
            ON spqh.BusinessEntityID = sp.BusinessEntityID
            WHERE sp.SalesYTD > 2500000.00;


            Both serving the exact same purpose.






            share|improve this answer





























              2















              What is and what is needed that parameter before the delete keyword
              (In my example coincides with table name)?




              Referencing the table is a possibility due to the fact that you could DELETE FROM with an INNER JOIN.



              A simple example of deleting from #footbl with an inner join to a different table



              DELETE FT
              FROM
              #DifferentTable DT
              INNER JOIN #fooTbl FT
              ON DT.attr = FT.attr
              WHERE FT.attr ='some';


              Whereas this generates an error due to not specifying what table to delete from



              DELETE 
              FROM #DifferentTable AS DT
              INNER JOIN #fooTbl AS FT
              ON DT.attr = FT.attr
              WHERE FT.attr ='some';



              Msg 156, Level 15, State 1, Line 45 Incorrect syntax near the keyword
              'AS'.




              And this also works



              DELETE #fooTbl
              FROM #DifferentTable AS DT
              INNER JOIN #fooTbl AS FT
              ON DT.attr = FT.attr
              WHERE FT.attr ='some';


              In short, you need to specify the alias/table to delete from if you are referencing multiple tables, but you don't have to when you only reference the one.




              What is the best practice?




              In terms of best practice I don't think that it matters much for the single table. Aliasses can be useful as to make adapting / reusing scripts easier.




              Some more examples in the Microsoft documentation



              D. Using joins and subqueries to data in one table to delete rows in another table



              Using the table name twice



              DELETE FROM Sales.SalesPersonQuotaHistory 
              FROM Sales.SalesPersonQuotaHistory AS spqh
              INNER JOIN Sales.SalesPerson AS sp
              ON spqh.BusinessEntityID = sp.BusinessEntityID
              WHERE sp.SalesYTD > 2500000.00;


              Using an alias



              DELETE spqh 
              FROM
              Sales.SalesPersonQuotaHistory AS spqh
              INNER JOIN Sales.SalesPerson AS sp
              ON spqh.BusinessEntityID = sp.BusinessEntityID
              WHERE sp.SalesYTD > 2500000.00;


              Both serving the exact same purpose.






              share|improve this answer



























                2












                2








                2








                What is and what is needed that parameter before the delete keyword
                (In my example coincides with table name)?




                Referencing the table is a possibility due to the fact that you could DELETE FROM with an INNER JOIN.



                A simple example of deleting from #footbl with an inner join to a different table



                DELETE FT
                FROM
                #DifferentTable DT
                INNER JOIN #fooTbl FT
                ON DT.attr = FT.attr
                WHERE FT.attr ='some';


                Whereas this generates an error due to not specifying what table to delete from



                DELETE 
                FROM #DifferentTable AS DT
                INNER JOIN #fooTbl AS FT
                ON DT.attr = FT.attr
                WHERE FT.attr ='some';



                Msg 156, Level 15, State 1, Line 45 Incorrect syntax near the keyword
                'AS'.




                And this also works



                DELETE #fooTbl
                FROM #DifferentTable AS DT
                INNER JOIN #fooTbl AS FT
                ON DT.attr = FT.attr
                WHERE FT.attr ='some';


                In short, you need to specify the alias/table to delete from if you are referencing multiple tables, but you don't have to when you only reference the one.




                What is the best practice?




                In terms of best practice I don't think that it matters much for the single table. Aliasses can be useful as to make adapting / reusing scripts easier.




                Some more examples in the Microsoft documentation



                D. Using joins and subqueries to data in one table to delete rows in another table



                Using the table name twice



                DELETE FROM Sales.SalesPersonQuotaHistory 
                FROM Sales.SalesPersonQuotaHistory AS spqh
                INNER JOIN Sales.SalesPerson AS sp
                ON spqh.BusinessEntityID = sp.BusinessEntityID
                WHERE sp.SalesYTD > 2500000.00;


                Using an alias



                DELETE spqh 
                FROM
                Sales.SalesPersonQuotaHistory AS spqh
                INNER JOIN Sales.SalesPerson AS sp
                ON spqh.BusinessEntityID = sp.BusinessEntityID
                WHERE sp.SalesYTD > 2500000.00;


                Both serving the exact same purpose.






                share|improve this answer
















                What is and what is needed that parameter before the delete keyword
                (In my example coincides with table name)?




                Referencing the table is a possibility due to the fact that you could DELETE FROM with an INNER JOIN.



                A simple example of deleting from #footbl with an inner join to a different table



                DELETE FT
                FROM
                #DifferentTable DT
                INNER JOIN #fooTbl FT
                ON DT.attr = FT.attr
                WHERE FT.attr ='some';


                Whereas this generates an error due to not specifying what table to delete from



                DELETE 
                FROM #DifferentTable AS DT
                INNER JOIN #fooTbl AS FT
                ON DT.attr = FT.attr
                WHERE FT.attr ='some';



                Msg 156, Level 15, State 1, Line 45 Incorrect syntax near the keyword
                'AS'.




                And this also works



                DELETE #fooTbl
                FROM #DifferentTable AS DT
                INNER JOIN #fooTbl AS FT
                ON DT.attr = FT.attr
                WHERE FT.attr ='some';


                In short, you need to specify the alias/table to delete from if you are referencing multiple tables, but you don't have to when you only reference the one.




                What is the best practice?




                In terms of best practice I don't think that it matters much for the single table. Aliasses can be useful as to make adapting / reusing scripts easier.




                Some more examples in the Microsoft documentation



                D. Using joins and subqueries to data in one table to delete rows in another table



                Using the table name twice



                DELETE FROM Sales.SalesPersonQuotaHistory 
                FROM Sales.SalesPersonQuotaHistory AS spqh
                INNER JOIN Sales.SalesPerson AS sp
                ON spqh.BusinessEntityID = sp.BusinessEntityID
                WHERE sp.SalesYTD > 2500000.00;


                Using an alias



                DELETE spqh 
                FROM
                Sales.SalesPersonQuotaHistory AS spqh
                INNER JOIN Sales.SalesPerson AS sp
                ON spqh.BusinessEntityID = sp.BusinessEntityID
                WHERE sp.SalesYTD > 2500000.00;


                Both serving the exact same purpose.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 3 hours ago

























                answered 7 hours ago









                Randi VertongenRandi Vertongen

                6,1782931




                6,1782931



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Database Administrators Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f240135%2fsql-server-delete-syntax%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

                    Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

                    Ласкавець круглолистий Зміст Опис | Поширення | Галерея | Примітки | Посилання | Навігаційне меню58171138361-22960890446Bupleurum rotundifoliumEuro+Med PlantbasePlants of the World Online — Kew ScienceGermplasm Resources Information Network (GRIN)Ласкавецькн. VI : Літери Ком — Левиправивши або дописавши її