Re: Stored procedure, which table is used ?
From: ben brugman (ben_at_niethier.nl)
Date: 02/20/04
- Next message: Dji_c: "Re: Data file growth not save"
- Previous message: treesy: "Re: Problem: sql server 2000 server low performance. thanks:)"
- In reply to: chris: "Stored procedure, which table is used ?"
- Next in thread: Tibor Karaszi: "Re: Stored procedure, which table is used ?"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 20 Feb 2004 09:20:49 +0100
> >CREATE PROCEDURE sp_demo AS
> >select * from demotable
> >exec ('select * from demotable')
> >GO
The first select takes the table from Master.
The second select (in the exec) takes the table from the
environment were it is run.
(See the example at the end of my original message.)
ben brugman
"chris" <anonymous@discussions.microsoft.com> wrote in message
news:1260b01c3f701$28bbf360$a101280a@phx.gbl...
> >Which table does a stored procedure use when
> >run in the Query analyser under local database.
>
> Whichever table the proc calls.
>
> I may not be following here. All your queries and all your
> procs will run in the local db by default. The exception
> to this would proably be some of the "sp_"'s which will
> probably be run in Master even if called from a user db.
>
>
>
>
> >-----Original Message-----
> >A stored procedure in the master database.
> >
> >Which table does a stored procedure use when
> >run in the Query analyser under local database.
> >If I do a 'normal' select from, it tries to read the
> >table form master.
> >During an exec the table comes from local database.
> >
> >Why the difference ?
> >
> >What should I do to 'force' the 'local' table from
> database ?
> >
> >Using an exec around all my queries is less elegant.
> >(more confusing and error prone).
> >Is there a design that I am missing ?
> >
> >ben brugman
> >
> >
> >RESULTS FROM HERE :
> >
> >OKKI
> >------
> >Master
> >
> >(1 row(s) affected)
> >
> >OKKI
> >----------
> >LocalDatabase
> >
> >THE DEMO CODE :
> >
> >-- In the master database.
> >use master
> >go
> >CREATE PROCEDURE sp_demo AS
> >select * from demotable
> >exec ('select * from demotable')
> >GO
> >
> >
> >-- In the master database.
> >use master
> >select 'Master' as OKKI INTO DEMOTABLE
> >
> >
> >-- In another database.
> >use LocalDatabase
> >select 'LocalDatabase' as OKKI INTO DEMOTABLE
> >
> >--In the query analyser run the sp_demo under
> >--the another database.
> >--
> >--
> >print 'RESULTS FROM HERE :'
> >use LocalDatabase
> >
> >exec sp_demo
> >
> >use LocalDatabase
> >drop table demotable
> >
> >use master
> >drop table demotable
> >drop procedure sp_demo
> >
> >
> >.
> >
- Next message: Dji_c: "Re: Data file growth not save"
- Previous message: treesy: "Re: Problem: sql server 2000 server low performance. thanks:)"
- In reply to: chris: "Stored procedure, which table is used ?"
- Next in thread: Tibor Karaszi: "Re: Stored procedure, which table is used ?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|