位置: 编程技术 - 正文

一些SQL Server存储过程参数及例子(sql server数据存放位置)

编辑:rootadmin

Microsoft included several hundred stored procedures in the various versions of Microsoft SQL Server and it has documented a good percentage of them. But many stored procedures remain undocumented. Some are used within the Enterprise Manager GUI in SQL and were not intended to be used by other processes. Microsoft has slated some of these stored procedures to be removed (or they have been removed) from future versions of SQL Server. While these stored procedures can be very useful and save you lots of time, they can be changed at any time in their function or they can simply be removed.

The chart below shows that while many of the procedures have been carried through from one version of Microsoft SQL Server to another, new stored procedures have been introduced, and some have been removed from the install package. Most, if not all, of the procedures require the user to be a member of the sysadmin fixed server role in order to execute the procedures. The stored procedures that interact with the file system also require that the user executing the procedure (as well as SQL Server's service account) have access to the file/folder.

Procedure NameSQL SQL SQL sp_executeresultsetX  sp_MSforeachdbXXXsp_MSforeachtableXXXsp_readerrorlogXXXxp_create_subdir XXXp_delete_file XXxp_dirtreeXXXxp_fileexistXXXxp_fixeddrivesXXXxp_getfiledetailsX  xp_getnetnameXXXxp_loginconfigXXXxp_makecabX  xp_msverXXXxp_get_mapi_profilesXXXxp_subdirsXXXxp_test_mapi_profileXXXxp_unpackcabX  

sp_executeresultset

Microsoft removed this handy little procedure called sp_executeresultset from SQL Server in SQL Server . It allows you to generate dynamic SQL code on the fly by using a SELECT query. Then, the resulting SQL commands will be executed against the database. It permits you to create a single piece of code that can, in a single step, find the number of records in every table in your database (as the example shows). This is an undocumented stored procedure and there is no way of knowing why it was removed. But, alas, this handy utility is gone.

exec sp_execresultset 'SELECT ''SELECT '''''' + name + '''''', count(*) FROM '' + namefrom sysobjectswhere xtype = ''U'''

sp_MSforeachdb / sp_MSforeachtable

Two procedures, sp_MSforeachdb and sp_MSforeachtable, are wrappers around a cursor. They allow you to execute T-SQL code against each database on your SQL Server and each table within the current database, respectively. You cannot, however, use an sp_MSforeachtable command within an sp_MSforeachdb command in SQL and prior. The cursor name that was used within those procedures was the same (hCForEach) and would therefore return an error saying that the cursor name was already in use for each execution of the sp_MSforeachtable. In SQL Server , Microsoft resolved this issue. In order to "next" the command, you must tell one of the procedures it will be using a different replacement character other than the default question mark. I change the replacement character in the database command because it's easier.

Print each table name in the current database.

exec sp_MSforeachtable 'print ''?'''

Print each database on the current server.

exec sp_MSforeachdb 'print ''?'''

Print each table on the current server.

exec sp_MSforeachdb 'use [@] exec sp_MSforeachtable ''print''''@.?''''''', '@'

sp_readerrorlog / xp_readerrorlog

The stored procedure sp_readerrorlog actually comes in two forms. Each works the same; one is simply a wrapper for the second. The wrapper stored procedure is sp_readerrorlog and it calls xp_readerrorlog. Both have four input parameters, but only the first two are useful to us. The first parameter establishes the file number that you wish to view. The second is the log to view (1 or null for ERRORLOG, 2 for SQL Agent Log). This allows you to view your error logs quickly and easily instead of having to look at the bloated log viewer that now comes with SQL Server and SQL .

View the current SQL ERRORLOG file.

exec sp_readerrorlog

exec sp_readerrorlog 0, 1

View the Prior SQL Agent Log file.

exec sp_readerrorlog 1, 2

xp_create_subdir

Introduced in SQL Server , the xp_create_subdir stored procedure is very handy because you can use it to create folders on SQL Server's hard drive or on a network share from within T-SQL.

exec xp_create_subdir 'c:MSSQLData'

xp_delete_file

Use the xp_delete_file stored procedure introduced in SQL Server to delete files from SQL Server's hard drive or a network share from within T-SQL.

xp_dirtree

The xp_dirtree procedure allows you to view the folder tree and/or file list beneath a folder. This procedure has several parameters that control how deep the procedure searches and whether it returns files and folders or folders only. The first parameter establishes the folder to look in. (Recommendation: Do not run this procedure against the root of the drive that Windows is installed on because it will take some time to generate the tree and return the data.) The second parameter limits the number of recursive levels that the procedure will dig through. The default is zero or all levels. The third parameter tells the procedure to include files. The default is zero or folders only, a value of 1 includes files in the result set. Specifying a third value not equal to zero will add an additional column to the output called file which is a bit field showing the entry in a folder or file.

Get the full directory tree.

exec xp_dirtree 'd:mssql'

Get the first two levels of the directory tree.

exec xp_dirtree 'd:mssql', 2

Get the first three levels of the directory tree, including files.

exec xp_dirtree 'd:mssql', 3, 1

xp_fileexist

This SQL Server stored procedure, xp_fileexist, is used to determine if a file exists on SQL Server's hard drive or on a network share. It is extremely useful in stored procedures that load data from flat files. It allows you to check and see if the file exists before attempting to blindly load the file. The procedure has two parameters. Use the first parameter to determine if the file or folder you want exists. The second is an output parameter, which when specified, returns a 1 or 0 if the file exists or does not.

Without the parameter.

exec xp_fileexist 'c:importfile.csv'

With the parameter.

DECLARE @file_exists intexec xp_fileexist 'c:importfile.csv', @file_exists OUTPUTSELECT @file_exists

xp_fixeddrives

The procedure xp_fixeddrives is one of the most useful procedures. It presents a list of all drive letters and the amount of free space each drive has. The parameter has a single optional input parameter that can filter the results by drive type. A value of 3 will return all mass storage devices (CD-ROM, DVD, etc.); a value of 4 will return the hard drives; while a value of 2 will return removable media (USB thumb drives, flash drives, etc.).

Return all drives.

exec xp_fixeddrives

Return hard drives only.

exec xp_fixeddrives 2

xp_getfiledetails

The procedure xp_getfiledetails is another extremely useful procedure, which was last available in SQL Server . This procedure returns size, date and attribute information about the file specified, including date and times created, accessed and modified.

exec xp_getfiledetails 'c:filetoload.csv'

xp_getnetname

The procedure xp_getnetname returns the name of the physical machine where Microsoft SQL Server is installed. You can have the machine name returned as a record set or as a variable.

Without the parameter.

exec xp_getnetname

Using the parameter.

DECLARE @machinename sysnameexec xp_getnetname @machinename OUTPUTselect @machinename

xp_loginconfig

This SQL Server stored procedure will tell you some basic authentication information about the user executing it. It tells you the authentication method (Windows versus SQL Login), the default domain of the server, the audit level, as well as some internal separator information.

exec xp_loginconfig

xp_makecab

Back in SQL Server , Microsoft gave us the ability to compress OS files directly from T-SQL without having to shell out to DOS via xp_cmdshell and run third-party software, like pkzip or winzip. That command was xp_makecab. It allows you to specify a list of files you want to compress as well as the cab file you want to put them in. It even lets you select default compression, MSZIP compression (akin to the .zip file format) or no compression. The first parameter gives the path to the cab file in which you want to create or add files to. The second parameter is the compression level. The third parameter applies if you want to use verbose logging. Starting with the fourth parameter and on down are the names of the files you want to compress. In my testing, I was able to pass file names to be compressed to the extended stored procedure, which means that it is a very flexible solution to your data compression requirements.

exec xp_makecab 'c:test.cab', 'mszip', 1, 'c:test.txt' , 'c:test1.txt'

xp_msver

The procedure xp_msver is very useful when looking for system information. It returns a wealth of information about the host operating system -- the SQL version number, language, CPU type, copyright and trademark information, Microsoft Windows version, CPU count and affinity settings, physical memory settings and your product key. This procedure has many input parameters that allow you to filter down the records that are returned. Each parameter is a sysname data type, which accepts the name of one of the records. If any parameters are specified, only the rows specified as a parameter are returned.

No filter specified.

exec xp_msver

Return only Platform and Comments records.

exec xp_msver 'Platform', 'Comments'

xp_get_mapi_profiles

The xp_get_mapi_profiles procedure assists you in configuring SQL Mail. When executed, it will call to Windows via the SQL Mail component of SQL Server and display a list of available MAPI profiles that are configured in Outlook and it specifies which profile is the default profile. If it doesn't display any records, then either Outlook is not configured correctly or SQL Server is not running under a domain account with Outlook profiles configured. In order to use this procedure in SQL Server or SQL Server , you must enable the "SQL Mail XPs" option in the Surface Area Configuration tool or within the sp_configure procedure.

exec xp_get_mapi_profiles

xp_subdirs

The xp_subdirs procedure displays a subset of the information avaialble through xp_dirtree. Xp_subdirs will display all the subfolders in a given folder. It can be very handy when you are building a directory tree within a table dynamically and you do not want to worry about the extra parameters of the xp_dirtree procedure.

exec xp_subdirs 'd:mssql'

xp_test_mapi_profiles

The procedure xp_test_mapi_profiles is another undocumented stored procedure that is very useful when you are setting up SQL Mail. It will start, then stop, a MAPI session to ensure that MAPI is configured correctly and working within the confines of Microsoft SQL Server. I should note that it does not verify the mail server configuration within the MAPI client (Outlook) nor does it send a test message.

The procedure accepts a single input parameter. That parameter is the name of the MAPI profile you wish to test. Like the xp_get_mapi_profiles procedure, for this stored procedure to function in SQL Server and SQL Server , you must enable the "SQL Mail XPs" option in the Surface Area Configuration tool or within the sp_configure procedure.

When working with the SQL Mail stored procedures, be aware that SQL Mail is still slated for removal from the Microsoft SQL Server platform. That means the procedures sp_get_mapi_profiles and xp_test_mapi_profiles are slated for removal, as they are part of the SQL Mail subsystem. You should do all mail work on SQL Server and later using Database Mail instead of SQL Mail to ensure code portability with future versions of SQL Server. Microsoft initially slated SQL Mail for removal in SQL Server , however, based on its inclusion in the current beta release, its future in SQL Server is unknown.

xp_unpackcab

Along with the xp_makecab procedure comes the xp_unpackcab extended stored procedure, and it does just what it says: It extracts files from cab files. The first paramater is the cab file, the second is the path you want to extract to and the third is verbose logging. A fourth paramater lets you specify the "extract to" file name.

exec xp_unpackcab 'c:test.cab', 'c:temp', 1

While this is not intended to be a complete list of the undocumented stored procedures in SQL Server, it does provide a reference point for many of these procedures with the hope of making the lives of the SQL Server administrators easier. Remember, you should never count on these procedures surviving from one SQL Server version to the next, nor should you expect their code base to remain the same between versions. That said, go code and enjoy.

All information provided about Microsoft SQL Server (Katmai) is based on beta edition .0. of the software and is subject to change without notice.

推荐整理分享一些SQL Server存储过程参数及例子(sql server数据存放位置),希望有所帮助,仅作参考,欢迎阅读内容。

一些SQL Server存储过程参数及例子(sql server数据存放位置)

文章相关热门搜索词:sql server数据库已存在,sql server有许多的数据文件,sql server数据库已存在,sqlserver 存储文件,sql server 能存多少数据,sqlserver 存储文件,sqlserver 存储文件,sql server有许多的数据文件,内容如对您有帮助,希望把文章链接给更多的朋友!

sql高级技巧几个有用的Sql语句 1、例如:有两个表A(字段1,字段2,字段3)、B(字段2,字段3),其中存储数据如下所示表A字段1字段2字段Null地段内容Null地段内容Null地段内容Null

SQL语句实现SQL Server 及Sql Server 日志收缩(批量) DECLARE@nameVARCHAR()DECLARE@SQLVARCHAR()DECLARE@logidINTDECLAREsysdatabase_nameCURSORFORSELECTnameFROMmaster.dbo.sysdatabasesOPENsysdatabase_nameFETCHNEXTFROMsysdatabase_nameINTO@nameWHILE@@FET

用SQL建立索引的方法步骤 进入查询窗口后,输入下面的语句:CREATEINDEXmycolumn_indexONmytable(myclumn)这个语句建立了一个名为mycolumn_index的索引。你可以给一个索引起任何名字,但你

标签: sql server数据存放位置

本文链接地址:https://www.jiuchutong.com/biancheng/348731.html 转载请保留说明!

上一篇:SQL Server下几个危险的扩展存储过程(sql server key)

下一篇:sql高级技巧几个有用的Sql语句(sql高级语句实例)

  • 所得税月度申报
  • 税收指的是什么
  • 车间设备折旧费属于制造费用吗
  • 速达3000货品怎么入库
  • 报税显示税款入账未到账
  • 买断式贴现是什么业务
  • 汇票贴息入什么科目
  • 计提存货跌价准备是递延所得税资产吗
  • 平行式明细账
  • 长期待摊费用可以转入费用或者成本吗
  • 小额贷款业务涉及哪些法律
  • 金税设备维护费账务处理
  • 开出转账支票怎么入账
  • 短期借款的利息会计分录怎么写
  • 工业企业哪些房子要交房产税
  • 营改增后增值税暂行条例实施细则
  • 盐酸编号
  • 一般纳税人出租不动产增值税税率
  • 企业上月份销售收入在本月份发生销售折让时
  • 预估成本怎么冲回
  • 个体户怎么给供货公司
  • 非居民纳税人享受协定待遇办理方式
  • 劳务市场零工临时工
  • 工地买东西怎么记账
  • 企业所得税征收标准
  • 电脑不能上网是什么原因?
  • linux桌面不见了
  • PHP:mb_ereg_replace_callback()的用法_mbstring函数
  • 公司装修待摊费怎么算
  • 增值税按简易计价方式
  • 纳税人提供应税服务
  • 什么叫财政专户返还方式
  • 本月认证上月的进项票如何做
  • 增值税注明的价款是含税还是不含税
  • 增值税电子发票怎么下载
  • 政府补助的核算内容有哪些
  • 人力资源公司的税率是多少
  • 织梦cms怎么样
  • 应付职工薪酬期末余额是什么意思
  • 小规模纳税人开具增值税专用发票
  • 收到保险赔款入什么科目
  • sql server简单查询
  • 旅游业营改增会计分录
  • 固定资产处置的会计科目
  • 已纳消费税扣除会计分录
  • mysql改造
  • 房地产行业概况
  • 停车费报销会计分录
  • 公司股权变更如何合理避税
  • 专利转让费一般是多少
  • 未使用的固定资产计提折旧应当计入
  • 新公司的注册
  • 会计估计变动怎么处理
  • 案例分析购入办法怎么写
  • 总账会计的岗位目的
  • mysql在数据分析中的作用
  • win8已共享但别电脑无权限
  • 在linux操作系统中,/etc/rc.d/init.d
  • windows的使用
  • windows7文件丢失
  • 平板电脑安装的是什么格式的软件
  • jQuery插件实现静态HTML验证码校验
  • Cocos2dx3.2 Crazy Tetris 由于遮罩引起的部分手机白屏
  • 怎样用在js中使用css的内容
  • python pyo
  • cocos2dx schedule
  • unity4.1
  • jquery教程w3c
  • css文件放在什么目录
  • awk范围筛选
  • js跨域请求的三种方法
  • jquery22插件网
  • jquery判断checkbox是否选中及改变checkbox状态的实现方法
  • 开发票 税收编码
  • 云南省税务局app缴费
  • 爱信诺开票系统怎么安装
  • 三方协议暂不支持缴款
  • 购车发票包含
  • 承租房变更承租人申请怎么写
  • 经营数据分析需要学什么
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设