SQL Server:Varialble VS Parameters

在SQL SERVER中,不要将变量和参数弄混淆了,即使他们的语法几乎相同:

1. 一个变量的值在一条SQL语句被真正执行之前永远是未知的,在编译时也是未知的。

2. 传递给存储过程的参数值在编译时是已知的,因为直到存储过程参数被赋值并且被真正调用,该存储过程才被编译和优化!

 

原文:

Don't confuse variables with parameters even though their syntax is nearly identical. A variable's value is never known until the statement is actually executed; it is never known at compile time. Stored procedure parameters are known when the procedure is compiled because compilation and optimization don't even take place until the procedure is actually called with specific values for the parameters.

原文地址:https://www.cnblogs.com/liunatural/p/1436577.html