網(wǎng)(LieHuo.Net)教程 SQL SERVER是一款非常好的數(shù)據(jù)庫軟件,SQL語句是我們經(jīng)常用到的,今天就來總結(jié)一些不是很常用的SQL語句。
以下為引用的內(nèi)容: -- 創(chuàng)建一個名為"book"的用戶數(shù)據(jù)庫,其主文件大小為120MB,初始大小為55MB -- 文件大小增長率為10%,日志文件大小為30MB,初始大小為12MB,文件增長增量為3MB -- 文件均存儲在 "D:數(shù)據(jù)庫" 下 create database book on primary ( name=book, filename='d:數(shù)據(jù)庫ook.mdf', size=55, maxsize=120, filegrowth=10% ) log on ( name=book_log, filename='d:數(shù)據(jù)庫ook.ldf', size=12, maxsize=30, filegrowth=3 ) -- 查看數(shù)據(jù)庫'book'的信息 sp_helpdb 'book' -- 擴充數(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語句的查詢計劃 use northwind go set showplan_all on go select * from customers where customerid='BLONP' go set showplan_all off -- 顯示SQL語句的所花費磁盤活動量 use northwind go set statistics io on go select * from customers where customerid='BLONP' go set statistics io off |