Sqlcreatedatabase create database Command

Source: Internet
Author: User
Tags filegroup
The createdatabase command is the most basic thing for beginners to get started with databases. Without it, you won't be able to continue learning. Why don't I leave it alone? Now let's take a look at the syntax of this command.

The create database Command is the most basic thing for beginners to get started with the database. Without it, you cannot go on to learn why I will not talk about it. Now, let's take a look at the syntax of this command.

The complete create database Command syntax is as follows:

The Code is as follows:

Create database database_name
[ON
{[PRIMARY] [ [,... N]
[, [,... N]
[Log on { [,... N]}
]
[COLLATE collation_name]
[ ]
]
[;]

To attach a database
Create database database_name
ON [,... N]
FOR {ATTACH [ ]
| ATTACH_REBUILD_LOG}
[;]

: =
{
(
NAME = logical_file_name,
FILENAME = {'OS _ file_name' | 'filestream _ path '}
[, SIZE = size [KB | MB | GB | TB]
[, MAXSIZE = {max_size [KB | MB | GB | TB] | UNLIMITED}]
[, FILEGROWTH = growth_increment [KB | MB | GB | TB | %]
) [,... N]
}

: =
{
FILEGROUP filegroup_name [contains filestream] [DEFAULT]
[,... N]
}

: =
{
[DB_CHAINING {ON | OFF}]
[, TRUSTWORTHY {ON | OFF}]
}
: =
{
ENABLE_BROKER
| NEW_BROKER
| ERROR_BROKER_CONVERSATIONS
}

Create a database snhot
Create database database_snapshot_name
ON
(
NAME = logical_file_name,
FILENAME = 'OS _ file_name'
) [,... N]
As snapshot of source_database_name
[;]


Instance

The Code is as follows:
Create database temporary
ON
(NAME = 'temporary _ data ',
FILENAME = 'H: temporary. mdf ',
SIZE = 5 MB,
MAXSIZE = 50 MB,
FILEGROWTH = 10%
)
LOG ON
(
NAME = 'temporary _ log ',
FILENAME = 'H: temporary. ldf ',
SIZE = 2 MB,
MAXSIZE = 5 MB,
FILEGROWTH = 1 MB
)

In fact, we only use some basic creation functions.

Database_name
The name of the new database. The database name must be unique in the SQL Server instance and comply with the identifier rules.

Unless the logical name is not specified for the log file, database_name can contain a maximum of 128 characters. If the logical log file name is not specified, SQL Server will append the suffix to database_name to generate logical_file_name and OS _file_name for the log. This limits database_name to 123 characters, so that the name of the generated logical file cannot exceed 128 characters.

If no data file name is specified, SQL Server uses database_name as logical_file_name and OS _file_name. The default path is obtained from the registry. You can use "server properties" ("database Settings" Page) in Management Studio to change the default path. To change the default path, restart SQL Server.

In fact, we can create databases more conveniently, such

The Code is as follows:

Crate database 111cn.net

If the reference system is not specified, it will be under your sqldata directory by default.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.