Creating Databases


Last modified: January 09, 2012

Applies to: Windows | Windows Server

The ESE database comprises one or more tables that organize data by columns and rows. The ESE database is identified by name and database ID. An ESE database looks like a single file to the Microsoft Windows operating system; however, internally the database is stored as a collection of pages. These pages contain metadata that describe the data in the database, the data itself, and one or more indices that store different orders of the data. The database may contain up to 2^31 pages, or 16 Terabytes of data for a database with 8 KB pages.

The application creates an instance of the database engine, then creates a database and attaches it to the instance. Up to 6 databases can be simultaneously attached to an instance with JetCreateDatabase or JetAttachDatabase. One or more sessions should be started within the database, because all subsequent ESE operations are performed in the context of a session. A separate session should be opened for each thread using ESE.

This procedure will initialize ESE and create a database.

To initialize ESE and create a database

  1. JetCreateInstance: Creates an instance of the database engine.

    Windows XP and later: This function is available in Windows XP and later. On Windows 2000, only one instance is supported and that instance is created implicitly

  2. JetSetSystemParameter: System parameters that the affect the physical layout such as the JET_paramLogFilePath and JET_paramSystemPath must be set before initializing the instance with JetInit. The parameters set at this stage are set for all databases created in the instance. JetSetSystemParameter is the only function that can use the instance before it is initialized with JetInit.

  3. JetInit: Initializes the instance. Instance must be initialized with JetInit before it can be used with any other functions.

  4. JetBeginSession: Creates the session for all subsequent transactions. All database transactions take place in the context of the session (JET_SESID).

  5. JetCreateDatabase: Creates the database and returns a handle to the database ID (JET_DBID).

    If the database already exists, step 5 above is replaced by the following two steps:

    1. JetAttachDatabase: Attaches the database by name to the session

    2. JetOpenDatabase: Returns the database ID that is used in subsequent database operations.

A database can be detached from one ESE instance using JetDetachDatabase and later attached to another instance with JetAttachDatabase. When the database is detached, it can be copied as a single file using standard Windows utilities. However, when the database is attached to an ESE instance it cannot be copied since ESE opens database files exclusively. Also, if the instance crashes then the database file cannot be copied alone because it needs the transaction log files associated with it to recover from that crash.