473,402 Members | 2,046 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

how to “store” stored procedures

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.
Apr 2 '09 #1
5 2842
I've not used 2008 but it should be something like:

Expand|Select|Wrap|Line Numbers
  1. USE [database name]
  2.  
  3. CREATE PROCEDURE [schema].[procedure name]
  4. AS
  5. BEGIN
  6.         your code here
  7. END
  8.  

Once created, if you need to modify it use ALTER PROCEDURE
Apr 2 '09 #2
ck9663
2,878 Expert 2GB
Open a query window and paste your stored procedure there then click RUN.


--- CK
Apr 2 '09 #3
ck9663:

I clicked New Query and pasted my procedure, but before I could even click RUN, SQL Server Management Studio made numerous objections.

Here's my procedure (sorry, I didn't code-wrap it so the bold font would show):

CREATE PROCEDURE UpdateProc (
@ContactID as int,
@Title as nvarchar (8),
@FirstName as Name:nvarchar (50),
@MiddleName as Name:nvarchar (50)
@LastName as Name:nvarchar (50)
@Suffix as nvarchar (10)
@EmailAddress as nvarchar (50)
@Phone as Phone:nvarchar (25)
@PasswordHash as varchar (128)
@PasswordSalt as varchar (10))
AS
UPDATE Person.Contact SET
Title = @Title, FirstName = @FirstName, MiddleName = @MiddleName, LastName = @LastName, Suffix = @Suffix,
EmailAddress = @EmailAddress, Phone = @Phone, PasswordHash = @PasswordHash,
PasswordSalt = @PasswordSalt
WHERE ContactID = @ContactID
GO

Here are Management Studio's objections:

Parameters: words shown in bold. All are "incorrect syntax". Data types are given exactly as they appear in the table "Person.Contact".

Body of procedure (every word except UPDATE, SET and WHERE):
Person.Contact: "invalid object name"
all column names: "invalid column name"
all scalar variables (with "@"): "must declare scalar variable"

It must be that I need to associate this proceure with the table. But how? I tried highlighting the table, but that didn't work.

BTW, I thought that, technically speaking, only SELECT constituted a query, and UPDATE, INSERT and DELETE were just called commands.

As you can see, I'm a newbie stumbling around in the dark, so ANY help would be most appreciated.

P.S. Just tried it again, the exact same way. This time it dropped its objections to column names and to object name "Person.Contact". I have no idea why.
Apr 2 '09 #4
ck9663
2,878 Expert 2GB
Here you go...

Expand|Select|Wrap|Line Numbers
  1.  
  2. CREATE PROCEDURE UpdateProc 
  3. (
  4.    @ContactID as int,
  5.    @Title as nvarchar (8),
  6.    @FirstName as nvarchar (50),
  7.    @MiddleName as nvarchar (50),
  8.    @LastName as nvarchar (50),
  9.    @Suffix as nvarchar (10),
  10.    @EmailAddress as nvarchar (50),
  11.    @Phone as nvarchar (25),
  12.    @PasswordHash as varchar (128),
  13.    @PasswordSalt as varchar (10)
  14. )
  15. AS
  16. UPDATE Person.Contact 
  17. SET
  18.    Title = @Title, FirstName = @FirstName, MiddleName = @MiddleName, LastName = @LastName, Suffix = @Suffix,
  19.    EmailAddress = @EmailAddress, Phone = @Phone, PasswordHash = @PasswordHash,
  20.    PasswordSalt = @PasswordSalt
  21. WHERE ContactID = @ContactID
  22. GO
  23.  
  24.  

--- CK
Apr 2 '09 #5
Thanks. I didn't notice I was missing some commas, and those Name and Phone references didn't help.
Apr 2 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: A.M. de Jong | last post by:
How does MicroSoft store the stored procedures in seperate files. What tools are used. Cause that's what I like to do too. Arno de Jong, The Netherlands. (SCPTFXR does not have the option to...
12
by: Sanjay | last post by:
hi, We are currently porting our project from VB6 to VB .NET. Earlier we used to make scale transformations on objects like pictureBox , forms etc.Now Such transformations are made on the...
2
by: serge | last post by:
My project is to automate testing of Stored Procedures of type SELECT (at least for now). I want to create a table where each stored procedure's input parameter values are entered and in another...
2
by: Kent Lewandowski | last post by:
hi all, Recently I wrote some stored procedures using java jdbc code (admittedly my first stab) and then tried to implement the same within java packages (for code reuse). I encountered...
1
by: esmith2112 | last post by:
We all of a sudden find ourselves in dire straits, because we have one of those mysteries where everything used to work, and apparently, all of a sudden everything went to pot just in time for a...
5
by: George Durzi | last post by:
I have a company form that I need to web-enable. The form has about 50 data items with some of these data items able to have N sub data items. I'm considering ways to store this form in my...
3
by: Solution Seeker | last post by:
I want to Store the String value with Single Quotes in the Field of Database where if i try to Store the String value with Single Quotes (as it is) then it is throwing the error as SQL String...
4
by: Marc | last post by:
Hi: Does anyone know if any IBM branch across the country offers Store procedure classes?. Thanks Marc
28
by: mooreit | last post by:
The purpose for my questions is accessing these technologies from applications. I develop both applications and databases. Working with Microsoft C#.NET and Microsoft SQL Server 2000 Production and...
4
by: seep | last post by:
hi.. i m working with vb.net 1st time. i wants to work with stored procedures. i have created stored procedures successfully but have no idea about how to code in vb.net to use these store...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.