-1

I have Views in Schema A and I want to create a Synonym for these views in Schema B.

Could you please help me write a query for Granting the role and creating a synonym?

SitGeek
  • 35
  • 1
  • 3
  • 8

1 Answers1

2

From user A, you only need to grant SELECT privilege to user A's views to user B

GRANT SELECT ON A.viewname1 TO B;
GRANT SELECT ON A.viewname2 TO B;
...

From B, creating synonyms allows reference to user A's views without the schema prefix ("A.").

CREATE SYNONYM viewname1 FOR A.viewname1;
CREATE SYNONYM viewname2 FOR A.viewname2;
...

It should now be possible for user B to select from those views like this:

SELECT * FROM viewname1;

Note that a user can only use CREATE SYNONYM if they have the CREATE SYNONYM privilege.

StampyCode
  • 7,218
  • 3
  • 28
  • 44
Gaz
  • 36
  • 4
  • I don't recommend using public synonyms for this sort of thing. One day schema C will want to have its own version of `viewname1`, and you'll end up with a mess. – Jeffrey Kemp Aug 24 '16 at 00:26
  • 1
    @Jeffrey: You are correct. I have edited the answer to reflect this. – Gaz Aug 24 '16 at 01:42