I try to explain correctly: I have stored procedures that use two tables: myFiles
and myBooks
. Now I want to create two new tables myFilesProduction
and myBooksProduction
.
What's the best way to change stored procedures to select the correct tables to use with an argument ?
Use a variable
@nameTable
with dynamic queries?IF(@isProduction) SET @books = 'myBooksProduction' EXEC 'SELECT * FROM' + @books
But I already use dynamic SQL in some procedures.
Using a simple condition
IF(@isProduction) BEGIN -- SELECT * FROM MyFilesProduction, MyBooksProduction ELSE -- SELECT * FROM myFiles, myBooks END
but I have to use redundant code
some other way ?