All Forums Database
Matvey Zhuravel 1 post Joined 09/13
02 Feb 2015
Create a stored procedure which can operate with different similar databases

Good day!
I've got several databases which contain tables of data; all these databases have the same table names and table structures, only the stored data differs.
Is it possible to create a universal stored procedure, that can work with these databases without having to repeat all the stored code once for each database? I mean Ctrl+C, Ctrl+V, change database name, then again - Ctrl+C, Ctrl+V, change database name, etc.
I've tried using DATABASE command from within stored procedure, both statically and dynamically; that's explicitly forbidden. Tried creating MACRO for database changing; but I cannot call macro from sp. Is this task possible?
Thank you!

Renji 17 posts Joined 08/05
03 Feb 2015

I would say it is possible to create a global stored procedure. You can pass the databasename as a variable and generate the SQL's you need and execute them

John Abraham

You must sign in to leave a comment.