Logo
programming4us
programming4us
programming4us
programming4us
Home
programming4us
XP
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server
programming4us
Windows Phone
 
Windows Server

SQL server 2008 R2 : Creating and Managing Stored Procedures - Modifying Stored Procedures

- Free product key for windows 10
- Free Product Key for Microsoft office 365
- Malwarebytes Premium 3.7.1 Serial Keys (LifeTime) 2019
4/12/2013 3:13:49 PM

You can modify the text of a stored procedure by using the ALTER PROCEDURE statement. The syntax for ALTER PROCEDURE is similar to the syntax for CREATE PROCEDURE (see Listing 1). Using ALTER PROCEDURE has a couple advantages over dropping and re-creating a procedure to modify it. The main advantage is that you don’t have to drop the procedure first to make the change, so it remains available, even if the ALTER PROCEDURE command fails due to a syntax or object reference error. The second advantage is that because you don’t have to drop the procedure, you don’t have to worry about reassigning permissions to it after modifying it.

Listing 1. Modifying a Stored Procedure by Using ALTER PROCEDURE
ALTER PROCEDURE title_authors @state char(2) = '%'
AS
BEGIN
    SELECT a.au_lname, a.au_fname, t.title, t.pubdate
       FROM titles t
       INNER JOIN titleauthor ta ON t.title_id = ta.title_id
       RIGHT OUTER JOIN authors a ON ta.au_id = a.au_id
       where state like @state
    RETURN
END

Viewing and Modifying Stored Procedures with SSMS

You can also use SSMS to create, view, and modify stored procedures.

To edit a stored procedure in SSMS, expand the Programmability folder and then the Stored Procedures folder, right-click the name of the procedure you want to modify, and select Modify (see Figure 1).

Figure 1. Modifying stored procedures in SSMS.

SSMS then extracts the ALTER PROCEDURE statement for the selected procedure into a new query window. Here, you can edit the procedure code as needed and then execute the contents of the query window to modify the procedure. In addition, the Object Browser in SSMS provides other options for extracting the stored procedure source code. It can generate code to create, alter, or drop the selected stored procedure. You can script the stored procedure source code to a new window, to a file, or to the Windows Clipboard by right-clicking the stored procedure name in the Object Browser and choosing the appropriate option (see Figure 2).

Figure 2. Extracting stored procedure source code to a new query window.
Other -----------------
- Microsoft Dynamics Ax 2009 : RunBase Framework Extension (part 4) - Adding a Query
- Microsoft Dynamics Ax 2009 : RunBase Framework Extension (part 3) - Adding Property Methods, Adding Constructors
- Microsoft Dynamics Ax 2009 : RunBase Framework Extension (part 2) - Bike-Tuning Service Offers Example
- Microsoft Dynamics Ax 2009 : RunBase Framework Extension (part 1) - Property Method Pattern, Pack-Unpack Pattern
- Nginx HTTP Server : Basic Nginx Configuration - Testing your server
- Nginx HTTP Server : Basic Nginx Configuration - A configuration for your profile
- Windows Server : Network Access Policy and Server and Domain Isolation (part 4) - Planning NAP DHCP Enforcement, Domain and Server Isolation
- Windows Server : Network Access Policy and Server and Domain Isolation (part 3) - Planning NAP VPN Enforcement, Planning NAP 802.1x Enforcement
- Windows Server : Network Access Policy and Server and Domain Isolation (part 2) - Planning NAP IPsec Enforcement
- Windows Server : Network Access Policy and Server and Domain Isolation (part 1) - Network Access Protection Overview
 
 
Top 10
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 2) - Wireframes,Legends
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Finding containers and lists in Visio (part 1) - Swimlanes
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Formatting and sizing lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Adding shapes to lists
- Microsoft Visio 2013 : Adding Structure to Your Diagrams - Sizing containers
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 3) - The Other Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 2) - The Data Properties of a Control
- Microsoft Access 2010 : Control Properties and Why to Use Them (part 1) - The Format Properties of a Control
- Microsoft Access 2010 : Form Properties and Why Should You Use Them - Working with the Properties Window
- Microsoft Visio 2013 : Using the Organization Chart Wizard with new data
 
programming4us
Windows Vista
programming4us
Windows 7
programming4us
Windows Azure
programming4us
Windows Server