Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

SQL expand database (command execution)

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Name logical file name, filename physical file name, size initial size, maxsize maximum, filegrowth growth. The default unit for the last three quantities is MB.

?

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

13 create database MyNewDB

On

(name=Lzh_dat1

Filename='E:\ Source Program\ CreatTest\ Lzh_dat1.mdf'

Size=10MB

Maxsize=30MB

Filegrowth=5MB)

Log on

(name=lzh_log1

Filename='E:\ Source Program\ CreatTest\ lzh_log1.ldf'

Size=3MB

Maxsize=unlimited

Filegrowth=3MB)

Here are the files in this filegroup after on, and the log files after log on (log space and data space are managed separately). In this way, because there is only one filegroup, the first file is recognized as the primary data file.

Note that the primary data file .MDF, the secondary data file .ndf, and the log file .ldf are all recommended extensions, and other extensions can be used, so what the file is depends on the location in the creation statement.

Create a database with multiple filegroups

The syntax is similar, where the on primary block is the primary filegroup, and the first file is the primary data file. Note that multiple data files or log files should be separated by commas.

?

one

two

three

four

five

six

seven

eight

nine

ten

eleven

twelve

thirteen

fourteen

fifteen

sixteen

seventeen

eighteen

nineteen

twenty

twenty-one

twenty-two

twenty-three

twenty-four

twenty-five

twenty-six

twenty-seven

twenty-eight

twenty-nine

thirty

thirty-one

thirty-two

thirty-three

thirty-four

thirty-five

thirty-six

thirty-seven

thirty-eight

thirty-nine

40 create database MyNewDB

On primary

(name=Lzh_dat1

Filename='E:\ Source Program\ CreatTest\ Lzh_dat1.mdf'

Size=10MB

Maxsize=30MB

Filegrowth=5MB)

(name=Lzh_dat2

Filename='E:\ Source Program\ CreatTest\ Lzh_dat2.ndf'

Size=5MB

Maxsize=20MB

Filegrowth=4MB)

Filegroup LzhGroup2

(name=Lzh_dat3

Filename='E:\ Source Program\ CreatTest\ Lzh_dat3.ndf'

Size=7MB

Maxsize=20MB

Filegrowth=3MB)

Filegroup LzhGroup3

(name=Lzh_dat4

Filename='E:\ Source Program\ CreatTest\ Lzh_dat4.ndf'

Size=10MB

Maxsize=30MB

Filegrowth=5MB)

(name=Lzh_dat5

Filename='E:\ Source Program\ CreatTest\ Lzh_dat5.ndf'

Size=20MB

Maxsize=30MB

Filegrowth=2MB)

Log on

(name=lzh_log1

Filename='E:\ Source Program\ CreatTest\ lzh_log1.ldf'

Size=3MB

Maxsize=unlimited

Filegrowth=3MB)

Expand the database space

If there is not enough data space, you can no longer insert data, and if there is not enough log space, you can no longer modify the database (because you need to write to the log file). There are two ways to expand the database space: adding new files to the database and expanding the size of existing files in the database.

① adds a new file to the database

?

one

two

three

4 ALTER DATABASE database name

ADD [LOG] FILE

(file parameter table)

[filegroup name that already exists in TO FILEGROUP or DEFAULT indicates default filegroup]

For example:

?

one

two

three

four

five

six

7 alter database MyNewDB

Add file (

Name=newlzh_dat1

Filename='E:\ Source Program\ CreatTest\ newlzh_dat1.ndf'

Size=6mb

Filegrowth=0)

To filegroup LzhGroup2

② expands existing file size

At this point, ADD will be changed to MODIFY. Note that the file name here is used to find the file you want to expand, not to change the file name.

?

one

two

three

four

5 alter database MyNewDB

Modify file (

Name=newlzh_dat1

Size=8MB

)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report