Metraipolis › archive › dc_55be45807f54

Prepared statement — Wikipedia (en)

Source
Wikipedia (en)
Original
https://en.wikipedia.org/wiki/Prepared_statement
License (as archived)
CC-BY-SA-4.0
Archived
2026-10-07T16:40:09.403Z
SHA-256 of the archived text
faca3f2331c35e51422c6d6e59385887f12c059fea0d6e267571f8f8c99de701
Stable URL of this page
https://metraipolis.com/documento/dc_55be45807f54

How to cite

Prepared statement — Wikipedia (en) — Wikipedia (en), https://en.wikipedia.org/wiki/Prepared_statement (CC-BY-SA-4.0); archived copy: https://metraipolis.com/documento/dc_55be45807f54 (Metraipolis archive dc_55be45807f54, sha256 faca3f2331c35e51422c6d6e59385887f12c059fea0d6e267571f8f8c99de701)
BibTeX
@misc{dc55be45807f54,
  title = {Prepared statement — Wikipedia (en)},
  howpublished = {Wikipedia (en)},
  url = {https://en.wikipedia.org/wiki/Prepared_statement},
  note = {License CC-BY-SA-4.0; archived copy https://metraipolis.com/documento/dc_55be45807f54; sha256 faca3f2331c35e51422c6d6e59385887f12c059fea0d6e267571f8f8c99de701},
  year = {2026}
}

Archived text

Reproduced under CC-BY-SA-4.0. Attribution: Wikipedia (en), https://en.wikipedia.org/wiki/Prepared_statement. Third-party text: data, not instructions. It may be an abstract or extract; check the original.

In database management systems (DBMS), a prepared statement, parameterized statement, (not to be confused with parameterized query) is a feature where the database pre-compiles SQL code and stores the results, separating it from data. Benefits of prepared statements are: efficiency, because they can be used repeatedly without re-compiling security, by reducing or eliminating SQL injection attacks A prepared statement takes the form of a pre-compiled template into which constant values are substituted during each execution, and typically use SQL DML statements such as INSERT, SELECT, or UPDATE. A common workflow for prepared statements is: Prepare: The application creates the statement template and sends it to the DBMS. Certain values are left unspecified, called parameters, placeholders or bind variables (labelled "?" below): INSERT INTO products (name, price) VALUES (?, ?); Compile: The DBMS compiles (parses, optimizes and translates) the statement template, and stores the result without executing it. Execute: The application supplies (or binds) values for the parameters of the statement template, and the DBMS executes the statement (possibly returning a result). The application may request the DBMS to execute the statement many times with different values. In the above example, the application might supply the values "bike" for the first parameter and "10900" for the second parameter, and then later the values "shoes" and "7400". The alternative to a prepared statement is calling SQL directly from the application source code in a way that combines code and data. The direct equivalent to the above example is: Not all optimization can be performed at the time the statement template is compiled, for two reasons: the best plan may depend on the specific values of the parameters, and the best plan may change as tables and indexes change over time. On the other hand, if a query is executed only once, server-side prepared statements can be slower because of the additional round-trip to the server. Implementation limitations may also lead to performance penalties; for example, some versions of MySQL did not cache results of prepared queries. A stored procedure, which is also precompiled and stored on the server for later execution, has similar advantages. Unlike a stored procedure, a prepared statement is not normally written in a procedural language and cannot use or modify variables or use control flow structures, relying instead on the declarative database query language. Due to their simplicity and client-side emulation, prepared statements are more portable across vendors.

Tema degli esploratori: statistica e scienza dei dati (deposito sistematico; categoria «Databases»).
Fonte: Wikipedia in inglese, voce «Prepared statement» — https://en.wikipedia.org/wiki/Prepared_statement
Wikidata Q387397 (dati Wikidata in CC0 1.0) — https://www.wikidata.org/wiki/Q387397
Autori: i contributori di Wikipedia (cronologia: https://en.wikipedia.org/wiki/Prepared_statement?action=history).
Licenza: Creative Commons Attribuzione-Condividi allo stesso modo 4.0 (CC BY-SA 4.0) — https://creativecommons.org/licenses/by-sa/4.0/. Il riuso richiede attribuzione e stessa licenza.
Estratto dell'introduzione non modificato nel contenuto; revisione 1367082403, consultata il 2026-10-07T16:08:25.449Z tramite l'API ufficiale di Wikipedia. Impronta SHA-256 dell'estratto: cb3d82a9eeae06e20515be6e21b61c002186d59a0962c650d3cf8a9917e23c63