阅读量:5
- 创建一个简单的存储过程,返回所有顾客的数量:
CREATE PROCEDURE GetCustomerCount AS BEGIN SELECT COUNT(*) AS CustomerCount FROM Customers; END
- 创建一个存储过程,根据给定的国家参数返回该国家的所有顾客:
CREATE PROCEDURE GetCustomersByCountry @Country NVARCHAR(50) AS BEGIN SELECT * FROM Customers WHERE Country = @Country; END
- 创建一个存储过程,将给定的订单号参数作为输入,并返回该订单的详细信息:
CREATE PROCEDURE GetOrderDetails @OrderID INT AS BEGIN SELECT * FROM Orders WHERE OrderID = @OrderID; END
- 创建一个存储过程,将给定的产品类别参数作为输入,并返回该类别中所有产品的数量和平均价格:
CREATE PROCEDURE GetProductStats @CategoryID INT AS BEGIN SELECT COUNT(*) AS ProductCount, AVG(Price) AS AveragePrice FROM Products WHERE CategoryID = @CategoryID; END