SQL Server 未公开的存储过程.docx

上传人:b****1 文档编号:124772 上传时间:2023-04-28 格式:DOCX 页数:17 大小:18.77KB
下载 相关 举报
SQL Server 未公开的存储过程.docx_第1页
第1页 / 共17页
SQL Server 未公开的存储过程.docx_第2页
第2页 / 共17页
SQL Server 未公开的存储过程.docx_第3页
第3页 / 共17页
SQL Server 未公开的存储过程.docx_第4页
第4页 / 共17页
SQL Server 未公开的存储过程.docx_第5页
第5页 / 共17页
SQL Server 未公开的存储过程.docx_第6页
第6页 / 共17页
SQL Server 未公开的存储过程.docx_第7页
第7页 / 共17页
SQL Server 未公开的存储过程.docx_第8页
第8页 / 共17页
SQL Server 未公开的存储过程.docx_第9页
第9页 / 共17页
SQL Server 未公开的存储过程.docx_第10页
第10页 / 共17页
SQL Server 未公开的存储过程.docx_第11页
第11页 / 共17页
SQL Server 未公开的存储过程.docx_第12页
第12页 / 共17页
SQL Server 未公开的存储过程.docx_第13页
第13页 / 共17页
SQL Server 未公开的存储过程.docx_第14页
第14页 / 共17页
SQL Server 未公开的存储过程.docx_第15页
第15页 / 共17页
SQL Server 未公开的存储过程.docx_第16页
第16页 / 共17页
SQL Server 未公开的存储过程.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

SQL Server 未公开的存储过程.docx

《SQL Server 未公开的存储过程.docx》由会员分享,可在线阅读,更多相关《SQL Server 未公开的存储过程.docx(17页珍藏版)》请在冰点文库上搜索。

SQL Server 未公开的存储过程.docx

SQLServer未公开的存储过程

 SQLServer2000未公开的存储过程

sp_MSget_qualified_name

The sp_MSget_qualified_name storedprocedureisusedtogetthequalifiednameforthegivenobjectid.

Syntax

sp_MSget_qualified_nameobject_id,qualified_name

where

object_id-istheobjectid.object_idisint.

qualified_name-isthequalifiednameoftheobject.qualified_name

isnvarchar(512).

 

Thisistheexampletogetthequalifiednameforthe authors tablefromthe pubs database.

USEpubs

GO

declare@object_idint,@qualified_namenvarchar(512)

select@object_id=object_id('authors')

EXECsp_MSget_qualified_name@object_id,@qualified_nameoutput

select@qualified_name

GO

 

Hereistheresultsetfrommymachine:

--------------------------------------

[dbo].[authors]

 

sp_MSdrop_object

The sp_MSdrop_object storedprocedureisusedtodropanobject(itcanbetable,view,storedprocedureortrigger)forthegivenobjectid,objectname,andobjectowner.Ifobjectid,objectname,andobjectownerarenotspecified,thennothingwillbedropped.

Syntax

sp_MSdrop_object[object_id][,object_name][,object_owner]

where

object_id-istheobjectid.object_idisint,

withadefaultofNULL.

object_name-isthenameoftheobject.object_nameissysname,

withadefaultofNULL.

object_owner-istheobjectowner.object_ownerissysname,

withadefaultofNULL.

 

Thisistheexampleofdroppingthe titleauthor tablefromthe pubs database.

USEpubs

GO

declare@object_idint

select@object_id=object_id('titleauthor')

EXECsp_MSdrop_object@object_id

GO

 

sp_gettypestring

The sp_gettypestring storedprocedurereturnsthetypestringforthegiventableidandcolumnid.

Syntax

sp_gettypestringtabid,colid,typestring

where

tabid-isthetableid.tabidisint.

colid-isthecolumnid.colidisint.

typestring-isthetypestring.It'soutputparameter.

typestringisnvarchar(255).

 

Thisistheexampletogetthetypestringforthecolumnnumber2inthe authors table,fromthe pubs database.

USEpubs

GO

declare@tabidint,@typestringnvarchar(255)

select@tabid=object_id('authors')

EXECsp_gettypestring@tabid,2,@typestringoutput

select@typestring

GO

 

Hereistheresultsetfrommymachine:

-------------------------------

