后面insert语句看不明白了,为什么没有values,这句年insert应该怎么理解?
CREATE Procedure CMRC_OrdersAdd
(
@CustomerID int,
@CartID nvarchar(50),
@OrderDate datetime,
@ShipDate datetime,
@OrderID int OUTPUT
)
AS
BEGIN TRAN AddOrder
/* Create the Order header */
INSERT INTO CMRC_Orders
(
CustomerID,
OrderDate,
ShipDate
)
VALUES
(
@CustomerID,
@OrderDate,
@ShipDate
)
SELECT
@OrderID = @@Identity
/* Copy items from given shopping cart to OrdersDetail table for given OrderID*/
INSERT INTO CMRC_OrderDetails
(
OrderID,
ProductID,
Quantity,
UnitCost
)
SELECT
@OrderID,
CMRC_ShoppingCart.ProductID,
Quantity,
CMRC_Products.UnitCost
FROM
CMRC_ShoppingCart
INNER JOIN CMRC_Products ON CMRC_ShoppingCart.ProductID = CMRC_Products.ProductID
WHERE
CartID = @CartID
/* Removal of items from user 's shopping cart will happen on the business layer*/
EXEC CMRC_ShoppingCartEmpty @CartID
COMMIT TRAN AddOrder
GO
------解决方案--------------------这是INSERT的一种语法之一.INSERT共三种语法:
1.insert table (...) values(...)
2.insert table (...) select ... from table2
2.insert table default values
------解决方案--------------------楼上正解
1.insert table (...) values(...)
这个很明显只能一次插入一条数据,但是下面这句就可以批量插入
2.insert table (...) select ... from table2
------解决方案--------------------select出来的列就对应之前insert的列,注意位置就ok了