怎么把存储过程改回SQL句子
基于Access数据库,实现购物功能的程序.微软IBuySpy(购物程序示例)中的一个存储过程和我要的功能可接近,怎么仿之写出SQL句子.
Orders是订单表,OrdersDetail是明细表,
ShoppingCart 是购物车,Products 是商品表
CREATE Procedure OrdersAdd
(
@CustomerID int,
@CartID nvarchar(50),
@OrderDate datetime,
@ShipDate datetime,
@OrderID int OUTPUT
)
AS
BEGIN TRAN AddOrder
/* Create the Order header */
INSERT INTO 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 OrderDetails
(
OrderID,
ProductID,
Quantity,
UnitCost
)
SELECT
@OrderID,
ShoppingCart.ProductID,
Quantity,
Products.UnitCost
FROM
ShoppingCart
INNER JOIN Products ON ShoppingCart.ProductID = Products.ProductID
WHERE
CartID = @CartID
/* Removal of items from user's shopping cart will happen on the business layer*/
EXEC ShoppingCartEmpty @CartId
COMMIT TRAN AddOrder
GO
Orders是订单表,OrdersDetail是明细表,
ShoppingCart 是购物车,Products 是商品表
CREATE Procedure OrdersAdd
(
@CustomerID int,
@CartID nvarchar(50),
@OrderDate datetime,
@ShipDate datetime,
@OrderID int OUTPUT
)
AS
BEGIN TRAN AddOrder
/* Create the Order header */
INSERT INTO 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 OrderDetails
(
OrderID,
ProductID,
Quantity,
UnitCost
)
SELECT
@OrderID,
ShoppingCart.ProductID,
Quantity,
Products.UnitCost
FROM
ShoppingCart
INNER JOIN Products ON ShoppingCart.ProductID = Products.ProductID
WHERE
CartID = @CartID
/* Removal of items from user's shopping cart will happen on the business layer*/
EXEC ShoppingCartEmpty @CartId
COMMIT TRAN AddOrder
GO
...全文
相关推荐
SQL语句创建存储过程
在SQL Server 2005中,存储过程是一种预编译的SQL代码集合,它可以封装一组复杂的查询和操作,以供以后重复使用。这极大提高了数据库管理效率,减少了网络流量,并增强了安全性。
SQL存储过程SQL存储过程SQL存储过程
SQL存储过程详解SQL存储过程是数据库管理系统中的一种重要组件,它是一组为了完成特定功能的 SQL 语句,集经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数来执行它。
SQL Server中存储过程比直接运行SQL语句慢的原因
SQL Server 中存储过程比直接运行 SQL 语句慢的原因在 SQL Server 中,存储过程比直接运行 SQL 语句慢的原因是 Parameter sniffing 问题。
SQL Server基础:存储过程
"本文主要介绍了SQL Server中的存储过程,包括其基本概念、优点、缺点以及分类。"在SQL Server中,存储过程是一个重要的数据库管理工具,它由一系列T-SQL语句组成,用于执行特定的
SQL中存储过程的创建和使用
"这篇资料主要介绍了SQL中存储过程的创建和使用方法,包括创建存储过程的基本语法以及在C#中调用存储过程的示例代码。"在SQL中,存储过程是一种预编译的SQL语句集合,它可以接受输入参数、提供输


