Welcome to Scribd. Sign in or start your free trial to enjoy unlimited e-books, audiobooks & documents.Find out more
Download
Standard view
Full view
of .
Look up keyword
Like this
19Activity
0 of .
Results for:
No results containing your search query
P. 1
Stored Procedure

Stored Procedure

Ratings: (0)|Views: 351|Likes:
Published by sthombare

More info:

Published by: sthombare on Oct 16, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOC, PDF, TXT or read online from Scribd
See more
See less

02/26/2013

pdf

text

original

 
CREATE PROCEDURETopic last updated -- June 2007
Creates a stored procedure, which is a saved collection of Transact-SQL statements thatcan take and return user-supplied parameters.Procedures can be created for permanent use or for temporary use within a session (localtemporary procedure) or for temporary use within all sessions (global temporary procedure).Stored procedures can also be created to run automatically when Microsoft® SQLServer™ starts.
Syntax
CREATE PROC [ EDURE ] [
owner 
.
]
 procedure_name
[
;
number 
][ { @
 parameter data_type
}
 
[ VARYING ] [
=
default 
] [ OUTPUT ]] [
,
...
n
][ WITH{ RECOMPILE | ENCRYPTION | RECOMPILE
,
ENCRYPTION } ][ FOR REPLICATION ]AS
 sql_statement 
[ ...
n
]
Arguments
owner 
Is the name of the user ID that owns the stored procedure.
owner 
must be either the nameof the current user or the name of a role that a current user is a member of.
 procedure_name
 
Is the name of the new stored procedure. Procedure names must conform to the rules for identifiers and must be unique within the database and its owner. For more information,seeUsing Identifiers.Local or global temporary procedures can be created by precedingthe
 procedure_name
with a single number sign (#
 procedure_name
) for local temporary procedures and a double number sign (##
 procedure_name
) for global temporary procedures. The complete name, including # or ##, cannot exceed 128 characters.Specifying the procedure owner name is optional.
;
number 
Is an optional integer used to group procedures of the same name so they can be droppedtogether with a single DROP PROCEDURE statement. For example, the procedures usedwith an application called orders may be named
orderproc
;1,
orderproc
;2, and so on.The statement DROP PROCEDURE
orderproc
drops the entire group. If the namecontains delimited identifiers, the number should not be included as part of the identifier;use the appropriate delimiter around
 procedure_name
only.@
 parameter 
Is a parameter in the procedure. One or more parameters can be declared in a CREATEPROCEDURE statement. The value of each declared parameter must be supplied by theuser when the procedure is executed (unless a default for the parameter is defined or thevalue is set to equal another parameter). A stored procedure can have a maximum of 2,100 parameters.Specify a parameter name using an at sign (@) as the first character. The parameter namemust conform to the rules for identifiers. Parameters are local to the procedure; the same parameter names can be used in other procedures. By default, parameters can take the place only of constants; they cannot be used in place of table names, column names, or the names of other database objects. For more information, see EXECUTE.
data_type
 
Is the parameter data type. All data types, except the
table
data type, can be used as a parameter for a stored procedure. However, the
cursor
data type can be used only onOUTPUT parameters. When you specify a data type of 
cursor
, the VARYING andOUTPUT keywords must also be specified. For more information about SQL Server -supplied data types and their syntax, seeData Types.
Note
There is no limit on the maximum number of output parameters that can beof 
cursor
data type.VARYINGSpecifies the result set supported as an output parameter (constructed dynamically by thestored procedure and whose contents can vary). Applies only to cursor parameters.
default 
Is a default value for the parameter. If a default is defined, the procedure can be executedwithout specifying a value for that parameter. The default must be a constant or it can be NULL. It can include wildcard characters (%, _, [], and [^]) if the procedure uses the parameter with the LIKE keyword.OUTPUTIndicates that the parameter is a return parameter. The value of this option can bereturned to EXEC[UTE]. Use OUTPUT parameters to return information to the calling procedure.
Text
,
ntext
, and
image
parameters can be used as OUTPUT parameters. Anoutput parameter using the OUTPUT keyword can be a cursor placeholder.
n
Is a placeholder indicating that a maximum of 2,100 parameters can be specified.{RECOMPILE | ENCRYPTION | RECOMPILE
,
ENCRYPTION}RECOMPILE indicates that SQL Server does not cache a plan for this procedure and the procedure is recompiled at run time. Use the RECOMPILE option when using atypical or temporary values without overriding the execution plan cached in memory.

Activity (19)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
ilyasamine liked this
Gurmukh Singh liked this
sagerofgyan liked this
jayavardhankoti liked this
highlander2006 liked this
thiyagani liked this
wepsm liked this
Vinesh liked this

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->