SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Create stored procedure


Create stored procedure

Author
Message
UMG Developer
UMG Developer
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4146 Visits: 2204
Thanks for the interesting question.
ziangij
ziangij
Hall of Fame
Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)Hall of Fame (3.6K reputation)

Group: General Forum Members
Points: 3626 Visits: 377
Another "funny" thing is that BEGIN...END does not define the body of the procedure. You can have multiple BEGIN...END in the body of a procedure, like this:
create proc test
as
begin
select 1
end
begin
select 2
end

Executing "test" will return two recordsets.

A procedure can have an empty body, but BEGIN...END cannot be empty.


This one is pretty interesting. I really didn't know that by adding Begin, End (twice or more), we can return 2 recordsets. But I dont think this type of proc can ever be used.

Has anybody tried using sp_spaceused (returns 2 recordsets) in a select query ? Its just not possible.
Koen Verbeeck
Koen Verbeeck
SSC Guru
SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)SSC Guru (64K reputation)

Group: General Forum Members
Points: 64930 Visits: 13298
Nice question, thanks.


How to post forum questions.
Need an answer? No, you need a question.
What’s the deal with Excel & SSIS?
My blog at SQLKover.

MCSE Business Intelligence - Microsoft Data Platform MVP
tejaswini.patil
tejaswini.patil
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1174 Visits: 234
I agree with Ron.

This question made us look into the basics of naming conventions.

Thanks for the question.
Duncan Pryde
Duncan Pryde
SSCarpal Tunnel
SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)SSCarpal Tunnel (4.2K reputation)

Group: General Forum Members
Points: 4206 Visits: 1552
Here's where it's useful. If you want an alternative to the DROP and CREATE method of maintaining stored procedure scripts - which would overwrite metadata about when a procedure was first created - you can use this:

IF OBJECT_ID ( '[dbo].[NewProcedure]', 'P' ) IS NULL 
BEGIN
EXEC ('CREATE PROCEDURE [dbo].[NewProcedure] AS')
END
GO
ALTER PROCEDURE [dbo].[NewProcedure]
-- Procedure code goes here



Just an idea.
amit_adarsh
amit_adarsh
SSC Eights!
SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)SSC Eights! (846 reputation)

Group: General Forum Members
Points: 846 Visits: 169
You can not use any special character as a first later of procedure name except _ .
Nakul Vachhrajani
Nakul Vachhrajani
Hall of Fame
Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)Hall of Fame (3.4K reputation)

Group: General Forum Members
Points: 3360 Visits: 2149
amit_adarsh (3/17/2011)
You can not use any special character as a first later of procedure name except _ .


That is because they are not supported by the naming conventions for identifiers. Please go back to the 1st page of the discussion where I have explained why the SQL Server allows you to create this particular stored procedure.

Thanks & Regards,
Nakul Vachhrajani.
http://nakulvachhrajani.com
Be courteous. Drive responsibly.

Follow me on
Twitter: @sqltwins
Google Plus: +Nakul
Toreador
Toreador
Hall of Fame
Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)Hall of Fame (3.9K reputation)

Group: General Forum Members
Points: 3878 Visits: 8129
ziangij (3/16/2011)I really didn't know that by adding Begin, End (twice or more), we can return 2 recordsets.


You don't need multiple begin/end pairs to return 2 recordsets.

create proc test
as
begin
select 1
select 2
end



or

create proc test
as
select 1
select 2



will do just as well.

We make regular use of procedures returning multiple recordsets. Using ADO you just use NextRecordSet to get at the data.
Dwayne Dibley
Dwayne Dibley
Right there with Babe
Right there with Babe (730 reputation)Right there with Babe (730 reputation)Right there with Babe (730 reputation)Right there with Babe (730 reputation)Right there with Babe (730 reputation)Right there with Babe (730 reputation)Right there with Babe (730 reputation)Right there with Babe (730 reputation)

Group: General Forum Members
Points: 730 Visits: 3171
Bala' (3/16/2011)
Its not really adding any value..


There is actually quite a lot of value. When creating a system in a team environment, it allows the db developer to create all the procedure stubs initiallly even though they may not return any values. In turn, this allows the front end coders get on with coding the data access layer to an extent. The db developer can then continue addig the function bodies without other developers screaming at him to hurry up.

You may not see the value, but it is there for somebody.
SanDroid
SanDroid
SSCrazy
SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)SSCrazy (2.5K reputation)

Group: General Forum Members
Points: 2490 Visits: 1046
rjohal-500813 (3/17/2011)
Bala' (3/16/2011)
Its not really adding any value..


You may not see the value, but it is there for somebody.


Cool I would have to agree with that. ;-) Somebody out there sees all kinds of value in SQL developers and DBA's know the minimum amount of code required to create Procedures and Functions. Most likely why it is on the Certification exams.
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search