Building a database using SQL statements
Create a database with three names, the first is the database name after create, the second is the logical name of name, and the third is the physical name of filename.
A. Creating a database that does not specify a file
Create database TestDB--testdb The name--dbms in this name.
B. Creating a database that specifies data and transaction log files
Create database TestDB--testdb The name--dbms in this name.
On--on represents the data file group
(--Main data file
name = ' TestDB ',--logical name
Filename = ' D:\Program files\mssql\data\testdb.mdf ',--Physical name
Size =3MB,--Initial size
Maxsize =10MB,--Upper limit
FileGrowth =1MB--1Mb per increase
),
(--Secondary data file
Name = ' testdb1.ndf ',
Filename = ' D:\Program files\mssql\data\testdb1.ndf ',
Size =3MB,
Maxsize =10MB,
FileGrowth =10%
)
Log on--Journal file
(
Name = ' Testdb_log ',
Filename = ' D:\Program files\mssql\data\testdb_log. LDF ',
Size =3MB,
Maxsize =10MB,
FileGrowth =10%
)
Go (--end of statement)
MDF Master file: All databases must have a primary database file. The main deposit is not only used to save data for the database, but also to store the location of all other files that make up the database.
NDF files: There can be multiple, mainly saving data, but not saving system data.
LDF log file: It is recommended to create more than one file, primarily to save the user's actions on the database, which can be used to recover data.
Building a database using SQL statements