The master database should be backed up whenever a user database is created, modified, or dropped.
The CREATE DATABASE statement must run in autocommit mode (the default transaction management mode) and is not allowed in an explicit or implicit transaction. For more information, see Autocommit Transactions.
You can use one CREATE DATABASE statement to create a database and the files that store the database. SQL Server implements the CREATE DATABASE statement by using the following steps:
-
The SQL Server 2005 Database Engine uses a copy of the model database to initialize the database and its metadata.
-
A service broker GUID is assigned to the database.
-
The Database Engine then fills the rest of the database with empty pages, except for pages that have internal data that records how the space is used in the database. For more information, see Database File Initialization.
A maximum of 32,767 databases can be specified on an instance of SQL Server.
Each database has an owner that can perform special activities in the database. The owner is the user that creates the database. The database owner can be changed by using sp_changedbowner (Transact-SQL).
Database Files and Filegroups
Every database has at least 2 files, a primary file and a transaction log file, and at least one filegroup. A maximum of 32,767 files and 32,767 filegroups can be specified for each database. For more information, see Physical Database Files and Filegroups.
When you create a database, make the data files as large as possible based on the maximum amount of data you expect in the database. For more information, see Using Files and Filegroups to Manage Database Growth.
We recommend that you use a Storage Area Network (SAN), iSCSI-based network, or locally attached disk for the storage of your SQL Server database files, because this configuration optimizes SQL Server performance and reliability. By default, using network database files (stored on a networked server or network-attached storage) is not enabled for SQL Server. However, you can create a database that has network-based database files by using trace flag 1807. For information about this trace flag and important performance and maintenance considerations, see this Microsoft Web site.
Database Snapshots
You can use the CREATE DATABASE statement to create a read-only, static view, a database snapshot, of an existing database, the source database. A database snapshot is transactionally consistent with the source database as it existed at the time when the snapshot was created. A source database can have multiple snapshots.
Note: |
|---|
|
When you create a database snapshot, the CREATE DATABASE statement cannot reference log files, offline files, restoring files, and defunct files. |
If creating a database snapshot fails, the snapshot becomes suspect and must be deleted. For more information, see DROP DATABASE (Transact-SQL).
Each snapshot persists until it is deleted by using DROP DATABASE.
For more information, see Database Snapshots.
Database Options
Several database options are automatically set whenever you create a database. For a list of these options and their default settings, see Setting Database Options. These options can be modified using the ALTER DATABASE statement.
The model Database and Creating New Databases
All user-defined objects in the model database are copied to all newly created databases. You can add any objects, such as tables, views, stored procedures, data types, and so on, to the model database to be included in all newly created databases.
When a CREATE DATABASE database_name statement is specified without additional size parameters, the primary data file is made the same size as the primary file in the model database.
Unless FOR ATTACH is specified, each new database inherits the database option settings from the model database. For example, the database option auto shrink is set to true in model and in any new databases you create. If you change the options in the model database, these new option settings are used in any new databases you create. Changing operations in the model database does not affect existing databases. If FOR ATTACH is specified on the CREATE DATABASE statement, the new database inherits the database option settings of the original database.
Viewing Database Information
You can use catalog views, system functions, and system stored procedures to return information about databases, files, and filegroups. For more information, see Viewing Database Metadata.