Create a stored procedure which can operate with different similar databases

Database

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!

1 REPLY
Enthusiast

Re: Create a stored procedure which can operate with different similar databases

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