SQL Server
  Home arrow SQL Server arrow Page 2 - Extended Stored Procedures: Intro And 10 C...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
SQL SERVER

Extended Stored Procedures: Intro And 10 Cool Examples
By: Joe O'Donnell
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 105
    2002-02-11

    Table of Contents:
  • Extended Stored Procedures: Intro And 10 Cool Examples
  • Extended Stored Procedures
  • Useful Extended Stored Procedures
  • Examples (contd.)
  • Examples (contd.)
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Extended Stored Procedures: Intro And 10 Cool Examples - Extended Stored Procedures


    (Page 2 of 6 )

    Before I break into discussing how to use some extended stored procedures that come pre-installed with SQL Server 2000, let's take a look at how we can view this list of stored procedures using Enterprise Manager. Start Enterprise Manager (Start -> Programs -> Microsoft SQL Server -> Enterprise Manager) and expand the nodes of the master database in the left hand column. Click on the extended stored procedures node. You should see the entire list of extended stored procedures for the master database.

    Take a look at any of the other databases on your server. You'll notice that they don't have an extended stored procedures node. The only way to execute a built-in extended stored procedure is to prefix the call to the procedure with "master..", which tells SQL Server that the extended stored procedure is part of the master database.

    Double click on any extended stored procedure in the right hand column that is prefixed with "sp_". Its property page will appear:

    The properties window

    Remember earlier that I said extended stored procedures are created and loaded as DLL's? This is true for stored procedures prefixed with "xp_". As shown in the screen shot above, extended stored procedures that are prefixed with "sp_" are defined internally by SQL server, but still have access to the Win32 API's, etc as those prefixed with "xp_" do.

    Close the open properties window and double click on an extended store procedure that's prefixed with "xp_". Its property page should appear:

    The properties window

    Notice this time however that extended procedures prefixed with "xp_" show a DLL file as the path property? In SQL Server 2000, all extended stored procedures prefixed with "xp_" actually physically reside in a DLL file. To prove this, open the C:\Program Files\Microsoft SQL Server\MSSQL\Binn folder. This is the folder when the DLL's for all extended stored procedures should reside. It looks like this:

    The Binn directory of SQL Server 2000

    See how the xplog70.dll file exists in this directory? Whenever a call to an extended stored procedure is made as part of a batch, function, procedure, or through some third-party interface such as ADO, SQL Server will load the function from that DLL and wrap it up so that it can accept and return arguments. It's a very complex procedure, and we won't go into its details in this article.

    There's one last thing to do before we look at some useful extended stored procedures, and that's how to actually call them. Fire up Query Analyzer (Start -> Programs -> Microsoft SQL Server -> Query Analyzer) and connect to any database on your server. Calling extended stored procedures is exactly the same as calling normal stored procedures, but because they exist only in the master database, each call must be prefixed with "master..", to let SQL Server know that it can find the extended stored procedure as part of the master database.

    Enter the following line into the query window:

    exec master..xp_fixeddrives

    Click on the play button or press F5 to execute a call to the xp_fixeddrives extended stored procedure. You should get something like this:

    Executing an extended stored procedure

    Alternatively, you could tell SQL Server explicitly where the extended stored procedure can be found by using the USE command:

    USE MASTER

    GO

    exec master..xp_fixeddrives


    Now that we've gotten a nicely rounded intro to extended stored procedures, let's look at 10 extremely useful extended store procedures that we can use through batches, procedures and functions to improve the functionality of our code.

    More SQL Server Articles
    More By Joe O'Donnell


     

    SQL SERVER ARTICLES

    - Executing SQL Server Stored Procedure from P...
    - How to Search for Date and Time Values Using...
    - Replication: SQL Server 2000 - Part 2
    - Replication: SQL Server 2000 - Part 1
    - SQL Sever: Storing Code in Binary or Text Fi...
    - Execute SQL on Multiple Tables/Columns - New...
    - How to Connect to a SQL Server from Visual F...
    - SQL Server Hardware Tuning and Performance M...
    - Primary Key on Multiple Tables – New RDBMS C...
    - Migrating from Sybase to SQL Server
    - What's Best for DBAs? GUI or T-SQL Comma...
    - How to Perform a SQL Server Performance Audit
    - An Introduction To The Bulk Copy Utility
    - SQL Server Stored Procedures 101
    - Building Your First SQL Server 2000 Database






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT