Showing posts with label schema. Show all posts
Showing posts with label schema. Show all posts

Friday, March 9, 2012

Ownership in SQL 2005

Hi there,
maybe I've misunderstood something but i just read this phrase in BOL :
"All tables in the partition's schema must have the same owner; for example,
you cannot have a FROM clause that references the tables [tk].[custo
mer],
[john].[store], and [dave].[sales_fact_2004]"
Talking about SQL 2005 I would think that we now are refering to schemas and
in this example it is 3 schemas and they can easily have the same owner.. Or
am I wrong ? BOL furthermore states that using schemas make things a lot
easier. For the most I guess. But you can now have one user owning the
schema and another user owning a table in that schema, so how does this make
the transfering of an ownership easier ? I've read the following : "Now
database objects are owned by schemas. Users no longer direcly own database
objects; instead they own schemas". Well that would have simplified things
but apparently it isn't so! The MOC 2733 states the following about schemas
: "Improved manageability, because dropping a user does not necessitate the
renaming of all objects that the user owns". In the above example I could
have a schema owned by "dbo" and maby 20 tables in that schema owned by
"user1". How do I easily drop that user ? And here's some more fun :
Creating a schema owned by dbo and creating a new table in that schema the
table inherits the ownership from the schema so therefore the owner of the
table is dbo, too. Pretty straightforward. If I change the ownership of the
schema to user1 the table inherits the ownership and changing it back to dbo
does the same thing. But changing the ownership explicitly to the table
changes things. Changing the ownership of the schema does NOT change the
ownership of the table )
Anyone have some really good article explaining this ?
Regards
Bobby Henningsen> "All tables in the partition's schema must have the same owner; for
> example,
> you cannot have a FROM clause that references the tables [tk].[cus
tomer],
> [john].[store], and [dave].[sales_fact_2004]"
> Talking about SQL 2005 I would think that we now are refering to schemas
> and
> in this example it is 3 schemas and they can easily have the same owner..
> Or
> am I wrong ?
The context of this BOL statement is requirements for indexed views. The
'owner' requirement for indexed views is the schema owner, not the schema
name. It is possible to create an index on a view referencing tables in
different schema as long as schema share the same owner.

> I've read the following : "Now database objects are owned by schemas.
I don't know where this excerpt is from. Database objects are owned by
users as they always have been. The difference in SQL 2005 is that
ownership is via the schema owner so the schema name can be different than
the owner name. Consider:
CREATE USER Bobby WITHOUT LOGIN
GO
CREATE SCHEMA john AUTHORIZATION Bobby
CREATE SCHEMA dave AUTHORIZATION Bobby
GO
CREATE TABLE [john].[store](...)
CREATE TABLE [dave].[sales_fact_2004](...)
GO
In this example, the user Bobby owns both tables because schema 'john' and
'dave' are both owned by user 'Bobby'.

> How do I easily drop that user ?
To drop user Bobby, you would first need to change schema owner to another
user:
ALTER AUTHORIZATION ON SCHEMA::john TO SomeOtherUser;
ALTER AUTHORIZATION ON SCHEMA::dave TO SomeOtherUser;
GO
DROP USER Bobby
GO
It gets confusing because a schema name and owner name can also be the same.
Be mindful that these are actually separate.
Hope this helps.
Dan Guzman
SQL Server MVP
"Bobby Henningsen" <bobhen@.mail.dk> wrote in message
news:OkjqgExXGHA.1200@.TK2MSFTNGP03.phx.gbl...
> Hi there,
> maybe I've misunderstood something but i just read this phrase in BOL :
> "All tables in the partition's schema must have the same owner; for
> example,
> you cannot have a FROM clause that references the tables [tk].[cus
tomer],
> [john].[store], and [dave].[sales_fact_2004]"
> Talking about SQL 2005 I would think that we now are refering to schemas
> and
> in this example it is 3 schemas and they can easily have the same owner..
> Or
> am I wrong ? BOL furthermore states that using schemas make things a lot
> easier. For the most I guess. But you can now have one user owning the
> schema and another user owning a table in that schema, so how does this
> make
> the transfering of an ownership easier ? I've read the following : "Now
> database objects are owned by schemas. Users no longer direcly own
> database
> objects; instead they own schemas". Well that would have simplified things
> but apparently it isn't so! The MOC 2733 states the following about
> schemas
> : "Improved manageability, because dropping a user does not necessitate
> the
> renaming of all objects that the user owns". In the above example I could
> have a schema owned by "dbo" and maby 20 tables in that schema owned by
> "user1". How do I easily drop that user ? And here's some more fun :
> Creating a schema owned by dbo and creating a new table in that schema the
> table inherits the ownership from the schema so therefore the owner of the
> table is dbo, too. Pretty straightforward. If I change the ownership of
> the
> schema to user1 the table inherits the ownership and changing it back to
> dbo
> does the same thing. But changing the ownership explicitly to the table
> changes things. Changing the ownership of the schema does NOT change the
> ownership of the table )
> Anyone have some really good article explaining this ?
> Regards
> Bobby Henningsen
>
>

Ownership in SQL 2005

Hi there,
maybe I've misunderstood something but i just read this phrase in BOL :
"All tables in the partition's schema must have the same owner; for example,
you cannot have a FROM clause that references the tables [tk].[customer],
[john].[store], and [dave].[sales_fact_2004]"
Talking about SQL 2005 I would think that we now are refering to schemas and
in this example it is 3 schemas and they can easily have the same owner.. Or
am I wrong ? BOL furthermore states that using schemas make things a lot
easier. For the most I guess. But you can now have one user owning the
schema and another user owning a table in that schema, so how does this make
the transfering of an ownership easier ? I've read the following : "Now
database objects are owned by schemas. Users no longer direcly own database
objects; instead they own schemas". Well that would have simplified things
but apparently it isn't so! The MOC 2733 states the following about schemas
: "Improved manageability, because dropping a user does not necessitate the
renaming of all objects that the user owns". In the above example I could
have a schema owned by "dbo" and maby 20 tables in that schema owned by
"user1". How do I easily drop that user ? And here's some more fun :
Creating a schema owned by dbo and creating a new table in that schema the
table inherits the ownership from the schema so therefore the owner of the
table is dbo, too. Pretty straightforward. If I change the ownership of the
schema to user1 the table inherits the ownership and changing it back to dbo
does the same thing. But changing the ownership explicitly to the table
changes things. Changing the ownership of the schema does NOT change the
ownership of the table :))
Anyone have some really good article explaining this ?
Regards :)
Bobby Henningsen> "All tables in the partition's schema must have the same owner; for
> example,
> you cannot have a FROM clause that references the tables [tk].[customer],
> [john].[store], and [dave].[sales_fact_2004]"
> Talking about SQL 2005 I would think that we now are refering to schemas
> and
> in this example it is 3 schemas and they can easily have the same owner..
> Or
> am I wrong ?
The context of this BOL statement is requirements for indexed views. The
'owner' requirement for indexed views is the schema owner, not the schema
name. It is possible to create an index on a view referencing tables in
different schema as long as schema share the same owner.
> I've read the following : "Now database objects are owned by schemas.
I don't know where this excerpt is from. Database objects are owned by
users as they always have been. The difference in SQL 2005 is that
ownership is via the schema owner so the schema name can be different than
the owner name. Consider:
CREATE USER Bobby WITHOUT LOGIN
GO
CREATE SCHEMA john AUTHORIZATION Bobby
CREATE SCHEMA dave AUTHORIZATION Bobby
GO
CREATE TABLE [john].[store](...)
CREATE TABLE [dave].[sales_fact_2004](...)
GO
In this example, the user Bobby owns both tables because schema 'john' and
'dave' are both owned by user 'Bobby'.
> How do I easily drop that user ?
To drop user Bobby, you would first need to change schema owner to another
user:
ALTER AUTHORIZATION ON SCHEMA::john TO SomeOtherUser;
ALTER AUTHORIZATION ON SCHEMA::dave TO SomeOtherUser;
GO
DROP USER Bobby
GO
It gets confusing because a schema name and owner name can also be the same.
Be mindful that these are actually separate.
--
Hope this helps.
Dan Guzman
SQL Server MVP
"Bobby Henningsen" <bobhen@.mail.dk> wrote in message
news:OkjqgExXGHA.1200@.TK2MSFTNGP03.phx.gbl...
> Hi there,
> maybe I've misunderstood something but i just read this phrase in BOL :
> "All tables in the partition's schema must have the same owner; for
> example,
> you cannot have a FROM clause that references the tables [tk].[customer],
> [john].[store], and [dave].[sales_fact_2004]"
> Talking about SQL 2005 I would think that we now are refering to schemas
> and
> in this example it is 3 schemas and they can easily have the same owner..
> Or
> am I wrong ? BOL furthermore states that using schemas make things a lot
> easier. For the most I guess. But you can now have one user owning the
> schema and another user owning a table in that schema, so how does this
> make
> the transfering of an ownership easier ? I've read the following : "Now
> database objects are owned by schemas. Users no longer direcly own
> database
> objects; instead they own schemas". Well that would have simplified things
> but apparently it isn't so! The MOC 2733 states the following about
> schemas
> : "Improved manageability, because dropping a user does not necessitate
> the
> renaming of all objects that the user owns". In the above example I could
> have a schema owned by "dbo" and maby 20 tables in that schema owned by
> "user1". How do I easily drop that user ? And here's some more fun :
> Creating a schema owned by dbo and creating a new table in that schema the
> table inherits the ownership from the schema so therefore the owner of the
> table is dbo, too. Pretty straightforward. If I change the ownership of
> the
> schema to user1 the table inherits the ownership and changing it back to
> dbo
> does the same thing. But changing the ownership explicitly to the table
> changes things. Changing the ownership of the schema does NOT change the
> ownership of the table :))
> Anyone have some really good article explaining this ?
> Regards :)
> Bobby Henningsen
>
>

Owner of the table

I've got this question:
Is it possible to assign the 'current owner' using a query like the
following one:

set current schema OWNER1 (in DB2 sql, this allow me to reference the tables
without an explicit indication of the owner (es: after this query I can
simply write 'Select * from dummy', instead of 'Select * from
OWNER1.dummy')).

Thank you
Federica"Federica T" <fedina_chicca@.N_O_Spam_libero.it> wrote in message
news:ckga73$t06$1@.atlantis.cu.mi.it...
> I've got this question:
> Is it possible to assign the 'current owner' using a query like the
> following one:
> set current schema OWNER1 (in DB2 sql, this allow me to reference the
> tables
> without an explicit indication of the owner (es: after this query I can
> simply write 'Select * from dummy', instead of 'Select * from
> OWNER1.dummy')).
> Thank you
> Federica

Not really - in MSSQL, it's considered good practice to always fully specify
the object owner. There is a SETUSER command which allows a sysadmin to
impersonate another user, but it's deprecated and it doesn't support Windows
authentication which is the preferred authentication method.

Simon|||"Simon Hayes" <sql@.hayes.ch> ha scritto nel messaggio
news:416bc568$1_3@.news.bluewin.ch...

> Not really - in MSSQL, it's considered good practice to always fully
specify
> the object owner. There is a SETUSER command which allows a sysadmin to
> impersonate another user, but it's deprecated and it doesn't support
Windows
> authentication which is the preferred authentication method.
> Simon

Thank you a lot!
Fede

Wednesday, March 7, 2012

owned schema or role members?

Hi,
I want to create a login (for account ASPNET from the Active Directory) in
sql server express 2005 for a specific database.
When addidng a new user to a specific database, i see:
Owned schemas, where i take db_datareader and db_datawriter
Roles members: also db_datareader and db_datawriter
What's the difference between both and are they both required fpr account
ASPNET?
Tbanks
BartBart
--db_datareader
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/7d71fca8-ad8d-49c5-b4cc-c1cd
ab0fab43.htm
--db_datawriter
ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/08a5c847-f993-4402-b3ac-a511
3f41e8c8.htm
"Bart" <b@.sdq.dc> wrote in message
news:OMfgIZlbHHA.3420@.TK2MSFTNGP05.phx.gbl...
> Hi,
> I want to create a login (for account ASPNET from the Active Directory) in
> sql server express 2005 for a specific database.
> When addidng a new user to a specific database, i see:
> Owned schemas, where i take db_datareader and db_datawriter
> Roles members: also db_datareader and db_datawriter
> What's the difference between both and are they both required fpr account
> ASPNET?
> Tbanks
> Bart
>
>
>|||Thanks, but my question was more about the difference between Owned schema
and Role members.
Is it enough to take db_anything in Role members or must the user also owns
a schema with db_anything?
"Uri Dimant" <urid@.iscar.co.il> schreef in bericht
news:eDumYbsbHHA.2088@.TK2MSFTNGP04.phx.gbl...
> Bart
> --db_datareader
> ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/7d71fca8-ad8d-49c5-b4cc-c1
cdab0fab43.htm
>
> --db_datawriter
> ms-help://MS.SQLCC.v9/MS.SQLSVR.v9.en/udb9/html/08a5c847-f993-4402-b3ac-a5
113f41e8c8.htm
>
> "Bart" <b@.sdq.dc> wrote in message
> news:OMfgIZlbHHA.3420@.TK2MSFTNGP05.phx.gbl...
>|||Bart
SCHEMA and Roles are different things. When you create a user ut should be
mapped to schema you have specified ir DEFAULT schema--DBO.
Can you elaborate on what you are trying to achive?
"Bart" <b@.sdq.dc> wrote in message
news:uEq8NwvbHHA.4140@.TK2MSFTNGP06.phx.gbl...
> Thanks, but my question was more about the difference between Owned schema
> and Role members.
> Is it enough to take db_anything in Role members or must the user also
> owns a schema with db_anything?
> "Uri Dimant" <urid@.iscar.co.il> schreef in bericht
> news:eDumYbsbHHA.2088@.TK2MSFTNGP04.phx.gbl...
>|||Well, i want to create a new login for account ASPNET (which runs under
ASP.NET) and then define an user (aspnet) for 'mydatabase'. That user must
get read/write prights to the db. At that level, i see in the window
configuration two things about read /write: Owned Schema and Role members.
So my question is: should i take db_readreader / db_writer in the Ownd
Schema or in Role members or in both?
Thanks
"Uri Dimant" <urid@.iscar.co.il> schreef in bericht
news:%23p8We%232bHHA.4632@.TK2MSFTNGP03.phx.gbl...
> Bart
> SCHEMA and Roles are different things. When you create a user ut should be
> mapped to schema you have specified ir DEFAULT schema--DBO.
> Can you elaborate on what you are trying to achive?
>
> "Bart" <b@.sdq.dc> wrote in message
> news:uEq8NwvbHHA.4140@.TK2MSFTNGP06.phx.gbl...
>|||Bart
Does the user should run queries which manipulate with tables belong to
anohter SCHEMA?
I'd go with ROLES and grant SELECT/EXECUTE permission on SCHEMAs that the
user needs to query
"Bart" <b@.sdq.dc> wrote in message
news:u1ddKM3bHHA.4772@.TK2MSFTNGP05.phx.gbl...
> Well, i want to create a new login for account ASPNET (which runs under
> ASP.NET) and then define an user (aspnet) for 'mydatabase'. That user
> must get read/write prights to the db. At that level, i see in the window
> configuration two things about read /write: Owned Schema and Role members.
> So my question is: should i take db_readreader / db_writer in the Ownd
> Schema or in Role members or in both?
> Thanks
> "Uri Dimant" <urid@.iscar.co.il> schreef in bericht
> news:%23p8We%232bHHA.4632@.TK2MSFTNGP03.phx.gbl...
>|||"Uri Dimant" <urid@.iscar.co.il> schreef in bericht
news:OOCCsw3bHHA.4000@.TK2MSFTNGP02.phx.gbl...
> Bart
> Does the user should run queries which manipulate with tables belong to
> anohter SCHEMA?
> I'd go with ROLES and grant SELECT/EXECUTE permission on SCHEMAs that the
> user needs to query
Thanks, but I still don't understand the difference between giving the Role
db_datareader / db_datawriter to user 'aspnet' and adding user 'aspnet' to
Schema dbdatareader and Schema db_datawriter ...|||Bart (b@.sdq.dc) writes:
> Thanks, but I still don't understand the difference between giving the
> Role db_datareader / db_datawriter to user 'aspnet' and adding user
> 'aspnet' to Schema dbdatareader and Schema db_datawriter ...
You should not need the schemss. They exist of legacy reasons. In SQL 2000
there was no difference between a role/user on the one hand and a schema
on the other. If you created a user/role X, you also got a schema X included
in the price.
In SQL 2005 schemas and database principals (users and roles) are separated.
But Microsoft still by default creates schemas for all pre-defined roles
and users, since old applications may rely on these and create objects
in these schemas.
Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pr...oads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodin...ions/books.mspx|||ok, thanks
"Erland Sommarskog" <esquel@.sommarskog.se> schreef in bericht
news:Xns99004B34D29Yazorman@.127.0.0.1...
> Bart (b@.sdq.dc) writes:
> You should not need the schemss. They exist of legacy reasons. In SQL 2000
> there was no difference between a role/user on the one hand and a schema
> on the other. If you created a user/role X, you also got a schema X
> included
> in the price.
> In SQL 2005 schemas and database principals (users and roles) are
> separated.
> But Microsoft still by default creates schemas for all pre-defined roles
> and users, since old applications may rely on these and create objects
> in these schemas.
>
> --
> Erland Sommarskog, SQL Server MVP, esquel@.sommarskog.se
> Books Online for SQL Server 2005 at
> http://www.microsoft.com/technet/pr...oads/books.mspx
> Books Online for SQL Server 2000 at
> http://www.microsoft.com/sql/prodin...ions/books.mspx