Home >Database >Mysql Tutorial >SQL Server 数据库创建

SQL Server 数据库创建

WBOY
WBOYOriginal
2016-06-07 14:50:161066browse

1.用SQL语言创建一个带有主数据库文件、数据库文件组、主日志、副日志文件的数据库 2.用SQL语言查询刚创建的数据库 3.用SQL语言对刚创建的数据库增加一个文件组 ----------------------------------若存在同名数据库,则删除数据库USE masterIF EXISTS(SELEC

1.用SQL语言创建一个带有主数据库文件、数据库文件组、主日志、副日志文件的数据库

2.用SQL语言查询刚创建的数据库

3.用SQL语言对刚创建的数据库增加一个文件组

--------------------------------
--若存在同名数据库,则删除数据库
USE master
IF EXISTS(SELECT * from sysdatabases WHERE name='Market')
DROP DATABASE Market
GO
--------------------------------
--创建数据库
--------------------------------
CREATE DATABASE Market

ON PRIMARY--主文件组
(
	NAME='Market_data.mdf',
	FILENAME='D:\SQLProject\Market_data.mdf',
	SIZE=5MB,
	FILEGROWTH=10%,
	MAXSIZE=100MB
),
FILEGROUP FG--文件组
(
	NAME='FG_Market.ndf',
	FILENAME='D:\SQLProject\Market_data.ndf',
	SIZE=10MB,
	FILEGROWTH=10%,
	MAXSIZE=100MB
)

LOG ON--日志
(
	NAME='Market_log.ldf',
	FILENAME='D:\SQLProject\Market_log.ldf',
	SIZE=2MB,
	FILEGROWTH=0
),
(
	NAME='Market2_log.ldf',
	FILENAME='D:\SQLProject\Market2_log.ldf',
	SIZE=5MB,
	FILEGROWTH=0
)
GO
-----------------------------------

-----------------------------------
--设置默认文件组
ALTER DATABASE Market
MODIFY FILEGROUP FG DEFAULT
GO
-----------------------------------

-----------------------------------
--查询所有数据库
SELECT * FROM sysdatabases
GO
-----------------------------------

-----------------------------------
--对数据库做局部修改
--增加一个文件组
USE Market
ALTER DATABASE Market ADD FILEGROUP FG2
GO

ALTER DATABASE Market ADD FILE
(
	NAME='FG2_Market_data.ndf',
	FILENAME='D:\SQLProject\FG2_Market_data.ndf',
	SIZE=10MB,
	FILEGROWTH=10%,
	MAXSIZE=100MB
)TO FILEGROUP FG2

GO
------------------------------------

操作运行结果:





Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn