由于@A从未被声明,所以
sql server应该会抛出一个
错误,但是它不会.这是为什么?
DECLARE @i int = 1;
IF @i > 10
BEGIN
DECLARE @A int = 100;
END
PRINT @A; // doesn't return any result
感谢名单
sql Server没有块级变量范围.
它是每批次/存储过程等
From MSDN(我的大胆)
The scope of a variable is the range
of Transact-sql statements that can
reference the variable. The scope of a
variable lasts from the point it is
declared until the end of the batch or
stored procedure in which it is declared.
原文链接:https://www.f2er.com/mssql/75666.html