7 February, 2012
4 Comments
1 category
Well for ages, I created mine stored procedures like:
if exists (select 1 from sys.objects where name = 'GetSales' and type = 'p') begin drop procedure [Reporting].[GetSales] end go create procedure [Reporting].[GetSales] @parameter1 int, @parameter2 int as begin select @parameter1, @parameter2 end go
, but there is a slightly shorter notation:
if object_id('[Reporting].[GetSales]') is not null begin drop procedure [Reporting].[GetSales] end go create procedure [Reporting].[GetSales] @parameter1 int, @parameter2 int as begin select @parameter1, @parameter2 end go
Youβre never to old to learn .
Tags: T-SQL
Category: Uncategorized
And I though you knew everything there is to know. Caught me off guard here π
hahaahahahahahahahahahahaahahaha
hahaahahahahahahahahahahaahahaha
hahaahahahahahahahahahahaahahaha
hahaahahahahahahahahahahaahahaha
Nope, but some people believe the internet starts and ends at the knowledgebase π
But now you’re deleting the GetSales Table !! π
And then the create procedure fails.
Nope, a stored procedure and a table can’t have the same name in the same schema, so you can’t have a table [Rapportage].[GetSales] and a table [Rapportage].[GetSales].
So the code above will always drop the stored procedure [Rapportage].[GetSales] en then create it.