Solved

Which is correct declaration of Stored Procedure - SQL Server

Posted on 2011-09-05
5
257 Views
Last Modified: 2012-06-27
Hi,

I can write the stored procedure in these ways:

CREATE PROCEDURE dbo.P(@X int, @Y int)
AS
BEGIN

END

CREATE PROCEDURE dbo.P
@X int,
@Y int
AS
BEGIN

END

Which one is correct syntax ? Which one needs to be used when ?

Thanks
0
Comment
Question by:milani_lucie
5 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 167 total points
ID: 36485776
for CREATE PROCEDURE you should not use parenthesis, but for CREATE FUNCTION, you should.

See the difference between

http://msdn.microsoft.com/en-us/library/ms187926.aspx

and

http://msdn.microsoft.com/en-us/library/ms186755.aspx
0
 
LVL 6

Expert Comment

by:jorgedeoliveiraborges
ID: 36485963
After the creation of the procedure P (with the first syntax), try to re-generate the scripts within «SQL Server Management Studio».
Do the same with the second syntax.

Compare the results.
0
 
LVL 21

Assisted Solution

by:Alpesh Patel
Alpesh Patel earned 167 total points
ID: 36486778
CREATE PROCEDURE dbo.P
@X int,
@Y int
AS
BEGIN

END

is the correct syntax
0
 
LVL 1

Assisted Solution

by:FreelanzWithUs
FreelanzWithUs earned 166 total points
ID: 36489577
You should not use ( ) for stored procedures so the below will be correct

CREATE PROCEDURE dbo.P
@X int,
@Y int
AS
BEGIN

END
0
 
LVL 7

Expert Comment

by:Kishan Zunjare
ID: 36490720
hi,

A stored procedure or in simple a proc is a named SQL block which performs one or more specific task. This is similar to a procedure in other .NET languages.
A procedure may or may not return any value.

General Syntax to create a procedure is:

CREATE PROCEDURE dbo.sp_TestProc
AS
    SELECT FirstName, LastName FROM Person.Person;
GO


Syntax to Execute Stored procedure
EXEC sp_TestProc;
EXEC dbo.sp_TestProc;
GO

Syntax to delete Stored procedure
DROP PROCEDURE dbo.sp_TestProc;
GO

Let me know if you need more details on this.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question