Creating a Database (Creating Metadata)
Go Up to Creating Metadata
CREATE DATABASE
establishes a new database and its associated system tables, which describe the internal structure of the database. SQL programs can select the data in most of these tables just as in any user-created table.
In its most elementary form, the syntax for CREATE DATABASE
is:
EXEC SQL CREATE DATABASE '<filespec>';
CREATE DATABASE
must appear before any other CREATE
statements. It requires one parameter, the name of a database to create. For example, the following statement creates a database named countries.ib
:
EXEC SQL CREATE DATABASE 'countries.ib';
The database name can include a full file specification, including both host or node names, and a directory path to the location where the database file should be created. For information about file specifications for a particular operating system, see the operating system manuals.
Although InterBase enables access to remote databases, you should always create a database directly on the machine where it is to reside.
Optional Parameters
There are optional parameters for CREATE DATABASE
. For example, when an application running on a client attempts to connect to an InterBase server in order to create a database, it may be expected to provide USER
and PASSWORD
parameters before the connection is established. Other parameters specify the database page size, the number and size of multi-file databases, and the default character set for the database.
For a complete discussion of all CREATE DATABASE
parameters, see the Data Definition Guide. For the complete syntax of CREATE DATABASE
, see Language Reference Guide.
An application that creates a database must be preprocessed with the
gpre -m
switch. It must also create at least one table. If a database is created without a table, it cannot be successfully opened by another program. Applications that perform both data definition and data manipulation must declare tables with DECLARE TABLE
before creating and populating them. For more information about table creation, see Creating a Table.Specifying a Default Character Set
A default character set designation of a database specifies the character set the server uses to transliterate and store CHAR
, VARCHAR
, and text Blob data in the database when no other character set information is provided. A default character set should always be specified for a database when it is created with CREATE DATABASE
.
To specify a default character set, use the DEFAULT CHARACTER SET
clause of CREATE DATABASE
. For example, the following statement creates a database that uses the ISO8859_1 character set:
EXEC SQL CREATE DATABASE 'europe.ib' DEFAULT CHARACTER SET ISO8859_1;
If you do not specify a character set, the character set defaults to NONE
. Using character set NONE
means that there is no character set assumption for columns; data is stored and retrieved just as you originally entered it. You can load any character set into a column defined with NONE
, but you cannot later move that data into another column that has been defined with a different character set. In this case, no transliteration is performed between the source and destination character sets, and errors may occur during assignment.
For a complete description of the DEFAULT CHARACTER SET
clause and a list of the character sets supported by InterBase, see the Data Definition Guide.