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.

Tuesday, October 6, 2009

Codd's Rules for RDBMS

Codd's Rules for RDBMS

In 1985, Edgar Codd published a set of 13 rules which he defined as an evaluation scheme for a product which claimed to be a Relational DBMS.

Although these rules were later extended - and they now number in the 100s - they still serve as a foundation for a definition of a Relational DBMS.
(0) The foundation rule:

This is Codd's Rule Zero which is the foundation for the other rules.

The rules states that, any system which claims to be a relation database management system must be able to manage databases entirely through its relational capabilities and means that the RDBMS must support:

A data definition language

A data manipulation language

A data integrity language

A data control language

all of which must work on several records at a time, that is, on a relation.

(1) Information Rule:
All information in a relational database including table names column names are
represented explicitly by values in tables. Knowledge of only one language is necessary to
access all data such as description of the table and attribute definitions integrity
constraints action to be taken when constraints are violated and security information.

(2)Guaranteed Access Rule:
Every piece of data in the relational database can be accessed by using a
combination of a table name a primary key value that identifies the row and a column
that identifies the cell. The benefit of this is that user productivity is improved
since there is no need to resort to using physical pointers addresses. Provides
data independence.

(3)Systematic treatment of Nulls Rule:
The RDBMS handles, that have unknown or inapplicable values in a predefined fashion.
RDBMS distinguishes between zeros blanks and nulls in records and handles such values in
a consistent manner that produces correct answers comparisons and calculations.

(4)Active On-Line Catalog Based on the Relational Model:
The description of a database and its contents are database tables and therefore
can be queried online via the data language. The DBA's productivity is improved since
changes and additions to the catalog can be done with the same commands that are
used to access any other table. All queries and reports can be done as with other tables.

(5)Comprehensive Data Sub-language Rule:
A RDBMS may support several languages but at least one of them allows the user to do all
of the following: define tables view query and update data set integrity constraints
set authorization and define transactions.

(6)View Updating Rule:
Any view that is theoretically updatable if changes can be made to the tables that
effect the desired changes in the view. Data consistency is ensured since changes
in the underlying tables are transmitted to the view they support. Logical data
independence reduces maintenance cost.

(7)High Level Inserts Update and Delete:
The RDBMS supports insertion updation and deletion at a table level. With this the
RDBMS can improve performance by optimizing the path to be taken to execute the action
ease of use improved since commands act on set of records.

(8)Physical data Independence :
The execution of adhoc requests and application programs is not affected by changes
in the physical data access and storage methods. Database administrators can make
the changes to physical acccess and storage methods which improve performance
but do not changes in the application programs or adhoc requests. This reduces
maintenance costs.

(9)Logical data Independence:
Logical changes in tables and view such as adding/deleting columns or changing
field lengths do not necessitate modifications in application programs or in the
format of adhoc requests.

(10)Integrity Independence:
Like table/view definitions integrity constraints are stored in the
on-line catalog and therefore can be changed without necessitating changes
in application programs or in the format of adhoc requests .
The following two integrity constraints must be supported.
(a)Entity Integrity:
No component of primary key is allowed to have a null value.
(b)Referential integrity:
For each distinct non-null foreign key value in a relational database
there must exist a matching primary key from the same range of data value.

(11)Distribution Independence:
Application programs and adhoc requests are not affected by changes
in the distribution of the physical data.

(12)Non sub-version Rule:
If the RDBMS has a language change that accesses the information
of a record at a time this language cannot be used to by-pass the
integrity constraints. In order to adhere to this rule the RDBMS must have an
active catalog that contains the constraints and must have a logical data independence.