Change 'Owner' (source database) for tables/views in a SQL file
Posted: Thu 19 Mar 2015 13:49
I have multiple databases setup with the same tables and views. Is it possible to tell a .sql file which database to use, without having to preface each statement referencing a table/view in the SQL with the DB name? If I do explicitly state the DB name, I would have to find/replace every occurrence when I wish to reference a different DB.
For example, I have MYDB1 and MYDB2. Both have table USERS with fields ID, FIRST, LAST.
My SQL would be something like
SELECT USERS.ID, USERS.FIRST, USERS.LAST FROM USERS
Is there a way to instruct the SQL which DB to look at, without coding the DB into each table/view reference such as:
SELECT USERS.ID, USERS.FIRST FROM MYDB1.USERS
The optimal solution (at least for me) would be something that could be a property that could be set/changed within 'Query Builder' without having to edit the source SQL text.
For example, I have MYDB1 and MYDB2. Both have table USERS with fields ID, FIRST, LAST.
My SQL would be something like
SELECT USERS.ID, USERS.FIRST, USERS.LAST FROM USERS
Is there a way to instruct the SQL which DB to look at, without coding the DB into each table/view reference such as:
SELECT USERS.ID, USERS.FIRST FROM MYDB1.USERS
The optimal solution (at least for me) would be something that could be a property that could be set/changed within 'Query Builder' without having to edit the source SQL text.