Question: Unpreparing a statement after use
See original GitHub issueThe documentation suggests calling ‘unprepare’ after you execute the prepared statement; but doing this removes the prepared statement from SQL Server thus negating the point of preparing it in the first place.
Preparing the statement, creates an execution plan for the query thus making future calls much quicker (3 to 4 times MS says) as it can reuse the plan; unpreparing it actually makes the query slower as it has to do more roundtrips than if you just called it as a normal query.
SQL Server Documentation https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-prepare-transact-sql?view=sql-server-2017
Is my understanding flawed?
-- Prepare query
DECLARE @P1 int;
EXEC sp_prepare @P1 output,
N'@Param int',
N'SELECT *
FROM Sales.SalesOrderDetail AS sod
INNER JOIN Production.Product AS p ON sod.ProductID = p.ProductID
WHERE SalesOrderID = @Param
ORDER BY Style DESC;';
EXEC sp_execute 1, 49879;
GO
EXEC sp_execute 1, 48766;
GO
EXEC sp_unprepare 1;
GO
Software versions
- NodeJS: v10.15.0
- node-mssql: v4.3.0
- SQL Server: Microsoft SQL Server 2016 (SP1) - 13.0.4001.0 (X64)
Issue Analytics
- State:
- Created 5 years ago
- Comments:6
Top Results From Across the Web
DB::unprepared() does no raise exception on 2nd or later ...
I noticed that if I put each statement to its own DB::unprepared() call, it will raise the exception as expected, however, as soon...
Read more >3 Practice CASPer Questions and Best Responses
It's good to use conditional statements in your CASPer answers. For example: “If the group discovered a serious personal issue in Sue's life,...
Read more >How to Design an Agenda for an Effective Meeting
Another tactic for creating a better meeting agenda is listing topics as questions to be answered. Instead of writing “office space ...
Read more >How to Answer The 64 Toughest Interview Questions | OHSU
Keep an interview diary. Right after each interview note what you did right, what could have gone a little better, and what steps...
Read more >HURRICANE KATRINA: A NATION STILL UNPREPARED
and state officials have known since at least 1994 about the need to address this problem. For its part, the federal government, which...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Totally understood. Thx for the help
I was also confused by the
unprepare
and I ended up using onlyprepare
andexecute
… I just push different params inside the prepared query by usinginput
… it brought me up to 5x performance.Maybe it is a lack of knowledge but I think
unprepare
is in the docs to show it can be used, but is optional.