MSSQL Server CREATE database creates the DB code

Source: Internet
Author: User

MSSQL Server CREATE database creating databases Tutorial code
/*
If db_id (' test ') is NOT NULL drop database test
Go
Create DATABASE Test
On Primary (
Name=test_dat_main1
, Filename= ' D:databasetest_dat_main1.mdf '
, SIZE=3MB
, maxsize=unlimited
, FILEGROWTH=5MB
),(
Name=test_dat_main2
, Filename= ' D:databasetest_dat_main2.mdf '
, SIZE=3MB
, maxsize=unlimited
, FILEGROWTH=5MB
)
, filegroup test_dat_sub1 Default (
Name=test_dat_sub1
, Filename= ' D:databasetest_dat_sub1.mdf '
, SIZE=2MB
, maxsize=unlimited
, FILEGROWTH=5MB
),(
Name=test_dat_sub2
, Filename= ' D:databasetest_dat_sub2.mdf '
, SIZE=2MB
, maxsize=unlimited
, FILEGROWTH=5MB
)
, Filegroup test_dat_sub2 (
Name=test_dat_sub3
, Filename= ' D:databasetest_dat_sub3.mdf '
, SIZE=2MB
, maxsize=unlimited
, FILEGROWTH=5MB
)
Log On (
Name=test_log1
, Filename= ' D:databasetest_log1.ldf '
, SIZE=10MB
, maxsize=unlimited
, FILEGROWTH=10MB
),(
Name=test_log2
, Filename= ' D:databasetest_log2.ldf '
, SIZE=10MB
, maxsize=unlimited
, FILEGROWTH=10MB
)
Collate chinese_prc_ci_as
With
Db_chaining off
, trustworthy off

Grammar
CREATE DATABASE database_name
[On
{[primary] [<filespec> [,... N]
[, <filegroup> [,... N]]
[Log on {<filespec> [,... n]}]}
]
[Collate collation_name]
[With <external_access_option>]
]
[;]

To attach a database
CREATE DATABASE database_name
On <filespec> [,... N]
For {attach [with <service_broker_option>]
| Attach_rebuild_log}
[;]

<filespec>:: =
{
(
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 filegroup_name [contains FILESTREAM] [default]
<filespec> [,... N]
}

<external_access_option>:: =
{
[Db_chaining {on | off}]
[, trustworthy {on | off}]
}
<service_broker_option>:: =
{
Enable_broker
| New_broker
| Error_broker_conversations
}

Create a database snaps tutorial hot
Create DATABASE Database_snapshot_name
    on
&NBSP;&NBSP;&N bsp;     (
        name = logical_file_name,
         filename = ' os_file_name '
       ) [, ... n]
    as snapshot of Source_database_name
[;]

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.