Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

CREATE DATABASE

SQL Server 2000

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

Note  To execute the CREATE DATABASE statement, you must be connected to a database. For information about connecting to a database, see Using SQL Server CE Query Analyzer.

Syntax
CREATE DATABASE database_name 
   [DATABASEPASSWORD 'database_password' 
      [ENCRYPTION {ON|OFF}] 
   ]
   [COLLATE collation_name comparison_style] 
database password ::= identifier
Arguments
database_name
Is the name of the new database. database_name 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. The file extension for a database name in Microsoft® SQL Server™ 2000 Windows® CE Edition (SQL Server CE) is .sdf.
'database_password'
Is the name of the password that allows for the database to be opened. SQL Server CE returns an error if a user connects to a password-protected database without a password. database_password must be enclosed in single quotation marks.

If the optional ENCRYPTION ON keyword is passed, the database is encrypted with 128-bit encryption.

collation_name
Specifies the default collation for the database. collation_name can only be a Windows collation. If collation_name is not specified, the database is assigned the default collation of the device. For a list of collation names, see COLLATE.
comparison_style
Specifies the comparison style of characters. SQL Server CE supports only CI_AS (case insensitive and accent sensitive).

collation_name and comparison_style must not be enclosed in single or double quotation marks.

Examples
A. Creating a password-protected database

The following example creates a database with a password.

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

When a user tries to connect to a password-protected database without supplying the correct password, SQL Server CE returns this error:

Error: 0x80040e4d DB_SEC_E_AUTH_FAILED
Minor Error: (25028)
Description: Authentication failed.
Interface defining error: IID_IDBInitialize
Param. 0:0
Param. 1:0
Param. 2:0
Param. 3:
Param. 4:
Param. 5:

For information about errors, see SQL Server CE Errors.

B. Creating a database with a collation specified

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

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

Show:
© 2015 Microsoft