cancel
Showing results for 
Search instead for 
Did you mean: 

How to change the owner of a database object?

VolkerBarth
Contributor
8,644

A question that came up in the NNTP groups lately...

Well, I'm quite sure that SQL Anywhere (up to v12.0.1) does not allow to alter the owner of a database object at all, i.e. to do something like

ALTER TABLE User1.Table1 RENAME User2.Table1;

or

ALTER SCHEMA User2 TRANSFER User1.Table1;

Furthermore, I remember to have read several NNTP discussions on that in the past, but I can't find an official statement there nor in this nice forum nor in the docs.

Where does it tell that the only way to "change ownership" is by dropping and recreating the object for the new owner?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member

I cannot recall seeing this explicitly documented, Volker. But you are correct that, currently, SQL Anywhere does not permit an ALTER statement to change the owner of a table.

VolkerBarth
Contributor

@Glenn, I'm very happy that this forum is not "Glenn-free"...:)

VolkerBarth
Contributor
0 Kudos

...and does not permit any other statement to the change the owner of a table, either - right?

Former Member
0 Kudos

Correct. Currently, with 12.x software there is no way to change a table owner.

Answers (2)

Answers (2)

Breck_Carter
Participant

This should be a Product Suggestion. This has been a common request over the years, often from folks coming from Transact SQL who mistakenly thought "dbo" as an owner was a good idea (it's not, for a plethora of reasons, not the least of which is that it's a user id in SQL Anywhere but some other incomprehensible thing in Transact SQL).

FWIW the unfortunately-named PostgreSQL has ALTER TABLE name SET SCHEMA new_schema which is kind of cheesy as syntax goes ("it's an owner, not a "schema", sheesh!) but it apparently does the trick; e.g., it cascades to other objects.

I'll bet money that "cascading" is the reason it hasn't been implemented yet... but having it would be yet another feather in SQL Anywhere's cap, something to make the administrator's life easier that most other products don't have.

Former Member
0 Kudos

To provide a bit of background material on this subject, PostgreSQL uses ALTER TABLE name OWNER TO new_owner. Changing the owner doesn't have the cascading effect you mention. Schemas and owners are different things.

Microsoft also supports this with its ALTER AUTHORIZATION statement.

ASE recently introduced ALTER TABLE name MODIFY OWNER as well.

I don't know of any other database products that support this feature.

VolkerBarth
Contributor
0 Kudos

@Breck: Feel free to post this as a product suggestion (as you will have done several times in the past, I'd bet).

Personally, I was just searching for an "official document" (and thankfully Glenn can still speak "officially") - I have never had the need to alter the owner myself...

Breck_Carter
Participant
0 Kudos

Both PostgreSQL and SQL Anywhere use "owner" and "schema" to mean different things. Arguably, the PostgreSQL "schema" is analogous to SQL Anywhere's "owner" since both are useful: you can code SELECT FROM schema.table in PostgreSQL and SELECT FROM owner.table in SQL Anywhere. Folks seem to ask "how do I change schema in PostgreSQL" as often as they ask about changing the owner in SQL Anywhere.

Similarly, the PostgreSQL "owner" seems to be analogous to SQL Anywhere's "schema" since both seem utterly useless... well, I'm not sure about PostgreSQL's owner being useless, but CREATE SCHEMA in SQL Anywhere certainly is... not one in one thousand SQL Anywhere developers even knows it exists, far fewer than the number who know about CREATE DATATYPE, possibly the second-most-useless feature...

...but, that's just thread drift 🙂

Former Member
0 Kudos

@Breck, I don't want to drift this thread too much, and I'm sure you are much more familiar with PostgreSQL than I am. However, it would seem to me that in PostgreSQL, ownership is strictly focused on security-related grouping, whereas schemas are strictly focused on namespace separation. Of course, privileges can be granted to schemas, so I suspect you can fulfill your security requirements with schemas as well.

In contrast, SQL Anywhere uses ownership for both security and namespace separation. The CREATE SCHEMA statement does neither and simply provides a way to create multiple objects and specify their privileges in a single atomic statement.

Breck_Carter
Participant
0 Kudos

@Phil: I think you are correct on all points, except one: "I'm sure you are much more familiar with PostgreSQL than I am"... if you have actually used PostgreSQL at all, ever, in your lifetime, then you're way ahead of me 🙂

Any problems developers have understanding security and namespaces in SQL Anyhwere are NOTHING compared to the problems they have in products like Oracle (which, unlike PostgreSQL, is familiar to me).

Former Member

Of course the 'work-around' (I've done this on numerous occassions...) is:

select * into NewOwner.TableName from OldOwner.TableName

or ... if you have lots of indexes & triggers .... or for views, functions, and procedures ....

Unload the database into a script using dbunload, find the 'CREATE <object>' statement ...

and paste and run the modified version with the new owner .. then drop the old object!