为什么 DELETE FROM ... FROM ... 不会出错? [英] Why does DELETE FROM ... FROM ... not error out?

查看:25
本文介绍了为什么 DELETE FROM ... FROM ... 不会出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

存储过程中的这一位显然是有效的 sql:

删除顶部(@MaxRecords)发件人表从表 BINNER JOIN Table2 R ON B.fk = R.pk其中 R.Value <@DecVariable;

如何将两个 FROM 语句放在一起并且仍然有效?

解决方案

首先TOP在删除语法中表示它是SQL Server.

这是完美的有效查询,请参阅

对象:

This bit within a stored proc is apparently valid sql:

DELETE TOP (@MaxRecords)
FROM Table
FROM Table B
INNER JOIN Table2 R ON B.fk = R.pk
WHERE R.Value < @DecVariable;

How can two FROM statements be put together and yet still be valid?

解决方案

First of all TOP in delete syntax indicates that it is SQL Server.

It is perfect valid query, see DELETE:

FROM

An optional keyword that can be used between the DELETE keyword and the target table_or_view_name, or rowset_function_limited.

FROM table_source

Specifies an additional FROM clause. This Transact-SQL extension to DELETE allows specifying data from and deleting the corresponding rows from the table in the first FROM clause.

This extension, specifying a join, can be used instead of a subquery in the WHERE clause to identify rows to be removed.

DELETE:

Object:

这篇关于为什么 DELETE FROM ... FROM ... 不会出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