SQLSERVER2 database implementation

Source: Internet
Author: User
1. database creation syntax createdatabase database name on [primary] (data file parameter [, n] [file group parameter]) [LOGON] (log file parameter [, n]) note: [] indicates the optional part, and {} indicates that you need to create some database instances: createdatabaseNetBarDBonprimary -- default

1. create database Syntax: create database name on [primary] (data file parameter [, n] [file group parameter]) [log on] (LOG file parameter [, n]) Note: "[]" indicates the optional part, and "{}" indicates that some database instances need to be created: create database NetBarDB on primary -- default

1. database creation syntax

Create database Name

On [primary]

(

<数据文件参数> [,... N] [ <文件组参数> ]

)

[Log on]

(

<日志文件参数> [,... N]

)

Note:

"[]" Indicates the optional part, and "{}" indicates the required part.

Create a database instance:

Create database NetBarDB

On primary -- by default, it belongs to the primary main file group, server space, U.S. server, which can be omitted

(

Name = 'netbar _ data', -- Logical name of the master data file

Filename = 'e: \ NetBar_mdf.mdf ', -- physical name of the master data file

Size = 3 mb, -- initial size of the master data file

Maxsize = 100 mb, -- maximum growth of the master data file

Filegrowth = 15% -- growth rate of the master data file

)

Syntax for creating database data files and log files:

Create database Name

On

{

NAME = logical NAME,

FILENAME = Name of the physical file,

SIZE = file SIZE,

MAXSIZE = maximum file length,

FILEGROWTH = automatic Growth

}

Log on

{

...........................

}

2. delete database Syntax:

Drop database name;

Delete multiple databases:

Drop database name 1, database name 2,... database name n;

Note:

Deleting a database using the drop statement will delete the database.

Disk related to the database to be deleted

Files, virtual hosts, such as data files and log files

Example of deleting a database:

If exists (select * from sysdatabases where)

Drop database NetBarDB

Go

Or:

If DB_ID ('netbardb') is not null

Drop database NetBarDB

Go

3. Table creation Syntax:

Create table Name

(

Field 1 Data Type field features,

Field 2 Data Type field features,

......

Field n data type field features,

)

4. Modify the table Syntax:

Add column:

Alter table name

Add {Field Data Type field feature} [,... n]

Delete column:

Alter table name

Drop column {field} [,... n]

Modify columns:

Alter table name

Alter column field data type [null | not null]

5. Table deletion Syntax:

Drop table Name

6. SQL Server constraints:

Purpose: To ensure the complete type of data in the table.

Related Article

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.