varchar(40)

 

sp_MSgettools_path

The sp_MSgettools_path storedprocedurereturnsthepathtotheSQLServer2000toolsandutilities.

Syntax

sp_MSgettools_pathinstall_path

where

install_path-istheinstallationpath.It'soutputparameter.

install_pathisnvarchar(260).

 

ThisistheexampletogetthepathtotheSQLServer2000toolsandutilities.

USEmaster

GO

declare@install_pathNVARCHAR(260)

EXECsp_MSgettools_path@install_pathOUTPUT

select@install_path

GO

 

Hereistheresultsetfrommymachine:

------------------------------------------------------------

C:

\ProgramFiles\MicrosoftSQLServer\80\Tools

 

sp_MScheck_uid_owns_anything

The sp_MScheck_uid_owns_anything storedprocedurereturnsthelistoftheobject,ownedbythespecifieduser.

Syntax

sp_MScheck_uid_owns_anythinguid

where

uid-istheUserID,uniqueinthisdatabase.uidissmallint.

 

Thisistheexampletogetthelistoftheobjects,ownedbythedatabaseowner1inthe pubs database.

USEpubs

GO

EXECsp_MScheck_uid_owns_anything1

GO

 

sp_columns_rowset

The sp_columns_rowset storedprocedurereturnsthecompletecolumnsdescription,includingthelength,type,name,andsoon.

Syntax

sp_columns_rowsettable_name[,table_schema][,column_name]

where

table_name-isthetablename.table_nameissysname.

table_schema-isthetableschema.table_schemaissysname,

withadefaultofNULL.

column_name-isthecolumnname.column_nameissysname,

withadefaultofNULL.

 

Thisistheexample:

USEpubs

GO

EXECsp_columns_rowset'authors'

GO

 

sp_fixindex

The sp_fixindex storedprocedurecanbeusedtofixcorruptioninasystemtablebyrecreatingtheindex.

Syntax

sp_fixindexdbname,tabname,indid

where

dbname-isthedatabasename.dbnameissysname.

tabname-isthesystemtablename.tabnameissysname.

indid-istheindexidvalue.indidisint

 

Note.Beforeusingthisstoredprocedurethedatabasehastobeinsingleusermode.

Seethislinkformoreinformation:

HowcanIfixacorruptioninasystemtable?

Thisistheexample:

USEpubs

GO

EXECsp_fixindexpubs,sysindexes,2

GO

 

sp_MSforeachdb

Sometimes,youneedtoperformthesameactionsforalldatabases.Youcancreatecursorforthispurpose,oryoucanalsousethe sp_MSforeachdb storedproceduretoaccomplishthesamegoalwithlesswork.

Forexample,youcanusethe sp_MSforeachdb storedproceduretorunaCHECKDBforallthedatabasesonyourserver:

EXECsp_MSforeachdb@command1="print'?

'DBCCCHECKDB('?

')"

sp_MSforeachtable

Sometimes,youneedtoperformthesameactionsforalltablesinthedatabase.Youcancreatecursorforthispurpose,oryoucanalsousethe sp_MSforeachtable storedproceduretoaccomplishthesamegoalwithlesswork.

Forexample,youcanusethe sp_MSforeachtable storedproceduretorebuildalltheindexesinadatabase:

EXECsp_MSforeachtable@command1="print'?

'DBCCDBREINDEX('?

')"

sp_MShelpcolumns

The sp_MShelpcolumns storedprocedurereturnsthecompleteschemaforatable,includingthelength,type,name,andwhetheracolumniscomputed.

Syntax

sp_MShelpcolumnstablename[,flags][,orderby][,flags2]

where

tablename-isthetablename.tablenameisnvarchar(517).

flags-flagsisint,withadefaultof0.

orderby-orderbyisnvarchar(10),withadefaultofNULL.

flags-flags2isint,withadefaultof0.

 

Togetthefullcolumnsdescriptionforthe authors tableinthe pubs database,run:

USEpubs

GO

EXECsp_MShelpcolumns'authors'

GO

 

sp_MShelpindex

The sp_MShelpindex storedprocedurereturnsinformationaboutname,status,fillfactor,indexcolumnsnames,andfilegroupsforagiventable.

Syntax

sp_MShelpindextablename[,indexname][,flags]

