Question
· Jun 19

Namespace vs database

I'm confused about the differences between a namespace and a database.

I understand that a database is a single IRIS.DATA file in a directory in the os hosting IRIS.

What is the difference between a namespace and a database?

Can I write data into a database without specifying a namespace?
If so how do I write to a particlar DB in objectscript?

Does a database have to be in a namespace?
Can a database be in more than one namespace?

Can a namespace have only one 'routine' database and only one 'data' database?

Discussion (8)5
Log in or sign up to continue
  1. A namespace is a logical abstraction that provides access to one or more databases. It acts as a layer that allows you to organize and manage data and code effectively. In contrast, a database is a physical construct, represented as a single IRIS.DATA file on the operating system, storing the actual data and code [1][2].

  2. It is not possible to write data directly into a database without specifying a namespace. When working with ObjectScript or SQL, operations are performed within the context of a namespace. Data is automatically written to the underlying database(s) mapped to that namespace [2][3].

  3. You can specify which database to write data into by first changing to the correct namespace and ensuring appropriate mappings are in place. In ObjectScript, you can change namespaces using the SET $NAMESPACE command:

    NEW $NAMESPACE
    SET $NAMESPACE="TargetNamespace"
    
  4. A database does not necessarily have to belong to a namespace; it can exist independently. However, a namespace provides the mapping to allow logical access to the database contents. A database can be associated with multiple namespaces, allowing the same data to be accessed from different logical contexts [1].

  5. A namespace typically has one "routine" database (for code) and one "data" database for global storage. However, complex mappings are possible where multiple databases can handle different data types or functional roles for a single namespace [1].

Sources:

Point 2. of the previous reply is definitely WRONG!

Point 4. takes that back in some way but leaves it ambiguous.

Using extended Global References (also in Class Storage Definitions)
allows access to any mounted DB if you have access rights.

A personal example:

USER>for i=1:1:5 set ^|"^^C:\InterSystems\IRIS242\mgr\nonspace"|rcc(i)=i
 
USER>zwrite ^|"^^C:\InterSystems\IRIS242\mgr\nonspace"|rcc
^|"^^C:\InterSystems\IRIS242\mgr\nonspace"|rcc(1)=1
^|"^^C:\InterSystems\IRIS242\mgr\nonspace"|rcc(2)=2
^|"^^C:\InterSystems\IRIS242\mgr\nonspace"|rcc(3)=3
^|"^^C:\InterSystems\IRIS242\mgr\nonspace"|rcc(4)=4
^|"^^C:\InterSystems\IRIS242\mgr\nonspace"|rcc(5)=5
USER>

I learned this traditional technique  47 years ago. 
And it still works fine.

 

Hi @Phillip Wu !

Namespaces give flexibility and were introduced to make a lot of powerful things possible.

If you are confused with all this uncertainty and don't need flexibility for now you can create Namespace DEV that has only one database DEV for everything and you can think that you are working with database DEV only with no any confusion.

But you will sign in into Namespace DEV in your IRIS system as users log in into Namespaces in InterSystems IRIS.
 

Or, e.g., if you take any vanilla IRIS docker image and run it, it will have a USER namespace that provides access to the USER database, which is convenient to use for any dev experiments.

Here's an example of how we use the relationship between namespaces and databases.

My company sells ERP software for the millwork industry. Our customers sell building materials to contractors, distributors, etc. Some of our customers have multiple locations throughout the country. For those customers, we will usually set up a different namespace for each of those locations. Each of those namespaces is set up to have their own database for their data, but the all share the same database for routines because while they all have different data, like customers, orders, invoices, etc., the same set of code is running all of them.