Mathematica 8 is now available

Creating Databases Using Database Access Kit

download notebookDownload this example as a Mathematica notebook.

Introducing a New Database

The creation of a new database can be done only through the ODBC control panel.

  1. Open the ODBC control panel. From the Windows Start button, select Settings and then Control Panel. Double-click the ODBC icon. You will be presented with the ODBC Data Source Administrator, or similarly titled, window.

    [Graphics:Images/index_gr_1.gif]

  2. To view the list of available database drivers, click the Add button in the ODBC Data Source Administrator window.

  3. Choose Microsoft Access Driver (to connect to a Microsoft Access database), and then click Finish.

    [Graphics:Images/index_gr_2.gif]

  4. Type "dbcreate" into the Data Source Name field and "dbcreate database example" next to Description. Click the Create button.

    [Graphics:Images/index_gr_3.gif]

  5. Type "dbcreate.mdb" into the field for Database Name. Place this database in a directory by choosing, for example, the \Windows\temp directory found within the Windows folder in the Directories list. Click OK.

    [Graphics:Images/index_gr_4.gif]

  6. A dialog box confirming the successful completion of the database should appear. If it does, click OK in this and each successive window until the control panel is closed.

    [Graphics:Images/index_gr_5.gif]


Filling the New Database

To create the structure of the database, first load Database Access Kit and open the database.

[Graphics:Images/index_gr_6.gif]

[Graphics:Images/index_gr_7.gif]

[Graphics:Images/index_gr_8.gif]

Next, create a table and its columns.

[Graphics:Images/index_gr_9.gif]

Enter three rows of data in the "employees" table, using the SQLInsert function three times, with different data values each time.

[Graphics:Images/index_gr_10.gif]

This process can also be automated for any list using just a couple of lines of code.

[Graphics:Images/index_gr_11.gif]

The new function addEmployee takes either a name or a list of names. It could easily be generalized to read the names from a file, from another database table, or off the web. It could also be modified to take the column name as a variable or assign it to a button.

[Graphics:Images/index_gr_12.gif]

The next line adds these four names to the database dbcreate.

[Graphics:Images/index_gr_13.gif]

View the "employees" table with column headings. Each of the column names has a space in the name as defined.

[Graphics:Images/index_gr_14.gif]
emp_id emp_lname emp_fname
0001 Isaac Newton
0002 George Washington
0003 Jesse James
0004 Donald Tubbs
0005 Claire Mulligan
0006 Peter Fontane
0007 Julie Debussy

Close the data source.

[Graphics:Images/index_gr_15.gif]