為您介紹一些不常見的SQL語句
在SQL語句中,有一些不常見的語句,但是也同樣有其獨(dú)特的功能,下面就為您介紹幾個(gè)不常見的SQL語句,供您參考。
-- 創(chuàng)建一個(gè)名為"book"的用戶數(shù)據(jù)庫,其主文件大小為120MB,初始大小為55MB
-- 文件大小增長率為10%,日志文件大小為30MB,初始大小為12MB,文件增長增量為3MB
-- 文件均存儲(chǔ)在 "D:\數(shù)據(jù)庫\" 下
create database book
on primary
(
name=book,
filename='d:\數(shù)據(jù)庫\book.mdf',
size=55,
maxsize=120,
filegrowth=10%
)
log on
(
name=book_log,
filename='d:\數(shù)據(jù)庫\book.ldf',
size=12,
maxsize=30,
filegrowth=3
)
-- 查看數(shù)據(jù)庫'book'的信息
sp_helpdb 'book'
-- 擴(kuò)充數(shù)據(jù)庫,必須大于原數(shù)據(jù)庫的大小
use book
go
alter database book
modify file
(
name=book,
size=50
)
-- 縮減數(shù)據(jù)庫
use book
go
dbcc shrinkdatabase ('book')
-- 更改數(shù)據(jù)庫為"只讀",取消"只讀"則是false
exec sp_dboption 'book','read only',true
-- 改成單用戶模式
exec sp_dboption 'book','single user',true
-- 數(shù)據(jù)庫更名,得先把數(shù)據(jù)庫改為單用戶模式
exec sp_dboption 'book','single user',true
exec sp_renamedb 'book','shu'
exec sp_dboption 'shu','single user',false
-- 刪除數(shù)據(jù)庫,得先停止對該數(shù)據(jù)庫的使用
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語句的查詢計(jì)劃
use northwind
go
set showplan_all on
go
select * from customers where customerid='BLONP'
go
set showplan_all off
-- 顯示SQL語句的所花費(fèi)磁盤活動(dòng)量
use northwind
go
set statistics io on
go
select * from customers where customerid='BLONP'
go
set statistics io off
【編輯推薦】