T-SQL statement creation Database

Source: Internet
Author: User

I recently reviewed the database (SQL Server), so I wrote some examples, which are the most basic things... (Don't laugh ...)
It is also convenient for beginners to learn sqlserver...

I,
Create a database
Example1
Create a database sample. Main dataFileSample_dat.
Create Database sample
On Primary
(Name = sample_dat,
Filename = 'd: \ SQL \ sample_data.mdf ',
Size = 5,
Maxsize = 5,
Filegrowth = 10)
Note: the location of the main data file is D: \ SQL \ sample_data.mdf. Because the capacity unit is not specified for the main file,SystemThe default value is mb. Therefore, the initial size of the primary data file is 5 MB, and the maximum size is 50 MB. The increase is 10 MB.
Because no log file is specified during creation, the system automatically creates a log file with an initial capacity of 1.25mb without the maximum capacity limit (the system automatically creates logs, the capacity is smaller than 25% of the total capacity of KB and all data files ).

 

 

Example 2
Create a database that contains only one database file and one log file. The database name is sales, the logical File Name of the data file is sales_data, the operating system name of the data file is sales_data.mdf, and the initial size is 10 MB. The maximum size can be increased to 500 mb, an increase of 10%. The logic of the log file is sales_log, the operating system is sales_log.ldf, the initial size is 5 MB, and the maximum value is 100 MB, the log file size increases by 2 MB.
Create Database sales
On
(Name = sales_data,
Filename = 'd: \ SQL \ sales_data.mdf ',
Size = 10 MB,
Max size = 500 mb,
Filegrowth = 10%)
Log On
(Neme = sales_log,
Filename = 'd: \ SQL \ sales_log.ldf ',
Size = 5 MB,
Max size = 100 MB,
Filegrowth = 2 MB)
Note: because the primary keyword is omitted, the first file sales_data.mdf is the main data file by default.

 

 

Example 3
Create a database that contains multiple data files and logs. The database name student contains three data files with an initial size of 10 MB and two 8 Mb log files.
Create Database student
On Primary
(Name = std_dat1,
Filename = 'd: \ SQL \ student1.mdf ',
Size = 10 MB,
Max size = 200 MB,
Filegrowth = 20 ),
(Name = std_dat2,
Fliename = 'd: \ SQL \ student2.ndf ',
Size = 10 MB,
Max size = 200 MB,
Filegrowth = 20 ),
(Name = std_dat3,
Filename = 'd: \ SQL \ student3.ndf ',
Size = 10 MB,
Max size = 200 MB,
Filegrowth = 20)
Log On
(Name = std_log1,
Filename = 'd: \ SQL \ stdlog1.ldf ',
Size = 8 Mb,
Max size = 100 MB,
Filegrowth = 10 MB ),
(Name = std_log2,
Filename = 'd: \ SQL \ sedlog2.ldf ',
Size = 8 Mb,
Max size = 100 MB,
Filegrowth = 10 MB)
Description: The file extension used in the filename option. The main data file uses. MDF, the secondary data file uses. NDF, and the log file uses. LDF.

 

 

Example 4
Create a database that contains two file groups. The database name is business. The main file group contains two data files: business_dat1 and business_dat2. The file group business_group contains the data file business_dat3. The database also contains a log file business_log.
Cteate Database Business
On Primary
(Name = business_dat1,
Filename = 'd: \ SQL \ businessdat1.mdf ',
Size = 10 MB,
Maxsize = 50 MB,
Filegrowth = 10 ),
(Name = business_dat2,
Filename = 'd: \ SQL \ businessdat2.ndf ',
Size = 10 MB,
Maxsize = 50 MB,
Filegrowth = 10 ),
Filegroup business_group
(Name = business_dat3,
Filename = 'd: \ SQL \ businessdat3.ndf ',
Size = 10 MB,
Maxsize = 50 MB,
Filegrowth = 10)
Log On
(Name = business_log,
Filename = 'd: \ SQL \ businesslog. ldf ',
Size = 8 Mb,
Max size = 100 MB,
Filegrowth = 10 MB)
Note: Here, "filegrowth = 10" is different from "filegrowth = 10 MB". If you do not specify the unit, it indicates that the increase is calculated by percentage. Otherwise, it is calculated by "10 MB.

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.