• SQL Server中使用DELETE INNER或UPDATE INNER


    在 SQL Server 中使用 DELETEUPDATEINNER JOIN 关键字与 Access 的常规写法不同。
    Access中写为:
    delete from t1 inner join t2 on t1.id = t2.tid
    而SQL Server中须写为:
    delete from t1 from t1 inner join t2 on t1.id = t2.tid
    注意蓝线部分!
    同样,Update的写法也有所有不同。
    Access中:
    update t1 inner join t2 on t1.id = t2.tid set t1.name='Liu'
    SQL Server中:
    update t1 set t1.name='Liu' from t1 inner join t2 on t1.id = t2.tid
    参照文档:

    http://www.sqlmag.com/Articles/Index.cfm?ArticleID=8808

    Editor's Note: This is the debut of T-SQL Black Belt, a series of articles that demonstrate practical, advanced tips for using T-SQL. Send your experts-only T-SQL tips to SQL Server MVP Itzik Ben-Gan at blackbelt@sqlmag.com. If we use your submission, you'll receive $100 and an exclusive T-SQL Black Belt shirt.

    Sometimes you need to modify data, but the criteria that define which rows will be affected are based on data that doesn't exist in the modified table but in another table. You could use subqueries to solve the problem; or you could use a syntax that originated from Sybase and uses joins in the DELETE and UPDATE statements. This syntax isn't ANSI-compliant and might look strange at first glance. But if you're comfortable writing join statements, you'll find the syntax convenient, especially for inside triggers, in which you usually need to join the base table to the inserted or deleted tables.

    These examples use Northwind sample database tables. Let's start with an abbreviated form of the DELETE statement syntax:

    DELETE [FROM] <modified_table>
    [FROM <modified_table> <join_type>
    JOIN <another_table>
    ON <join_condition>]
    [WHERE <search_condition>]

    Suppose you want to delete from the Order Details table all rows for orders that the customer VINET places. The problem is that the Order Details table doesn't have information about the customer who made the order; this information is in the Orders table. The following DELETE statement will delete the appropriate rows: . . .

  • 相关阅读:
    将方法作为方法的参数
    远程桌面无响应解决方案(转)
    QQ通信机制(转)
    电脑管家禁止程序修改文档后如何恢复权限
    SQL Sever——远程过程调用失败(0x800706be)
    JavaScript学习笔记之JavaScript调用C#编写的COM组件
    kendoUI 免费部分开发部分经验。
    mongoDB连接信息及生成对应的collection生成代码
    写个匹配某段html dom代码某属性的正则匹配方法
    微信获取用户支付共享地址
  • 原文地址:https://www.cnblogs.com/jyzjh/p/1444460.html
Copyright © 2020-2023  润新知