為您介紹一些不常見(jiàn)的SQL語(yǔ)句
在SQL語(yǔ)句中,有一些不常見(jiàn)的語(yǔ)句,但是也同樣有其獨(dú)特的功能,下面就為您介紹幾個(gè)不常見(jiàn)的SQL語(yǔ)句,供您參考。
-- 創(chuàng)建一個(gè)名為"book"的用戶(hù)數(shù)據(jù)庫(kù),其主文件大小為120MB,初始大小為55MB
-- 文件大小增長(zhǎng)率為10%,日志文件大小為30MB,初始大小為12MB,文件增長(zhǎng)增量為3MB
-- 文件均存儲(chǔ)在 "D:\數(shù)據(jù)庫(kù)\" 下
create database book
on primary
(
name=book,
filename='d:\數(shù)據(jù)庫(kù)\book.mdf',
size=55,
maxsize=120,
filegrowth=10%
)
log on
(
name=book_log,
filename='d:\數(shù)據(jù)庫(kù)\book.ldf',
size=12,
maxsize=30,
filegrowth=3
)
-- 查看數(shù)據(jù)庫(kù)'book'的信息
sp_helpdb 'book'
-- 擴(kuò)充數(shù)據(jù)庫(kù),必須大于原數(shù)據(jù)庫(kù)的大小
use book
go
alter database book
modify file
(
name=book,
size=50
)
-- 縮減數(shù)據(jù)庫(kù)
use book
go
dbcc shrinkdatabase ('book')
-- 更改數(shù)據(jù)庫(kù)為"只讀",取消"只讀"則是false
exec sp_dboption 'book','read only',true
-- 改成單用戶(hù)模式
exec sp_dboption 'book','single user',true
-- 數(shù)據(jù)庫(kù)更名,得先把數(shù)據(jù)庫(kù)改為單用戶(hù)模式
exec sp_dboption 'book','single user',true
exec sp_renamedb 'book','shu'
exec sp_dboption 'shu','single user',false
-- 刪除數(shù)據(jù)庫(kù),得先停止對(duì)該數(shù)據(jù)庫(kù)的使用
use master
go
drop database shu
-- 創(chuàng)建表
use book
create table author
(
id int primary key identity(1,1), -- 主鍵,自增
name nvarchar(20) not null, -- 非空
sex nvarchar(1) default('男') check(sex='男' or sex='女') -- 默認(rèn)'男',約束該字段只能是'男'或'女'
)
-- 查看表信息
exec sp_help author
-- 顯示SQL語(yǔ)句的查詢(xún)計(jì)劃
use northwind
go
set showplan_all on
go
select * from customers where customerid='BLONP'
go
set showplan_all off
-- 顯示SQL語(yǔ)句的所花費(fèi)磁盤(pán)活動(dòng)量
use northwind
go
set statistics io on
go
select * from customers where customerid='BLONP'
go
set statistics io off
【編輯推薦】


















