die Seilerwerks

Chronicling Life, Love, Linux and Oracle database administration.

ALTER TABLE doesn’t like synonyms

with 2 comments

Something new I found out today. When performing an ALTER TABLE statement (in this case to add a column) in another schema for which you have a synonym (public or private), you must refer to it with the schema qualifier, e.g. HR.EMPLOYEES rather than just EMPLOYEES. It seems the DDL statement doesn’t bother itself with synonyms. Probably a good thing, as DDL is nothing to be taken lightly and it’s best to fully spell out what it is you are mucking about with.

In the example, my user has been granted the ALTER ANY TABLE privilege, as well as SELECT on HR.EMPLOYEES. I’ve made a private synonym in my own schema, also named EMPLOYEES. Let’s see what happens:


SQL> alter table employees add foo number;
alter table employees add foo number
*
ERROR at line 1:
ORA-00942: table or view does not exist

SQL> alter table hr.employees add foo number;

Table altered.

Written by Don Seiler

April 14, 2008 at 3:21 pm

Posted in oracle

Tagged with , ,

2 Responses

Subscribe to comments with RSS.

  1. Don, your blog looks nicer now.

    I’m glad they chose not to allow synonyms here, it would be a mess if they did. As you said, we must know what we are doing or which object we are touching with DDL.

    Yas

    April 15, 2008 at 1:37 am

  2. Hi Don,

    Good remarks. I was also expecting this synonym behavior. When I learned it, I remembered it with my own explanation.

    As there is no ALTER SYNONYM command, so when we are altering table to add a column, it was expecting TABLE object followed by ALTER – not a SYNONYM object.

    Thanks for refreshing the memory. I have been reading your nice posts from time to time for few months :)

    Shawon

    April 16, 2008 at 11:05 am


Leave a Reply