Wednesday, March 7, 2012

call order

If a VIEW and a STORED PROCEDURE exist and have the same identical name -
is there a particular call sequence that SQL SERVER uses -
in other words if the particular name is called up in code - does SQL pull
the view first or the SP first.Not possible. Try below:
USE tempdb
GO
CREATE PROC xyz AS SELECT 1 AS s
GO
CREATE VIEW xyz AS SELECT 1 AS s
Object names need to be unique. And even if SQL Server would allow it, there
would not be any
ambiguity. You don't use a stored procedure and a view in the same way.
You execute a stored procedure. You don't execute a view.
You select data from a view. You don't select data from a stored procedure.
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://www.solidqualitylearning.com/
http://www.sqlug.se/
"jduran" <jduran@.discussions.microsoft.com> wrote in message
news:A0D23A66-F34E-4177-9C79-54D92ABB216B@.microsoft.com...
> If a VIEW and a STORED PROCEDURE exist and have the same identical name -
> is there a particular call sequence that SQL SERVER uses -
> in other words if the particular name is called up in code - does SQL pul
l
> the view first or the SP first.|||Hi
This should not occur as the names must be unique
CREATE PROCEDURE MyProc
AS
SELECT * FROM SYSOBJECTS
CREATE VIEW MyProc AS SELECT * FROM SYSOBJECTS
Server: Msg 2714, Level 16, State 5, Procedure MyProc, Line 1
There is already an object named 'MyProc' in the database.
Using a strict naming convention policy to distinguish objects is also a
good idea.
John
"jduran" wrote:

> If a VIEW and a STORED PROCEDURE exist and have the same identical name -
> is there a particular call sequence that SQL SERVER uses -
> in other words if the particular name is called up in code - does SQL pul
l
> the view first or the SP first.|||You can not create two objects with the same name. Even if you could, you ca
n
not select from an sp or execute a view.
Example:
use northwind
go
create procedure proc1
as
return 0
go
-- this will give an error
create view proc1
as
select * from orders
go
drop procedure proc1
go
AMB
"jduran" wrote:

> If a VIEW and a STORED PROCEDURE exist and have the same identical name -
> is there a particular call sequence that SQL SERVER uses -
> in other words if the particular name is called up in code - does SQL pul
l
> the view first or the SP first.

No comments:

Post a Comment