Create a database using SQL statements

Source: Internet
Author: User
1. createdatabasedataname this is the easiest way to create a database. all attributes of the database are default. such as database files and log file storage directories. database size. the following describes the clauses that often determine database attributes. on: defines the location of the stored database file. See the following code. filename: Database Logic

1. create database dataname this is the easiest way to create a database. all attributes of the database are default. such as database files and log file storage directories. database size. the following describes the clauses that often determine database attributes. on: defines the location of the stored database file. See the following code. filename: Database Logic

1. create database dataname
This is the easiest way to create a database. All attributes of the database are default, such as the database file and log file storage directory and database size.
The following describes the clauses that often determine database attributes.

  1. On: defines the location of the stored database file. See the following code.
  2. Filename: Logical alias of the database
  3. Size: initial database size
  4. Maxsize: the initial capacity of the database.
  5. Filegrowth: the size of the database added each time.
  6. Log on: defines the location for storing database log files.


Check the creation code:

  1. Create database Accounting
  2. On (name = 'accountingname ',
  3. Filename = 'f:/Summary/SQL/create and modify a data table/Accounting. mbdf ',
  4. Size = 10 mb,
  5. Maxsize = 50 mb,
  6. Filegrowth = 5 mb)
  7. Log on (name = 'accountinglog ',
  8. Filename = 'f:/Summary/SQL/create and modify a data table/Accounting. log ',
  9. Size = 10 mb,
  10. Maxsize = 50 mb,
  11. Filegrowth = 5 mb)

As mentioned above, filegrowth: the size of the database increases every time combined with the code. the initial database size is 10 MB. when the database capacity exceeds. it automatically increases by 5 MB. this will be the size of 15 MB. up to 50 mb

Create database song on
(Name = ktvdata, filename = 'd:/database/ktvdata. mdf ',
Size = 8 MB, maxsize = 9 MB, filegrowth = 100KB)
Log on
(Name = ktvdata_log, filename = 'd:/database/ktvdata. ldf ',
Size = 9 MB, maxsize = 10 MB, filegrowth = 100KB)
Go

2. Use the alter database statement to modify the DATABASE
Example 4-3 add two data files and one transaction log file to the test database.
The program list is as follows:

Alter database Test
ADD FILE
(NAME = Test1, FILENAME = 'C:/Program Files/Microsoft SQL Server/MSSQL/Data/test1.ndf ', SIZE =

5 MB, MAXSIZE = 100 MB, FILEGROWTH = 5 MB ),
(NAME = Test2, FILENAME = 'C:/Program Files/Microsoft SQL Server/MSSQL/Data/test2.ndf ', SIZE =

3 MB, MAXSIZE = 10 MB, FILEGROWTH = 1 MB)
GO
Alter database Test
Add log file (NAME = testlog1, FILENAME = 'C:/Program Files/Microsoft SQL

Server/MSSQL/Data/testlog1.ldf ', SIZE = 5 MB, MAXSIZE = 100 MB, FILEGROWTH = 5 MB)
GO

3. Rename test as demo.
Sp_renamedb 'test', 'Demo'

4. delete a database: drop database song
Go

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.