Change 'Owner' (source database) for tables/views in a SQL file

Discussion of open issues, suggestions and bugs regarding database management and administration tools for MySQL
Post Reply
mysqluser007
Posts: 4
Joined: Tue 10 Feb 2015 20:17

Change 'Owner' (source database) for tables/views in a SQL file

Post by mysqluser007 » 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.

alexa

Re: Change 'Owner' (source database) for tables/views in a SQL file

Post by alexa » Thu 19 Mar 2015 15:17

You could specify:

USE database_name

at the beginning of the SQL document or select the database in the 'Database' drop-down menu on the Connection toolbar for the SQL document.

Also, you could create multiple connections in Database Explorer and specify different databases for each connection in the 'Database' field on the 'General' tab of the 'Database Connection Properties' dialog box that can be invoked by right-clicking the connection in Database Explorer and selecting 'Modify Connection' from the popup menu.

mysqluser007
Posts: 4
Joined: Tue 10 Feb 2015 20:17

Re: Change 'Owner' (source database) for tables/views in a SQL file

Post by mysqluser007 » Thu 19 Mar 2015 18:20

Thank you, both of these options will provide the solution I need.

Post Reply