Why can't I use an alias in a DELETE statement?

前端 未结 2 1244
天命终不由人
天命终不由人 2020-11-30 22:27

In SQL Server Compact Edition in Visual Studio 2010 (maybe SQL Server and SQL in general, I don\'t know), this command works:

DELETE FROM foods WHERE (name I         


        
相关标签:
2条回答
  • 2020-11-30 23:05

    The delete statement has strange syntax. It goes like this:

    DELETE f FROM foods f WHERE (f.name IN ('chickens', 'rabbits'))
    
    0 讨论(0)
  • 2020-11-30 23:18

    To alias the table you'd have to say:

    DELETE f FROM dbo.foods AS f WHERE f.name IN (...);
    

    I fail to see the point of aliasing for this specific DELETE statement, especially since (at least IIRC) this no longer conforms to strict ANSI. But yes, as comments suggest, it may be necessary for other query forms (eg correlation).

    0 讨论(0)
提交回复
热议问题