1. 程式人生 > >第一章 資料庫的管理

第一章 資料庫的管理

if exists(select * from sysdatabases where name='E_Market')
drop database E_Market

create database E_Market
on primary
(
   name='E_Market_data',--主檔案組
   filename='D:\SQL\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\E_Market_data.mdf',
   size=5MB,
   maxsize=100MB,
   filegrowth=15%
),
filegroup FG  --建立了一個次檔案組
(
  name='E_Market2_data',
  filename='D:\SQL\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\E_Market2_data.ndf',
  size=4MB,
  filegrowth=10%
)
log on --日誌檔案
(
   name='E_Market_log',
   filename='D:\SQL\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\E_Market_log.ldf',
   size=5MB,
   filegrowth=0
),
(
   name='E_Market2_log',
   filename='D:\SQL\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\E_Market2_log.ldf',
   size=3MB,
   maxsize=100MB,
   filegrowth=10%
)
go

use E_Market
go
alter database E_Market add filegroup FG1
go


--為新建的檔案組FG1新增資料檔案

alter database E_Market  add file
(
   name='FG1_E_Market_data',
   filename='D:\SQL\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\FG1_E_Market_data.ndf',
   size=5MB,
   maxsize=100MB,
   filegrowth=10%
) to filegroup FG1
go


--將檔案組FG1設定為預設檔案組
alter database E_Market
modify  filegroup FG1 default
go


--刪除資料庫

use master   --指向當前所操作的資料庫


drop database E_Market
go


if exists(select * from sysdatabases where name='E_Market')
drop database E_Market
go