zoukankan      html  css  js  c++  java
  • OUTPUT 语句使用

    从msdn上截取的部分示例说明,记录下来以备使用.

    A. Using OUTPUT INTO with a simple INSERT statement

    USE AdventureWorks;
    GO
    DECLARE @MyTableVar table( ScrapReasonID smallint,
                               Name 
    varchar(50),
                               ModifiedDate 
    datetime);
    INSERT Production.ScrapReason
        OUTPUT INSERTED.ScrapReasonID, INSERTED.Name, INSERTED.ModifiedDate
            
    INTO @MyTableVar
    VALUES (N'Operator error'GETDATE());

    --Display the result set of the table variable.
    SELECT ScrapReasonID, Name, ModifiedDate FROM @MyTableVar;
    --Display the result set of the table.
    SELECT ScrapReasonID, Name, ModifiedDate 
    FROM Production.ScrapReason;
    GO

    B. Using OUTPUT with a DELETE statement

    USE AdventureWorks;
    GO
    DELETE Sales.ShoppingCartItem
    OUTPUT DELETED.
    * 
    WHERE ShoppingCartID = 20621;

    --Verify all rows in the table that match the WHERE clause have been deleted.
    SELECT COUNT(*AS [Rows in Table] FROM Sales.ShoppingCartItem WHERE ShoppingCartID = 20621;
    GO

    C. Using OUTPUT INTO with an UPDATE statement

    USE AdventureWorks;
    GO
    DECLARE @MyTableVar table(
        EmpID 
    int NOT NULL,
        OldVacationHours 
    int,
        NewVacationHours 
    int,
        ModifiedDate 
    datetime);
    UPDATE TOP (10) HumanResources.Employee
    SET VacationHours = VacationHours * 1.25 
    OUTPUT INSERTED.EmployeeID,
           DELETED.VacationHours,
           INSERTED.VacationHours,
           INSERTED.ModifiedDate
    INTO @MyTableVar;
    --Display the result set of the table variable.
    SELECT EmpID, OldVacationHours, NewVacationHours, ModifiedDate
    FROM @MyTableVar;
    GO
    --Display the result set of the table.
    --
    Note that ModifiedDate reflects the value generated by an
    --
    AFTER UPDATE trigger.
    SELECT TOP (10) EmployeeID, VacationHours, ModifiedDate
    FROM HumanResources.Employee;
    GO

  • 相关阅读:
    easyui tree:根据属性格式化树节点名称
    Druid执行多条SQL异常:Cause: java.sql.SQLException: sql injection violation, multi-statement not allow
    springmvc接收jquery提交的数组数据
    jquery easyui:tab自动加载第一个tab内容
    thymeleaf-extras-shiro
    Shiro:授权控制
    thymeleaf : EL1050E The arguments (...) for the constructor call are missing
    (转载)ibatis:解决sql注入问题
    05 Oracle process
    04 memory structure
  • 原文地址:https://www.cnblogs.com/xh831213/p/1690017.html
Copyright © 2011-2022 走看看