Here, You can find basic database theory on Prepared or Parameterized Statments.
|Prepared or Parameterized Statements in Database System|
In this post, I demonstrate basic practical about prepared statements of MySQL.
You can write or create prepared statement in MySQL but this is not an efficient way because the binary protocol through a prepared statement API is better.
But still you can write and even this doesn’t require any other programming you can directly write in SQL.
You can use a prepared statement for MySQL Client program.You can also use a prepared statement in a stored procedure for the dynamic SQL approach.
Below is a small practical demonstration of this:
Let’s first create sample table and data.
CREATE TABLE Test
INSERT INTO Test
Create prepared statement:
PREPARE TestStmt FROM
'SELECT * FROM Test
You can see ‘ ? ‘ in WHERE clause. This ‘ ? ‘ means require parameter in this field you can pass parameter during execution of Prepared Statement.
Execute Prepared Statement:
SET @a = 8;
EXECUTE TestStmt USING @a;
8 | 'EFG'
De-allocate prepared statement:
DEALLOCATE PREPARE TestStmt;
You can also set max_prepared_stmt_count this system variable to guard creation of too many prepared statements.
Please share your ideas and opinions about this topic with me, your contribution will add true value to this topic.
If anyone has doubts on this topic then please do let me know by leaving comments or send me an email.
If you like this post, then please share it with others.
Please follow dbrnd.com, I will share my experience towards the success of Database Research and Development Activity.
I put up a post every day, please keep reading and learning.
Discover Yourself, Happy Blogging !
Anvesh M. Patel.