Wednesday, October 28, 2009

What is a Namespace


Namespace: A namespace defines a group of object types, within which all names must be uniquely identified—by schema and name. Objects in different namespaces can share the same name
Object types all sharing the same namespace:
Tables, Views, Sequences, Private synonyms, Stand-alone procedures, Stand-alone stored functions, Packages, Materialized views, User-defined types, etc.

Thus it is impossible to create a view with the same name as a table; at least, it
is impossible if they are in the same schema.

Object types having their own namespace:
Indexes, Constraints, Clusters, Database triggers, Private database links, Dimensions
Thus it is possible for an index to have the same name as a table, even within the
same schema.

Non schema objects with their own namespace:
User roles, Public synonyms, Public database links, Tablespaces, Profiles, etc.

Let's see an Example:

SQL> create table test (eno number);
Table created.

SQL> create index test on test(eno);
Index created.

SQL> desc test;
Name Null? Type
----------------------------------------- -------- ----------------------------
ENO NUMBER

SQL> create view test as select * from test;
create view test as select * from test
*
ERROR at line 1:
ORA-00955: name is already used by an existing object

Here, we see that I can create an index with the same name as of table but I can't create a view with the same name as of a table as they share the same namespace.

3 comments: