T-SQL database-Delete and change

Source: Internet
Author: User

Creation of databases: CREATE DATABASE Data_name

         On primary

(

           name=data_1,

           F ilename= ' D\data\data_name.mdf ',

           size=50MB,

           maxsize=unlimited,

           filegrowth=10%

)

         Log on

(

           name=data_2,

           filename= ' d\data\data_name.ldf ',

           size=30MB,

           maxsize=unlimited,

           filegrowth=2MB

)

Explain:

Create a database named Data_ name

The main file name is data_1, the storage location is the D disk under the data file Data_name.mdf, the file size is 50MB, the maximum is unlimited, growth rate of 10%

The log file name is data_2, the storage location is the D disk under the data file Data_name.ldf, the file size is 30MB, the maximum is unlimited, the growth rate of 2MB

    

Deletion of databases:drop Database Data_name

  

Modifications to the database:

Modify database name:exec sp_renamedb ' data_name_old ', ' data_name_new ';

Add a new data file to the database:alter database Data_name

Add File

(

                  name=new_file,

                  filename= ' d\data\new_file.mdf ',

                  size=10MB,

                  maxsize=unlimited,

                  filegrowth=10MB

)

Modify the file size in the database:

Increase data files and log files:ALTER DATABASE Data_name

                  Modify File

(

                    name=new_file,

                    size=100MB

)

      Note: This method can only increase the size of the file, can not be reduced, or will error!

      To narrow down the data and log files:

                  DBCC SHRINKFILE (file_name,30)

      

T-SQL database-Delete and change

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.