Groups | Blog | Home
all groups > sql server programming > april 2007 >

sql server programming : SQL Management Studio - Create Stored Procedure - Frustrated


RosH
4/7/2007 11:35:11 PM
Hi,

I may sound a foolish newbie, but I am totally frustrated trying to
create a new Stored procedure in SQL server Management studio. I made
all the database tables and created a diagram and the relationships
and even tried out VBA connectivity which is working fine. I tried
creating a stored procedure inside MS and got glued to it unable to do
it correctly.

[quoted text, click to view]
went to Programmability > Stored Procedures. Right clicked and
selected "New Stored Procedure" and it opened up a template as given
below.

-- ================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>
-- Add the parameters for the stored procedure here
<@Param1, sysname, @p1> <Datatype_For_Param1, , int> =
<Default_Value_For_Param1, , 0>,
<@Param2, sysname, @p2> <Datatype_For_Param2, , int> =
<Default_Value_For_Param2, , 0>
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

-- Insert statements for procedure here
SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
END
GO
--------------------------------

I personalised the procedure to match my requirement and put a USE
<database> command on top and clicked save. Now MS after opening up
the save to dialog box is asking me to save the SQL query on some
location on my harddisk. "Mr. Management Studio, I need you to save
the procedure into the database, not outside." I cant find the
procedure in the Stored procedure section also after saving.

Any one here with a remedy? Help, I'm stuck on this simple thing for
two days.
Erland Sommarskog
4/8/2007 12:00:00 AM
RosH (roshin.majeed@gmail.com) writes:
[quoted text, click to view]

You may have been brainwashed by bad tools such as the Enterprise Manager
in SQL 2000 which makes you believe that you save stuff in the database.
The database is just a binary container for your code. When you save
code, you save it to disk, and hopefully you also put in under version
control.

To create the procedure, you just run the script by pressing the Execute
command. This is akin to compile a program in traditional language.

--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Adi
4/8/2007 12:03:11 AM
[quoted text, click to view]

The save button is for saving the code as a text file on the disk.
You have to run the create procedure statement in order to create it
in the database. You can press the Execute button on the tool bar or
press CTRL + E.

Adi
RosH
4/8/2007 3:47:02 AM
[quoted text, click to view]

Thank you Adi and Erland. I now understood the concept. I am
executing a piece of query for creating a stored procedure.

I am now faced with another challenge. When I press the execute
button, one of the error messages says that either the database does
not exist or I dont have permission to use it. Ok, i know that the
database exists, the reason should be that I dont have permissions.
Any views?
Erland Sommarskog
4/8/2007 4:17:25 PM
RosH (roshin.majeed@gmail.com) writes:
[quoted text, click to view]

Did you connect with the same user to create the procedure as when you
create the table? Are you able tp see the database name in the drop-down
box in the toolbar?


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
RosH
4/9/2007 2:55:32 AM
[quoted text, click to view]

I have not changed user at any point of time, I used Windows
authentication for the connection string. Yes, I am able to see the
database in the drop down box in the toolbar.

But when I checked today morning after restarting the server,
everything was working absolutely fine. Thank you for your continued
effort for making it happen. See ya with a new challenge.
AddThis Social Bookmark Button