SQL Server中set
和select
之间有什么区别,因为这两个关键字都用于在Microsoft SQL Server中分配参数值?
答案 0 :(得分:0)
SET
用于分配单个值,而SELECT
用于分配多个值。例如
DECLARE @Product TABLE (ProductId INT,ProductCode VARCHAR(10), Name VARCHAR(100))
INSERT INTO @Product(ProductId,ProductCode,Name)
(SELECT 1,'P001','Computer')
DECLARE @variable1 INT,@variable2 AS VARCHAR(100),@variable3 AS VARCHAR(100)
SET @variable1 = (SELECT ProductId FROM @Product)
SELECT @variable2 = ProductCode, @variable3 = Name FROM @Product
SELECT @variable1,@variable2,@variable3