查詢數(shù)據(jù)庫
- 查詢所有數(shù)據(jù)庫
exec sp_helpdb;
- 查詢數(shù)據(jù)庫test
exec sp_helpdb test;
- 查詢數(shù)據(jù)庫視圖
select * from sys.databases;
創(chuàng)建數(shù)據(jù)庫
- 創(chuàng)建數(shù)據(jù)庫(默認)
create database mydb;
- 創(chuàng)建包含兩個數(shù)據(jù)文件組火架,兩個日志文件的數(shù)據(jù)庫mydb。
create database mydb
on
/*默認為primary文件組*/
primary
(
name=mydb_dat1,
filename='G:\programs\SQL server\mydb_dat1.mdf',
size=10MB,
maxsize=20MB, /*默認unlimited*/
filegrowth=50%
),
(
name=mydb_dat2,
filename='G:\programs\SQL server\mydb_dat2.ndf',
size=10MB,
maxsize=20MB,
filegrowth=50%
),
/*文件組mydb_gro*/
filegroup mydb_gro
(
name=mydb_dat3,
filename='G:\programs\SQL server\mydb_dat3.ndf',
size=10MB,
maxsize=20MB,
filegrowth=50%
)
log on
(
name=mydb_log1,
filename='G:\programs\SQL server\mydb_log1.ldf',
size=10MB,
maxsize=20MB,
filegrowth=50%
)
- 進入數(shù)據(jù)庫
use mydb;
修改數(shù)據(jù)庫
- 移除文件踩窖。
alter database mydb
remove file mydb_dat2;
- 添加文件到文件組mydb_gro
alter database mydb
add file
(
name=mydb_dat2,
filename='G:\programs\SQL server\mydb_dat2.ndf',
size=10MB,
maxsize=20MB,
filegrowth=50%
)
to filegroup mydb_gro;
- 刪除數(shù)據(jù)庫
drop database mydb;