SQL Server中set和select之间的区别

时间:2018-03-20 17:35:57

标签: sql-server

SQL Server中setselect之间有什么区别,因为这两个关键字都用于在Microsoft SQL Server中分配参数值?

1 个答案:

答案 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