what is EXEC sp_unprepare

Heisenberg 261 Reputation points
2022-02-16T15:53:45.483+00:00

hello,
when i run sp_who /sp_whoisactive procs, i see statements like "EXEC sp_unprepare 124" run by some sessions. When i reached out to my development team they dont seem to be using these stored procedures. So is there any particular driver like jdbc internally creates it and sends it to sql server? if yes can someone give me example

Transact-SQL
Transact-SQL
A Microsoft extension to the ANSI SQL language that includes procedural programming, local variables, and various support functions.
4,624 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Tom Phillips 17,731 Reputation points
    2022-02-16T17:46:26.83+00:00

    You are seeing the last command run by the session.

    sp_unprepare remove the item used by sp_prepare. This is how most drivers run TSQL code with parameters, like JDBC. This is very common and not a cause for concern.

    https://learn.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-prepare-transact-sql?view=sql-server-ver15

    0 comments No comments

  2. Heisenberg 261 Reputation points
    2022-02-16T18:39:31.417+00:00

    Thanks Tom, so if i understand this clearly . a client code like "select * from <table> where <column>=5" will be translated using sp_prepare as dynamic sql and transferred to sql server in form of sp_prepare?

    if yes which statement will use sp_prepare/sp_unprepare? i have also seen simple SELECT statements without any sp_prepare . so want to know difference between these two.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.