CREATE DATABASE (SQL Server Compact)

Creates a new database and the file that is used to store the database.

Syntax

CREATE DATABASE databaseName 
   [DATABASEPASSWORD '<enterStrongDatabasePasswordHere>' 
      
   ]
   [COLLATE collationName comparisonStyle] 
database password ::= identifier

Arguments

  • databaseName
    The name of the new database. The databaseName argument is a file name and is restricted by the naming and size limitations of the operating system. Any valid character that can be used in a file name can be used for the database name. If a path name is not specified, the database is created in the current directory. By default, the file name extension for a database name in SQL Server Compact 4.0 is .sdf.

  • '<enterStrongDatabasePasswordHere>'
    SQL Server Compact 4.0 returns an error if a user connects to a password-protected database without a password. The database password must be enclosed in single quotation marks.

  • collationName
    Specifies the default collation for the database. The collationName argument can only be a Windows collation. If collationName is not specified, the database is assigned the default collation of the device. For a list of collation names, see COLLATE (SQL Server Compact).

  • comparisonStyle
    Specifies the comparison style of characters. The collationName and comparisonStyle parameters must not be enclosed in single or double quotation marks. SQL Server Compact 4.0 supports only CI_AS (case insensitive and accent sensitive) through the CREATE DATABASE statement. .

Note

In the SQL Server Compact 4.0 release, case-sensitive collations are also supported. However, this support is only available through the native and managed programming APIs. For more information, see Working with Collations (SQL Server Compact) and Supported Collations (SQL Server Compact).

Remarks

To execute the CREATE DATABASE statement, you must be connected to a database. For information about how to connect to a database, see SQL Server Compact Query Analyzer.

Code Example

A. Creating a password-protected database

The following example creates a database that uses a password.

CREATE DATABASE "\test1.SDF" DATABASEPASSWORD '<enterStrongPasswordHere>'

When a user tries to connect to a password-protected database without supplying the correct password, SQL Server Compact 4.0 returns an error..

B. Creating a database that has a collation specified

The following example specifies a specific collation for the database being created.

CREATE DATABASE "SpanishDB.sdf" DATABASEPASSWORD '<enterStrongPasswordHere>' COLLATE Traditional_Spanish_CI_AS

Note   When you create a new database, make sure that the correct collation is specified. If a table name is long and has mixed characters such as English and Japanese, the table might not be recognized in the subsequent connections to the database.