where

tablename-isthetablename.tablenameisnvarchar(517).

indexname-istheindexname.indexnameisnvarchar(258),

withadefaultofNULL.

flags-flagsisint,withadefaultofNULL.

 

Togettheindexesdescriptionforthe authors tableinthe pubs database,run:

USEpubs

GO

EXECsp_MShelpindex'authors'

GO

 

sp_MShelptype

The sp_MShelptype storedprocedurereturnsmuchusefulinformationaboutsystemdatatypesanduserdatatypes.

Syntax

sp_MShelptype[typename][,flags]

where

typename-isthetypename.typenameisnvarchar(517),

withadefaultofNULL.

flags-flagsisnvarchar(10),withadefaultofNULL.

 

Togetinformationaboutallbuilt-inanduserdefineddatatypesinthe pubs database,run:

USEpubs

GO

EXECsp_MShelptype

GO

 

sp_MSindexspace

The sp_MSindexspace storedprocedurereturnsthesizeinkb,oftheindexesfoundinaparticulartable.

Syntax

sp_MSindexspacetablename[,index_name]

where

tablename-isthetablename.tablenameisnvarchar(517).

index_name-istheindexname.index_nameisnvarchar(258),

withadefaultofNULL.

 

Todeterminethespaceusedbytheindexesfromthe authors tableinthe pubs database,run:

USEpubs

GO

EXECsp_MSindexspace'authors'

GO

 

sp_MSkilldb

The sp_MSkilldb storedproceduresetsadatabasetosuspectmodeanduses DBCCDBREPAIR tokillit.Youshouldrunthisspfromthecontextofthemasterdatabase.Useitverycarefully.

Syntax

sp_MSkilldbdbname

where

dbname-isthedatabasename.dbnameisnvarchar(258).

 

Tokillthe pubs database,run:

USEmaster

GO

EXECsp_MSkilldb'pubs'

GO

 

sp_MStablespace

The sp_MStablespace storedprocedurereturnsthenumberofrowsinatableandthespacethetableandindexuse.

Syntax

sp_MStablespacename[,id]

where

name-isthetablename.nameisnvarchar(517).

id-idisint,withadefaultofNULL.

 

Todeterminethespaceusedbythe authors tableinthe pubs database,run:

USEpubs

GO

EXECsp_MStablespace'authors'

GO

 

Hereistheresultsetfrommymachine:

RowsDataSpaceUsedIndexSpaceUsed

--------------------------------------

23832

 

sp_tempdbspace

The sp_tempdbspace storedprocedurecanbeusedtogetthetotalsizeandthespaceusedbythetempdbdatabase.Itisusedwithoutparameters.

Syntax

sp_tempdbspace

Thisistheexample:

EXECsp_tempdbspace

Hereistheresultsetfrommymachine:

database_namedatabase_sizespaceused

-----------------------------------------------------------------

tempdb9.750000.562500

 

sp_who2

The sp_who2 storedprocedurereturnsinformationaboutcurrentSQLServer2000usersandprocessessimilartosp_who,butitprovidesmoredetailedinformation.sp_who2returnsCPUTime,DiskIO,LastBatchandProgramNameinadditiontothedataprovidedbysp_who.

Syntax

sp_who[loginame]

where

loginame-theuser'sloginname.Ifnotspecified,theprocedure

reportsonallactiveusersofSQLServer.

 

Thisexamplereturnsinformationforthe'sa'login:

EXECsp_who2'sa'

sp_MSgetversion

ThisextendedstoredprocedurecanbeusedtogetthecurrentversionofMicrosoftSQLServer.TogetthecurrentSQLServerversion,run

EXECmaster..sp_MSgetversion

Note.AmorecommonwaytoretrievethecurrentSQLServerversion(thiswayprovidesmoreinformation)istousefollowingSELECTstatement:

SELECT@@version

xp_dirtree

Thisextendedstoredprocedurecanbeusedtogetalistofallthefoldersforthefoldernamedinthexp.TogetalistofallthefoldersintheC:

\MSSQL7folder,run:

EXECmaster..xp_dirtree'C:

\MSSQL7'

xp_enum_oledb_providers

Thisextendedstoredprocedur

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 解决方案 > 学习计划

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2