SQL server commands to create, modify, delete database

1. Create a database: create

Example 1: requires the creation of a student - course database (name of student).

Create database student

Example 2: requires the creation of a student in a local disk D - course database (named student1), only one data file and log files, file names are stu and stu_log, initial size are 3MB, growth was 10%, and 1MB The data files up to 500MB, the log file size is unlimited.

CREATE   DATABASE  student1
ON
( NAME = stu, 
FILENAME = 'D:\stu.mdf' , 
SIZE = 3MB , 
MAXSIZE = 500MB , 
FILEGROWTH = 10%)
 LOG ON 
( NAME = stu_log, FILENAME = 'D:\stu_log.ldf' , SIZE = 3MB , MAXSIZE = unlimited,FILEGROWTH = 1MB )

Examples

----------------------------------------------------------------
IF EXISTS(SELECT * FROM sysdatabases WHERE name='student')
DROP DATABASE student
GO
CREATE DATABASE student --创建数据库
ON PRIMARY --定义在主文件组上的文件
(NAME=stu_date, --逻辑名称
FILENAME='C:\sql\student.mdf', --物理名称
SIZE=10, --初始大小为10mb
MAXSIZE=unlimited, --最大限制为无限大
FILEGROWTH=10%) --主数据文件增长幅度为10%
LOG ON --定义事务日志文件
(NAME=stu_log, --逻辑名称
FILENAME='C:\sql\student.ldf', --物理名称
SIZE=1, --初始大小为1mb
MAXSIZE=5, --最大限制为5mb
FILEGROWTH=1) --事务日志增长幅度为1mb`
-----------------------------------------------------------------

2. Modify the database: alter

Example 3: student database to modify the properties of an existing data file, the maximum size of the main data file to 50MB, each 2MB growth to growth.

Alter database student1
modify file (name=stu,maxsize=50mb,filegrowth=2mb)

3. Delete the database: drop

Example 4: delete student database, the following statement may be used.

DROP DATABASE student

Guess you like

Origin www.cnblogs.com/CGGG/p/12556433.html