what this query do when delete ?

ahmed salah 3,216 Reputation points
2020-12-02T00:43:10.917+00:00

I work on SQL server only I have delete statement delete data from
table trade code
but I don't know when this statement delete Executed

DELETE FT

 FROM Parts.Nop_Part pt 
 INNER JOIN Parts.Nop_PartsFamilyAttribute fm ON pt.PartsFamilyID=fm.PartFamilyID AND fm.[Key]=20281007 
 INNER JOIN #Pls pl ON pl.ZPLID=fm.Value
 INNER JOIN Parts.TradeCodes FT ON pt.PartID=ft.PartID AND FT.PartLevel=0
 INNER JOIN #PLNewData TN ON TN.PartID = FT.PartID AND TN.CodeTypeID = FT.CodeTypeID
 WHERE 
 TN.Code <> FT.Code 

I know that statement delete from table trade code but I need small case when this delete from table trade code
done

Developer technologies | Transact-SQL
SQL Server | Other
{count} votes

Accepted answer
  1. Viorel 122.6K Reputation points
    2020-12-02T09:49:07.37+00:00

    It deletes the rows from TradesCode table that satisfy the conditions, which are expressed in SQL and can be interpreted in this manner:

    • The PartLevel is zero
    • There is a corresponding row (or rows) in Nop_Parts according to PartID
    • There is a corresponding row (or rows) in Nop_PartsFamilyAttribute according to PartFamilyID, excepting rows that have Key=20281007 and excepting rows that are enumerated in #Pls by Value
    • There is a corresponding row (or rows) in #PLNewData according to PartID and CodeTypeID, which has a different Code,

    or something like this. Re-check the conditions that appear in ON and WHERE, and see the algorithm used to fill #Pls and #PLNewData.

    0 comments No comments

4 additional answers

Sort by: Most helpful
  1. Guoxiong 8,206 Reputation points
    2020-12-02T01:40:03.02+00:00

    The DELETE statement deletes the rows from the table Parts.TradeCodes.

    0 comments No comments

  2. ahmed salah 3,216 Reputation points
    2020-12-02T01:45:44.757+00:00

    thank you for reply
    I know it delete from table parts.tradecodes

    this delete will happen when


  3. EchoLiu-MSFT 14,621 Reputation points
    2020-12-02T02:10:51.433+00:00

    Hi @ahmed salah ,

    DELETE removes one or more rows from a table or view in SQL Server.
    When executing the delete statement above, first execute the FROM and WHERE clauses, select the rows to be deleted, and then execute the DELETE clause to delete these rows.

    Regards
    Echo


    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.
    Hot issues November--What can I do if my transaction log is full?
    Hot issues November--How to convert Profiler trace into a SQL Server table

    0 comments No comments

  4. ahmed salah 3,216 Reputation points
    2020-12-02T02:17:36.427+00:00

    according to statement above when delete from table parts.tradecodes
    so what must exist on table pl and plnewdata to delete happen


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.