SQL Server資料庫SP命令祥解

2021-09-11 14:15:59 字數 3318 閱讀 7697

1、資料庫:

(1)sp_helpdb:報告有關指定資料庫或所有資料庫的資訊。

例:sp_helpdb   --顯示所有資料庫資訊(名稱、大小等)

例:sp_helpdb recruitment   --顯示recruitment資料庫資訊(名稱、大小等)

(2)sp_renamedb:更改資料庫的名稱。

例:sp_renamedb 』pubs』,』pub』   --將名為pubs的資料庫改名為pub

(3)sp_dboption:顯示或更改資料庫選項。不能在 master 或 tempdb 資料庫上使用 sp_dboption。

例:sp_dboption 』recruitment』,』read only』,』true』   --設定recruitment資料庫為read only

2、表

(1)sp_help:當前資料庫中查詢物件。

例:sp_helpemployee     --顯示employee表的結構

(2)sp_rename:更改當前資料庫中使用者建立物件(如表、列或使用者定義資料型別)的名稱。

例:sp_rename 』employee』,』employ』

3、使用者自定義資料型別

(1)sp_addtype:建立使用者定義的資料型別。 

例:sp_addtype birthday, datetime, 』null』   

--建立了乙個名為 birthday 的使用者定義資料型別(基於 datetime),該資料型別允許空值

(2)sp_droptype: 刪除使用者定義的資料型別。

例: sp_droptype 』birthday』     --刪除使用者定義的資料型別 birthday

(3)sp_help:檢視使用者自定義資料型別的情況

例:sp_helpbirthday     --檢視使用者定義的資料型別 birthday的資訊

4、規則

(1)sp_bindrule:將規則繫結到列或使用者定義的資料型別。

例:sp_bindrule rultype,』titles.type』   --將規則rultype繫結到titles表的type列

(2)sp_unbindrule:在當前資料庫中為列或使用者定義資料型別解除規則繫結。

例:sp_unbindrule 』titles.type』   --取消繫結到tiltes表中的type列的規則

(3)sp_helptext:檢視規則的詳細資訊。

例:sp_helptext rultype    --檢視規則rultype的詳細資訊

5、預設

(1)sp_bindefault:將預設值繫結到列或使用者定義的資料型別。

(2)sp_unbindefault:在當前資料庫中為列或者使用者定義資料型別解除(刪除)預設值繫結。

(3)sp_helptext:檢視預設值的資訊。

6、索引

sp_helpindex:報告有關表或檢視上索引的資訊。

例:sp_helpindex employee    --檢視employee表中索引資訊

7、檢視

sp_helptext:檢視視**本

8、儲存過程

sp_helptext:檢視儲存過程文字

9、觸發器

(1)sp_help《觸發器名》:檢視指定觸發器是否存在

(2)sp_helptrigger:返回指定表中定義的當前資料庫的觸發器型別。

10. 全文搜尋-sp_grep

this procedure will search stored procedures, functions, triggers and views for a search string.

for example

exec sp_grep 'iansheng'

name	                                               owner            object_type

isp0108p_wsiml_generic_shp_out_rules_900001_10 dbo stored procedure

isp3365p_wsiml_cn_levis_rec_out_rules_900001_10 dbo stored procedure

create sp_grep

(@object varchar(255))

as select distinct

'type' = case type

when 'fn' then 'scalar function'

when 'if' then 'inlined table-function'

when 'p' then 'stored procedure'

when 'tf' then 'table function'

when 'tr' then 'trigger'

when 'v' then 'view'

end,

o.[name],

watchword = @object

from dbo.sysobjects o (nolock)

join dbo.syscomments c (nolock)

on o.id = c.id

where c.text like '%'+@object+'%'

11、其他

sp_help:報告有關資料庫物件、使用者定義資料型別或 資料型別的資訊。

sp_helptext:顯示規則、預設值、未加密的儲存過程、使用者定義函式、觸發器或檢視的文字。

sp_rename:更改當前資料庫中使用者建立物件(如表、列或使用者定義資料型別)的名稱。

SQL Server資料庫SP命令祥解

1 資料庫 1 sp helpdb 報告有關指定資料庫或所有資料庫的資訊。例 sp helpdb 顯示所有資料庫資訊 名稱 大小等 例 sp helpdb recruitment 顯示recruitment資料庫資訊 名稱 大小等 2 sp renamedb 更改資料庫的名稱。例 sp rename...

sqlserver 檢視資料庫正在執行的命令

在sql中有時候我們需要檢視現在正在sql server執行的命令。在分析管理器或者microsoft sql server management studio中,我們可以在 管理 sql server日誌 活動監視器 中檢視。今天我們主要利用master.sysprocesses系統表來檢視。先看...

mysql查資料庫 mysql檢視資料庫命令

mysql檢視資料庫命令 2012 11 29 19 51 25 標籤 it mysql檢視資料庫命令 開啟的資料庫的命令 mysql use mysql database changed 檢視資料庫的命令 mysql show databases 檢視資料表的詳細結構 mysql desc fun...