Using a Script to Add Data to the Database Print this Topic Previous Page Up One Level Next page

Home >  Tutorials > "ZooDB" Database > Inserting Data into the Database >

Using a Script to Add Data to the Database

Earlier in this tutorial, you added a script to the ZooDBProject that you can now use to populate the tblAnimalTypes and tblAnimalCategories tables with data. The file tblAnimalTypes_data.sql contains all the INSERT statements that are necessary to add the data to the tblAnimalTypes and tblAnimalCategories tables.


To avoid the manual data source assignment to the individual SQL files in your project in the future, you will also define a default data source (i.e., your tutorial database) for all files that are contained in the SQL folder of the Project window.



To set a default data source for the SQL folder:

1.Click the SQL folder in the Project window.
2.In the Properties window below, select "ZooDBConnect" from the Data Source drop-down list in the General section.


3.Click the tblAnimalTypes_data.sql file in the SQL folder and note that "ZooDBConnect" now appears as data source in the properties.



To execute tblAnimalTypes_data.sql:

1.Make sure that the ZooDBConnect connection is active.
2.In the Project window, right-click the file tblAnimalTypes_data.sql in the SQL folder and choose Execute SQL ic_execute-sql from the context menu. The file opens in an SQL Editor window and executes automatically. The tables tblAnimalTypes and tblAnimalCategories are populated with data.


Checking the result

To do a quick check as to whether the tables have been successfully populated with data, you can display the row count for all tables in the Online Browser.



To display the row count of all tables in the Online Browser:

Right-click the "User Tables" folder and select Row Count | Show/Update from the context menu.

© 2019 Altova GmbH