Which is the correct syntax for Stored procedure in SQL server ?
which one is correct ???
1. CREATE PROCEDURE procedure_name
AS
sql_statement
GO;
OR
2. CREATE PROCEDURE [schema_name].procedure_name
@parameter_name data_type,
....
parameter_name data_type
AS
BEGIN
-- SQL statements
-- SELECT, INSERT, UPDATE, or DELETE statement
END
Rajeev KumarPosted Mar 14, 2023, 7:44 AM
CREATE procedure [dbo].[Usp_GetArticleDealDiscount]
@Articleid int
AS
Begin
Declare @SubscriptionPublishedDate datetime,@NetPriceAfterExchangeRate decimal(12,2),@JournalTypeid int
-- SQL statements -- SELECT, INSERT, UPDATE, or DELETE statement END
Satya KarkiPosted Nov 9, 2022, 10:27 AM
Hi, both Syntaxes are correct, Based on the need it depends on which one to use. The first one you can use when you don't need to pass parameters in the query such as SQL queries to select all values without where condition(s). The second one you can use when you need a parameterized query.
You can check the below link for a sample.
https://www.w3schools.com/sql/sql_stored_procedures.asp
Vishal JoshiPosted Nov 9, 2022, 7:32 AM
Hello
Both syntaxes are correct. there are several properties we can configure during create procedure. like, parameterize, with output variable with NoCount, etc.
So, it depends on the requirements we can write a stored procedure. below is the default syntax:
Vishal YelvePosted Nov 9, 2022, 7:02 AM
Brahma Prakash ShuklaPosted Nov 8, 2022, 7:16 PM
The syntax to create a stored procedure in SQL Server (Transact-SQL) is: CREATE { PROCEDURE | PROC } [schema_name.] procedure_name [ @parameter [type_schema_name.] datatype [ VARYING ] [ = default ] [ OUT | OUTPUT | READONLY ] , @parameter [type_schema_name.]