Importing database tables

If you have data for your project defined in an external database, we recommend you to import data in the built-in AnyLogic database, and then use data in the model by querying the AnyLogic database tables.

Follow one of the following instructions, depending on the type of your database:

If data in the external database have been changed, you can update data in the imported database. If you expect data to change constantly, you can set your database to update automatically on each model startup.

Importing from MS Access / MS Excel file

 To import data from MS Excel or MS Access file

  1. In the Projects view, right-click the model's Database item, and choose Import database tables... from the context menu.
  1. You will see the Import database tables... dialog box. First, choose the database file in the left pane, Setup connection settings.
  2. In the Type drop-down list, leave the default setting: Excel/Access.
  3. Click the Browse button. The Open dialog box is displayed. Browse for the MS Excel / MS Access file that stores the data you want to import. Double-click the file or select it and click the Open button to select the file. The  button to the right allows to switch between the absolute and relative file paths.
  4. When finished, establish the connection with the selected file. Click the Show list of tables button. AnyLogic will try to connect to the specified database, and show the list of external database tables in the right pane of the dialog.
  5. In the Select table(s) you want to import table, select the checkboxes for the database tables you want to import into your model's database. Here you can modify the auto-generated names of the tables that will be created in AnyLogic database (in the Name in AnyLogic DB column). 

  1. If you expect data in external database to be updated and want to always have the up-to-date data in your model, select the checkbox Update data on the model startup. Having set this option, you tell AnyLogic to update data from the external database every time the user starts running the model. You can switch the auto-update off in the database properties.
  2. If tables with the same names already exist in AnyLogic database, you will see the warning as shown at the bottom of the figure below. You can choose whether you want to replace the existing tables with the tables from the external database, or keep the existing tables, and use different names for the imported tables.
  1. Click OK button. In the Projects view, expand the  Database item branch, and you will see the list of tables added into the AnyLogic database.

Importing from MS SQL Server database

 To import data from MS SQL Server database

  1. In the Projects view, right-click the model's Database item, and choose Import database tables... from the context menu.
  1. You will see the Import database tables... dialog box. First, choose the database in the left pane, Setup connection settings.
  2. In the Type drop-down list, choose Microsoft SQL Server.
  3. Specify the host computer in the Host field and the name of the database you want to access in the Database name field.
  4. Enter Login and Password if they are required by the database.
  5. When finished, establish the connection with the selected database. Click the Show list of tables button. AnyLogic will try to connect to the specified database, and show the list of external database tables in the right pane of the dialog.
  6. In the Select table(s) you want to import table, select the checkboxes for the database tables you want to import into your model's database. Here you can modify the auto-generated names of the tables that will be created in AnyLogic database (in the Name in AnyLogic DB column). 
  7. If you expect data in external database to be updated, and want to always have the up-to-date data in your model, select the checkbox Update data on the model startup. Having set this option, you tell AnyLogic to update data from the external database every time the user starts running the model. You can switch the auto-update off in the database properties.
  8. If tables with the same names already exist in AnyLogic database,  you will see the warning as shown at the bottom of the figure below. You can choose whether you want to replace the existing tables with the tables from the external database, or keep the existing tables, and use different names for the imported tables.
  1. Click OK button. In the Projects view, expand the  Database item branch, and you will see the list of tables added into the AnyLogic database.


Updating data in imported database

If data in the external database have been changed, you can update data in the built-in database.

 To update data in the imported AnyLogic database

  1. In the Projects view, click the model's  Database item.
  2. In the Properties view, open the Import section and click the Update tables data link.

You can also set your built-in database to update automatically on model startup.

 To make AnyLogic database update on model startup

  1. In the Projects view, click the model's  Database item.
  2. In the Properties view, open the Import section and select the Autoupdate imported tables on model startup checkbox.