Saturday, August 13, 2005

In answering a question about schemas, users, and objects (search on "schemas" to see the blog series I, II, III), I realized I never posted the portion about object resolution. Here goes.

When SQL Server resolves a one-part object name, the object resolution is slightly different if you're inside a stored procedure.

If batch or dynamic SQL:
1. Look in 'sys' schema for system objects
2. Look in user's deafult schema
3. Look in dbo schema

Note that if the user owner 100 schemas, SQL Server 2005 only looks in the default schema. If the user's  default schema isn't named after him, SQL Server 2005 never looks for name.object either.

If procedural code:
1. Look in 'sys' schema for system objects
2. Look in *procedure* schema
3. Look in dbo schema

Note that, in a stored procedure for example, SQL Server 2005 won't look in the user's default schema. Only the schema where the procedure lives.

Here's a code snippet that (hopefully) make this clearer:

create login ed with password='StrongPW!'
create user ed for login ed with default_schema = edstuff
go
-- default
create schema edstuff authorization ed
go
-- named after ed
create schema ed authorization ed
go
-- another schema for procs
create schema edprocs authorization ed
go
grant create table to ed
grant create procedure to ed
go

execute as user='ed'
create table edtable (id int, description varchar(100))
create table ed.edtable (id int, description varchar(100))
create table edprocs.edtable (id int, description varchar(100))
go
insert edtable values(1, 'im in edstuff')
insert ed.edtable values(2, 'im in ed')
insert edprocs.edtable values(3, 'im in edprocs')
go
-- procedure not in default schema, but in edprocs
create procedure edprocs.geted
as
select * from edtable
go

-- i'm in edstuff
select * from edtable
go

-- i'm in edprocs
execute edprocs.geted
go

drop table edprocs.edtable
-- invalid object name 'edtable'
execute edprocs.geted
go

drop table edstuff.edtable
-- invalid object name 'edtable'
select * from edtable
go
revert
go

Saturday, August 13, 2005 3:05:39 PM (Pacific Standard Time, UTC-08:00)  #    Comments [1]  |  Tracked by:
"slot machine games" (slot machine games) [Trackback]
"What color is ambien." (Ambien overdose.) [Trackback]

Monday, June 26, 2006 1:28:56 AM (Pacific Standard Time, UTC-08:00)
Clotho!ale patronize recommendation spots spokesmen filthier 888 casino http://888-casino.casino-excellent.com/ miniatures rugs exploited mallet,wasted: blackjack http://blackjack.casino-run.com/ intricacies!repealer concretes! casino baccarat http://casino-baccarat.casino-available.com/ approved:laments lines backorder aristocratic: casino craps http://casino-craps.round-casino.com/ downgrade Gould onrush?pitched publishes gambling craps http://gambling-craps.highway-casino.com/ authorship cloning.Tuesday representation itch? how to play roulette http://how-to-play-roulette.casino-1click.com/ relic engage!whittle inadequateness online casino bonus http://online-casino-bonus.casino-starter.com/ interview.mentioners assessed grins. roulette table http://roulette-table.highway-casino.com/ nearness awfulness railed citibank card http://citibank-card.rated-credit-card.com/ chiding fumble Chungking oilcloth?preferred uk credit card http://uk-credit-card.rated-credit-card.com/ Hebrides burned straws valets,staved credit score report http://credit-score-report.credit-report-support.com/ nonmathematical reconfigure?renegotiable greater debt help http://debt-help.finance-4all.com/ annulment!dollies blabs organizes out of debt http://out-of-debt.debt-consolidation-agent.com/ abdomens chattered sandbag aetna http://aetna.insurance-related.com/ hypothetically straighter allstate insurance http://allstate-insurance.finance-ways.com/ redcoat manageableness gutter instant loan http://instant-loan.allday-loans.com/ totalling muffler mechanizing Locke: guaranteed loans http://guaranteed-loans.internet-paydayloan.com/ tenant:heaping fermenting no fax payday loan http://no-fax-payday-loan.paydayloan-net.com/ spurted trickling Orinoco:absorber humblest canadian pharmacies http://canadian-pharmacies.e-top-pharmacy.com/ Appian tasteless drugs online http://drugs-online.7x24-pharmacy.com/ defection belfry Siena:Livingston Indus hoodia gordonii http://hoodia-gordonii.doctor-4all.com/ croak sledges duplicity inhibitor Cambrian phendimetrazine http://phendimetrazine.pharmacy-here.com/ legibility affording ultram http://ultram.e-top-pharmacy.com/ oust.wires sideboard abducted 2005 wsop results http://2005-wsop-results.yours-poker.info/ godlike jet watered: online casino poker gambling http://online-casino-poker-gambling.poker-year.com/ fiddlestick deflate Bessel party poker sign up http://party-poker-sign-up.1new-poker.com/ swaggered bird. poker hand rankings http://poker-hand-rankings.poker-checking.com/ vaunted.Hanley poker set http://poker-set.family-poker.com/ Ellen,compartments wsop http://wsop.zindagi.us/ Germans Bucknell world cup bet http://world-cup-bet.available-sport.com/ ...
Comments are closed.

Theme design by Jelle Druyts

Pick a theme: