PUBLIC and PRIVATE Synonyms
If you use the PRIVATE keyword to declare a synonym in a database that is not ANSI-compliant, the unqualified synonym can be used by its owner. Other users must qualify the synonym with the name of the owner.
If you use the PUBLIC keyword (or no keyword at all), anyone who has access to the database can use your synonym. If the database is not ANSI-compliant, a user does not need to know the name of the owner of a public synonym.
In an ANSI-compliant database, all synonyms are private. If you use the PUBLIC or PRIVATE keywords, the database server issues a syntax error.
Examples of PRIVATE and PUBLIC synonyms
CREATE SEQUENCE IF NOT EXISTS MySequence
INCREMENT BY 1 START WITH 1
MAXVALUE 8000 MINVALUE 0
NOCYCLE CACHE 20 ORDER;
CREATE PRIVATE SYNONYM IF NOT EXISTS anaphora FOR MySequence;
Now user primus is the owner of two new objects
in the current database:- a sequence object called MySequence,
- and a private synonym called anaphora for the MySequence sequence.
- to create a permanent table called twoSmall,
- and to declare litotes as a private synonym for the twoSmall table:
CREATE TABLE IF NOT EXISTS twoSmall (c1 SMALLINT, c2 SMALLINT);
INSERT INTO twoSmall VALUES (0, 0);
CREATE PRIVATE SYNONYM litotes FOR twoSmall;
INSERT INTO primus.litotes (col1, col2)
VALUES (primus.anaphora.NEXTVAL, primus.anaphora.NEXTVAL);
Although
both synonyms in the INSERT statement were created as PRIVATE,
the user can access the objects that those synonyms reference by qualifying
the synonym names with the authorization identifier of primus,
who is the owner of those synonyms.INSERT INTO litotes (col1, col2)
VALUES (anaphora.NEXTVAL, anaphora.NEXTVAL);
CREATE SYNONYM IF NOT EXISTS synecdoche FOR MySequence;
In
the example above, synecdoche is a public synonym by default,
because neither the PUBLIC nor PRIVATE keyword
was specified.CREATE PUBLIC SYNONYM IF NOT EXISTS zeugma FOR MySequence;
CREATE PRIVATE SYNONYM IF NOT EXISTS pleonasm FOR MySequence;
CREATE SYNONYM asyndeton FOR MySequence;
CREATE PRIVATE SYNONYM litotes FOR MySequence;
For information about the scope of reference of the identifiers of public and private synonyms in databases that are not ANSI-compliant, see the topic Synonyms with the Same Name.