Opening and Executing an SQL File

www.altova.com Print this Topic Previous Page Up One Level Next page

Home >  Tutorials > "ZooDB" Database > Adding Tables to the Database >

Opening and Executing an SQL File

In the previous section of the tutorial, you added the create_ZooDB_tables.sql script to your database project. This script can now be used to add tables to the zoo database. Note that any SQL script must be assigned to a data source connection before it can be executed in DatabaseSpy (see the instructions below).

 

 

To add tables to a database by executing an SQL script:

1.Make sure that the ZooDBConnect connection is active.

 

Note:A new SQL Editor window is automatically associated with the data source that is active in the Online Browser or Project Window. The active data source is displayed at all times in the Execution Target Bar. That is, all commands issued from SQL Editor will affect this particular data source only. If there are multiple data sources, the SQL Editor belongs to the one which was last clicked before you opened the SQL Editor. Any subsequent SQL Editor windows that you open will inherit the currently active data source.

 

2.In the Project window, double-click the create_ZooDB_tables.sql entry in the SQL folder. The script file opens in an SQL Editor window.
3.If necessary, assign a data source to the current script. When the script has no data source assigned, the "Unknown - Offline" status appears at the top of the SQL Editor window.

sql_create-zoodb-tables

To assign a data source to the script, click the Offline hyperlink and, in the Properties window, select "ZooDBConnect" from the Data Source list.

tab_properties-data-source

The SQL script is now connected to the ZooDBConnect data source, and the execution buttons in the SQL Editor are active. Click the Save Project ic_save_project button in the Project window or press Ctrl+S to save this data source assignment in the project properties.

4.In the SQL Editor, click the Execute ic_execute-sql button or press F5. The tables are added to the ZooDB database.

 

 

To see the newly added tables in the Online Browser:

1.Click the Online Browser tab.
2.Right-click on the name of the database, ZooDB, and select Refresh from the context menu or click the Refresh ic_refresh-datasource button in the toolbar of the Online Browser.

zoo-refresh

The newly inserted tables are displayed in the User Tables folder. If the script executed successfully, the following tables will have been added to the database:

dbs_zoodb_tables


© 2019 Altova GmbH