我刚刚在 SQL Server 2008 R2 中对此进行了测试
我开始:
CREATE PROCEDURE dbo.Stupid
AS
WAITFOR DELAY '0:00:10'
SELECT TOP 5 * FROM dbo.UniqueId
GO
然后我执行了以下
SQL Server 查询窗口 1:
EXEC dbo.Stupid
SQL Server 查询窗口 2,而查询窗口 1 中的查询正在运行:
ALTER PROCEDURE dbo.Stupid
AS
WAITFOR DELAY '0:00:05'
SELECT TOP 5 * FROM dbo.UniqueId
WHERE ID > 5
GO
EXEC dbo.Stupid
SQL Server 查询窗口 3,而查询窗口 1 和查询窗口 2 中的查询正在运行:
EXEC dbo.Stupid
结果:
- 查询窗口 1 运行了 10 秒(因此在窗口 2 和 3 之后完成),并返回 ids 1 - 5
- 查询窗口 2 更改并在 5 秒内运行该过程,并返回 ids 6 - 10
- Query Window 3 ran in 5 seconds and returned ids 6 - 10
What happens:
- Already executing code will complete running on the procedure as it was when they were started
- Anything that starts run after the code is altered will run the new code