0

if somebody can help me please i want to write a store procedure in mysql to insert,update and delete but it should be dynamically because i have many tables and columns in my database the store procedure should be call than it should take the table and column dynamically ,can anyone help me please
thank you
god bless

2
Contributors
1
Reply
2
Views
5 Years
Discussion Span
Last Post by adam_k
0

Hello, first of all this is the MS SQL part of the forum, so you might get a better solution if you post in the MySQL.
Secondly I would like to warn you that quite often it can be very dangerous to use a stored procedure to delete from tables. Of course it depends on how you write the procedure, but it is easy to loose your data(ie if the criteria can be blank).
Now to the solution:
In MS SQL we use

execute(@sql)

to execute dynamic SQL. In MySQL I've searched (http://forums.mysql.com/read.php?98,152150,152174#msg-152174) and the equivalent seems to be

PREPARE stmt1 FROM 'SELECT "ok"';
		EXECUTE stmt1;
		DEALLOCATE PREPARE stmt1;

Give it a try and let us (or even better the MySQL team) know if you run into problems.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.