Introduction to SQL Server Extended Stored Procedures

Learn SQL with Udemy

For an instructor lead, in-depth look at learning SQL click below.


A Stored Procedure in SQL is a collection of SQL statements that have been created and stored in the database as a result of which they can be reused and shared by multiple programs. SQL Server’s set of stored procedures go beyond the traditional ones, giving rise to what we know as Extended Stored Procedures.

Extended Stored Procedures (ESPs) are a powerful feature offered by SQL Server, which allows users to link a programmed subroutine to an instance of SQL. As these subroutines are typically written in the C or C++ programming languages, ESPs provide a way to integrate the data manipulation capabilities of SQL with more extensive software functions.

How to Create an Extended Stored Procedure

Let’s create an extended stored procedure. In this case, we’ll create a simple procedure called xp_hello that writes ‘Hello world’ to the SQL Server error log.

This command adds a new extended stored procedure to SQL Server. ‘xp_hello’ is the name of our new procedure, and ‘C:\Program Files\Microsoft SQL Server\MSSQL13.SQL\MSSQL\Binn\xpstar.dll’ is the DLL that contains the implementation of our procedure.

How to Execute an Extended Stored Procedure

Executing an extended stored procedure is just as straightforward as executing a regular stored procedure. Here’s how we can execute the xp_hello procedure we created earlier:

In your SQL Server error log, you should see an entry that says ‘Hello world’.

Restrictions and Security Risks

While Extended Stored Procedures can add significant functionality to SQL Server, they are not without limitations and security risks. ESPs can execute any code they like, meaning they can potentially damage the server or compromise its security if not properly managed. Thus, it is vital to handle Extended Stored Procedures with the utmost caution and use them only when necessary.

Conclusion

Extended Stored Procedures are a potent tool in SQL Server, providing the ability to extend the server’s capabilities and integrate its features with broader software functions. While they come with security risks, knowing how to create, execute, and manage Extended Stored Procedures can be extremely beneficial for any SQL Server developer or administrator.

Leave a Comment