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.