Re: How many objects are owned by schema
- From: "Dan Guzman" <guzmanda@xxxxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Tue, 5 May 2009 07:50:13 -0500
I'm not Dan, but my guess to what he meant is:
You can create a user (a.k.a. "database principal") without specifying a login, as in:
CREATE USER no_login WITHOUT LOGIN
Yes, Tibor, a user without a login was exactly what I was referring to. Schema and objects must be owned by a valid database principal but the database principal doesn't necessarily need to be associated with a login for ownership purposes.
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"Tibor Karaszi" <tibor_please.no.email_karaszi@xxxxxxxxxxxxxxxxxx> wrote in message news:OyYm1lWzJHA.1420@xxxxxxxxxxxxxxxxxxxxxxx
I'm not Dan, but my guess to what he meant is:
You can create a user (a.k.a. "database principal") without specifying a login, as in:
CREATE USER no_login WITHOUT LOGIN
I have a feeling that Dan was referring to such a user...
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Martin" <martin_remove_this_@xxxxxxxxxxxxx> wrote in message news:30FDEA56-BE2E-4DA7-B828-D013B7A06CEF@xxxxxxxxxxxxxxxxHi dan,
thanks for the reply and pointing me to your article, however I have a question about that.
you state in the post
"Note that an owner can be any database principal and does not necessarily need to be associated with a login." - start of 2nd last paragraph.
how does this work. I tried it myself and got an error.
ALTER AUTHORIZATION ON OBJECT::dbo.testtable TO myself; ("myself" is neither a server login or a user in the database)
my understanding is that a login is a server level object (gives a user access to the server) and a user is a specific login that has been granted access to a particular database.
I do not understand how
1. an object can be owned by anthing that does not have access to either the db or he server.
I guess you could create a role, and that would get added to sys.database_principles and then that role could own an object.
can you shed any light on this please - perhaps I have interpretted you incorrectly.
also
I created an table in a test database
create table dbo.testtable
(
test int
)
next I altered the authorization to a user - Note "testuser" is a database user and not a schema.
ALTER AUTHORIZATION ON OBJECT::dbo.testtable TO testuser;
That is fine - works a treat.
I refreshed the database tree in object explorer SSMS.
in the tables branch "testtable " is still seen as " dbo.testtable" and not " testuser.testtable"
I looked at sys.objects and the data "principle_id" column hat was NULL, now has the ID of "testuser" - although the "schema_id" column still has the id of "dbo"
I attempted to alter the authorization back to dbo
ALTER AUTHORIZATION ON OBJECT::testuser.testtable TO dbo; --- did not work -- testuser.testtable does not exist
however
ALTER AUTHORIZATION ON OBJECT::dbo.testtable TO dbo; -- works fine.
I am assuming a principle owning an object is different that a schema owing an object.
I guess object are only meant to be owned by schemas.
an thoughts on this.
Thanks for your time.
cheers
martin.
"Dan Guzman" <guzmanda@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message news:#aMzCXRzJHA.2324@xxxxxxxxxxxxxxxxxxxxxxxI actually thought that all objects belonged to schemas in 2k5/8.
This is true. Schema-contained objects belong to exactly one schema. Separately, every schema has an owner (a.k.a. authorization) and object ownership is inherited from the containing schema unless specified otherwise.
in what circumstances would an object belong to a user - how would you do this.
Although seldom done in practice, one can specify an owner at the object level to override inheritance from the schema. This is done via ALTER AUTHORIZATION:
ALTER AUTHORIZATION ON OBJECT::dbo.Foo TO SomeOtherDatabasePrincipal;
I blogged my thoughts on schema and ownership at http://weblogs.sqlteam.com/dang/archive/2008/02/03/Keep-Schema-and-Ownership-Simple.aspx.
--
Hope this helps.
Dan Guzman
SQL Server MVP
http://weblogs.sqlteam.com/dang/
"Martin" <martin_remove_this_@xxxxxxxxxxxxx> wrote in message news:72DB4628-03C2-419D-A2A6-F62D68493FD4@xxxxxxxxxxxxxxxxHi Tibor,
That is exactly what I meant.
You interpreted my question correctly.
I'll try to use the correct terminology next time.
however, one of the point you seem to make is
An object is also owned by a user (most often the same user as the one who owns the schema the object is in).
I actually thought that all objects belonged to schemas in 2k5/8.
in what circumstances would an object belong to a user - how would you do this.
cheers
martin.
"Tibor Karaszi" <tibor_please.no.email_karaszi@xxxxxxxxxxxxxxxxxx> wrote in message news:O79#h6JzJHA.480@xxxxxxxxxxxxxxxxxxxxxxxMartin,
Something doesn't add up here. An object is in a schema. A schema is owned by a user. An object is also owned by a user (most often the same user as the one who owns the schema the object is in). But an object is not owned by a schema. Perhaps you meant to identify what objects *are* in a schema? That would be a simple join between sys.objects and sys.schemas (using the schema_id column).
--
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
"Martin" <martin_remove_this_@xxxxxxxxxxxxx> wrote in message news:3B8EA770-667D-45E9-ABD9-07F64063DBFE@xxxxxxxxxxxxxxxxhi,
I am looking to identify objects that are owned by a schema.
Is there a way of querying this from the system tables at all.
I'd prefer to do this via a query rather than looking through SSMS.
I managed to write a query to get the owner
select * from sys.schemas
join sys.sysusers
ON sys.schemas.name = sys.sysusers.name
where sys.schemas.principal_id between 5 and 16383;
I guess that I need to join this onto another table - maybe sysobjects - but I am not sure.
any help appreciated
cheers
martin.
.
- Follow-Ups:
- Re: How many objects are owned by schema
- From: Martin
- Re: How many objects are owned by schema
- References:
- How many objects are owned by schema
- From: Martin
- Re: How many objects are owned by schema
- From: Tibor Karaszi
- Re: How many objects are owned by schema
- From: Martin
- Re: How many objects are owned by schema
- From: Dan Guzman
- Re: How many objects are owned by schema
- From: Martin
- Re: How many objects are owned by schema
- From: Tibor Karaszi
- How many objects are owned by schema
- Prev by Date: Update datetime
- Next by Date: Re: Update datetime
- Previous by thread: Re: How many objects are owned by schema
- Next by thread: Re: How many objects are owned by schema
- Index(es):
Relevant Pages
|