sql存储过程几个简单例子

avatar
作者
猴君
阅读量:5

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

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!