| title | sp_unprepare (Transact-SQL) | ||
|---|---|---|---|
| description | Discards the execution plan created by the `sp_prepare` stored procedure. | ||
| author | markingmyname | ||
| ms.author | maghan | ||
| ms.reviewer | randolphwest | ||
| ms.date | 06/23/2025 | ||
| ms.service | sql | ||
| ms.subservice | system-objects | ||
| ms.topic | reference | ||
| f1_keywords |
|
||
| helpviewer_keywords |
|
||
| dev_langs |
|
||
| monikerRange | >=aps-pdw-2016 || =azure-sqldw-latest || >=sql-server-2016 || >=sql-server-linux-2017 || =azuresqldb-mi-current |
[!INCLUDE sql-asdbmi-asa-pdw]
Discards the execution plan created by the sp_prepare stored procedure. sp_unprepare is invoked by specifying ID = 15 in a tabular data stream (TDS) packet.
sp_unprepare handle
[ ; ]
[!INCLUDE extended-stored-procedures]
The handle value returned by sp_prepare. handle is int.
The following example prepares, executes, and unprepares a basic statement.
DECLARE @P1 AS INT;
EXECUTE sp_prepare
@P1 OUTPUT, N'@P1 NVARCHAR(128), @P2 NVARCHAR(100)',
N'SELECT database_id, name FROM sys.databases WHERE name = @P1 AND state_desc = @P2';
EXECUTE sp_execute @P1, N'tempdb', N'ONLINE';
EXECUTE sp_unprepare @P1;