Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to “store” stored procedures

Status
Not open for further replies.

thedougster

Programmer
Jan 22, 2009
56
US
I've written a few SQL stored procedures in a text editor. But how do I actually "store" them in (add them to?) a database using SQL Server 2008 Management Studio Express? I've tried to research this topic in Management Studio's onboard Help, but apparently Help assumes I know more about the subject than I actually do, because I don't even see the relevance of the answers I'm getting to my questions. Any help would be appreciated, including pointing me to a good SQL tutorial that assumes the reader knows nothing, yet teaches more than the bare-bones minimum.
 
Easy.
Start SSMS and open New Query window.
In that Window write:
Code:
USE YourDatabase
GO

Than paste the code for your SP after GO and press F5.

You must be sure that your code begins with:
CREATE PROCEDURE NameOfTheSP

Her an example
Code:
USE MyDB
GO
CREATE PROCEDURE MyTestSP
       (@par1 int,
        @par2 varchar(20))
AS
  BEGIN
      SELECT * FROM MyTest WHERE Field1 = @par1 AND
                                 Field2 = @par2
  END

If you have such SP already stored in the DB instead of CREATE PROCEDURE you must use ALTER PROCEDURE.

Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top