I am trying to understand how I can use an alias to refer to another database in the same instance, without the need for a hard-coded name.
The scenario is as follows:
I have db data with store data, db audit, which saves all changes made. for various reasons, I want to save audit data in a separate database, not least because it can become quite large for reporting purposes.
In db data, I donβt want to refer to it by a hard-coded name, but an alias, so in different environments I do not need to change the name and different sps to refer to the new name.
eg:
mydevdata mydevaudit
If there is an sp in mydevdata that calls mydevaudit , I don't want to change the sp when I go to check where db can be called mytestdata and mytestaudit . Again, for various reasons, database names can change more than spaces, instances, etc.
So, if I had a procedure in mydevdata :
proc A begin insert into mydevaudit.table.abc(somecol) select 1 end
when I go to the test, I donβt want to change the procedure to refer to another name (suppose for the argument that happened)
Instead, I want to do something like:
proc A begin insert into AUDITEBALIAS.table.abc(somecol) select 1 end
I am interested to know how I can do something like this, both pros and cons.
In addition, dymnamic SQL is not an option.
in advance for help.