The Mimer SQL Relational Database
Mimer SQL is a relational database system, which means that the information in the database is presented to the user in the form of tables. The tables represent a logical description of the contents of the database which is independent of, and insulates the user from, the physical storage format of the data.
The Mimer SQL database includes the data dictionary which is a set of tables describing the organization of the database and is used primarily by the database management system itself.
The database, although located on a single physical platform, may be accessed from many distinct platforms, even at remote geographical locations, linked over a network through client/server support.
Commands are available for managing the connections to different databases, see the Mimer SQL User's Manual, so the actual database being accessed may change during the course of an SQL session.
At any one time, however, the database may be regarded as one single organized collection of information.
The Data Dictionary
The data dictionary contains information on all the database objects stored in a Mimer SQL database and how they relate to one another.
The data dictionary stores information about:
- Databanks, see Databanks
- Idents, see Idents
- Schemas, see Schemas
- Tables and Views, see Base Tables and Views
- Indexes, see Primary Keys and Indexes
- Functions and procedures, see Routines - Functions and Procedures
- Modules, see Modules
- Sequences, see Sequences
- Synonyms, see Synonyms
- Triggers, see Triggers
- Shadows, see Shadows
- Domains, see Domains
- Access rights and privileges, see Access Rights and Privileges.
Mimer SQL Database Objects
Mimer SQL database objects can be divided into the following groups:
- System Objects
- Private Objects
Private objects are fully identified by their qualified name, which is the name of the schema to which they belong and the name of the object in the following form: schema.object, see Qualified Object Names.
Conflicts arising from the use of the same object name in two different schemas are avoided when the qualified name is used. If a private object name is specified without explicit reference to its schema, it is assumed to belong to a schema with the same name as the current ident.
A databank is the physical file where a collection of tables is stored. A Mimer SQL database may include any number of databanks.
There are two types of databank, system and user.
System databanks contain system information used by the database manager. These databanks are defined when the system is created.
The system databanks are:
- SYSDB containing the data dictionary tables
- TRANSDB used for transaction handling
- LOGDB used for transaction logging
- SQLDB used in transaction handling and for temporary storage of internal work tables.
User databanks contain the user tables. These databanks are defined by the user(s) responsible for setting up the database. See Specifying the Location of User Databanks for details concerning path names for user databank files.
The division of tables between different user databanks is a physical file storage issue and does not affect the way the database contents are presented to the user. Except in special situations (such as when creating tables), databanks are completely invisible to the user.
Note: Backup and Restore in Mimer SQL can be performed on a per-databank basis rather than on the entire database file base. See the Mimer SQL System Management Handbook for more information.
Specifying the Location of User Databanks
The location for a user databank file can be specified completely (as an absolute path name) or with some of the path name components omitted (a relative path name).
The default values used for omitted path name components are taken from the path name for the system databank file SYSDB, which is located in the database home directory.
Note: The databank location stored in the Mimer SQL data dictionary is the path name as explicitly specified, i.e. without the addition of default values for any omitted path name components. Such additions are determined and added each time the file is accessed.
Refer to the Mimer SQL System Management Handbook for recommendations concerning databank file management and for information on how the path name for a databank file is determined.
An ident is an authorization-id used to identify users, programs and groups. There are four types of idents in a Mimer SQL database: user, os_user, program and group idents.
User idents identify individual users who can connect to a Mimer SQL database.
A user ident's access to the database is protected by a password and is restricted by the specific privileges granted to the ident. User idents are generally associated with specific physical individuals who are authorized to use the system.
OS_USER idents are idents which reflect a user id defined by the operating system.
An OS_USER ident allows the user currently logged in to the operating system to access the Mimer SQL database without providing a username or password.
For example: if the current operating system user is ALBERT and there is an OS_USER ident called ALBERT defined in Mimer SQL, ALBERT may start BSQL (for example) and connect directly to Mimer SQL simply by pressing <return> at the Username: prompt.
If an OS_USER ident is defined with a password in Mimer SQL, the ident may also connect to Mimer SQL in the same way as a user ident (i.e. by providing the username and password). An OS_USER ident may not have the same name as a user ident in the database.
Program idents do not strictly connect to Mimer SQL, but they may be entered from within an application program by using the ENTER statement.
The ENTER statement may only be used by an ident who is already connected to a Mimer SQL database.
An ident is granted the privilege to enter a program ident. A program ident is set up to have certain privileges and these apply after the ENTER statement has been used. Program idents are generally associated with specific functions within the system, rather than with physical individuals.
The LEAVE statement is used to return to the state of privileges and database access that existed before ENTER was used.
Group idents are collective identities used to define groups of user and/or program idents.
Any privileges granted to or revoked from a group ident automatically apply to all members of the group. Any ident can be a member of as many groups as required, and a group can include any number of members.
Group idents provide a facility for organizing the privilege structure in the database system. All idents are automatically members of a logical group which is specified in Mimer SQL statements by using the keyword PUBLIC.
A schema defines a local environment within which private database objects can be created. The ident creating the schema has the right to create objects in it and to drop objects from it.
When a USER, OS_USER or PROGRAM ident is created, a schema with the same name can also be created automatically and the created ident becomes the creator of the schema. This happens by default unless WITHOUT SCHEMA is specified in the CREATE IDENT statement.
When a private database object is created, the name for it can be specified in a fully qualified form which identifies the schema in which it is to be created. The names of objects must be unique within the schema to which they belong, according to the rules for the particular object-type.
If an unqualified name is specified for a private database object, a schema name equivalent to the name of the current ident is assumed.
Data in a relational database is logically organized in tables, which consist of horizontal rows and vertical columns. Columns are identified by a column-name. Each row in a table contains data pertaining to a specific entry in the database. Each field, defined by the intersection of a row and a column, contains a single item of data.
Each row in a table must have the same set of data items (one for each column in the table), but not all the items need to be filled in. A column can have a default value defined (either as part of the column specification itself or by using a domain with a default value) and this is stored in a field where an explicit value for the data item has not been specified.
If no default value been defined for a column, the NULL value is stored when no data value is supplied (the way the NULL value is displayed depends on the application, in BSQL the minus sign is used).
A relational database is built up of several inter-dependent tables which can be joined together. Tables are joined by using related values that appear in one or more columns in each of the tables.
Part of the flexibility of a relational database structure is the ability to add more tables to an existing database. A new table can relate to an existing database structure by having columns with data that relates to the data in columns of the existing tables. No alterations to the existing data structure are required.
All the fields in any one column contain the same type of information and are of the same physical length. This length and type of information is defined by a data type, see Data Types in SQL Statements for a detailed description of data types.
Base Tables and Views
The logical representation of data in a Mimer SQL database is stored in tables. This is what the user sees, as distinct from the physical storage format which is transparent to the user.
The tables which store the data are referred to as base tables. Users can directly examine data in the base tables.
In addition, data may be presented in views, which are created from specific parts of one or more base tables. To the user, views may look the same as tables, but operations on views are actually performed on the underlying base tables.
Access privileges on views and their underlying base tables are completely independent of each other, so views provide a mechanism for setting up specific access to tables.
The essential difference between a table and a view is underlined by the action of the DROP command, which removes objects from the database. If a table is dropped, all data in the table is lost from the database and can only be recovered by redefining the table and re-entering the data. If a view is dropped, however, the table or tables on which the view is defined remain in the database, and no data is lost. Data may, however, become inaccessible to a user who was allowed to access the view but who is not permitted to access the underlying base table(s).
Note: Since views are logical representations of tables, all operations requested on a view are actually performed on the underlying base table, so care must be taken when granting access privileges on views.
Such privileges may include the right to insert, update and delete information. As an example, deleting a row from a view will remove the entire row from the underlying base table and this may include table columns the user of the view had no privilege to access.
Views may be created to simplify presentation of data to the user by including only some of the base table columns in the view or only by including selected rows from the base table. Views of this kind are called restriction views.
Views may also be created to combine information from several tables (join views). Join views can be used to present data in more natural or useful combinations than the base tables themselves provide (the optimal design of the base tables will have been governed by rules of relational database modeling). Join views may also contain restriction conditions.
Primary Keys and Indexes
Rows in a base table are uniquely identified by the value of the primary key defined for the table. The primary key for a table is composed of the values of one or more columns. A table cannot contain two rows with the same primary key value. (If the primary key contains more than one column, the key value is the combined value of all the columns in the key. Individual columns in the key may contain duplicate values as long as the whole key value is unique).
Other columns may also be defined as UNIQUE. A unique column is also a key, because it may not contain duplicate values, and need not necessarily be part of the primary key.
The columns of the primary key may not contain NULL (this is one of the requirements of a strictly relational database).
Values in primary key columns can be updated if the table involved is stored in a databank with the TRANS or LOG option.
Primary key and unique columns are automatically indexed to facilitate effective information retrieval.
Other columns or combinations of columns may be defined as a secondary index to improve performance in data retrieval. Secondary indexes are defined on a table after it has been created (using the CREATE INDEX statement).
A secondary index may be useful when, for example, a search is regularly performed on a non-keyed column in a table with many rows, then defining an index on the column may speed up the search. The search result is not affected by the index but the speed of the search is optimized.
It should be noted, however, that indexes create an overhead for update, delete and insert operations because the index must also be updated. Indexes are internal structures which cannot be explicitly accessed by the user once created.
There is no guarantee that the presence of an index will actually improve performance because the decision to use it or not is made by the internal query optimization process.
SQL queries are automatically optimized when they are internally prepared for execution. The optimization process determines the most effective way to execute the query and in some cases optimal query execution may not actually involve using an index.
Routines - Functions and Procedures
In Mimer SQL it is possible to define SQL routines that are stored in the data dictionary and which may be invoked when needed. The term 'routine' is a collective term for functions and procedures. The acronym PSM, Persistent Stored Modules, is also used to denote stored routines.
For a complete and detailed discussion of functions, procedures and the Stored Procedures functionality supported in Mimer SQL, see the Mimer SQL Programmer's Manual.
Functions are distinguished from procedures in that they return a single value and the parameters of a function are used for input only. A function is invoked by using it where a value expression would normally be used.
Mimer SQL supports standard procedures and also result set procedures, which are procedures capable of returning the row value(s) of a result-set.
Standard procedures are invoked directly by using the CALL statement and can pass values back to the calling environment through the procedure parameters.
In embedded SQL, result set procedures are invoked by declaring a cursor which includes the procedure call specification and by then using the FETCH statement to execute the procedure and return the row(s) of the result-set.
In interactive SQL, a result set procedure is invoked by using the CALL statement directly and the result-set values are presented in the same way as for a select returning more than one row.
The ident invoking a routine must have EXECUTE rights on it.
The creator of a routine must hold the appropriate access rights on any database objects referenced from within the routine. These access rights must be held for the life of the routine.
Routine names, like those of other private objects in the database, are qualified with the name of the schema to which they belong.
The PSM constructs available in Mimer SQL allow powerful functionality to be defined and used through the creation and execution of routines. The use of routines also makes it possible to move application logic from the client to the server, thereby reducing network traffic.
A module is simply a collection of routines. All the routines in a module are created when the module is created and belong to the same schema.
EXECUTE rights on the routines contained in a module are held on a per-routine basis, not on the module.
If a module is dropped, all the routines contained in the module are dropped.
Under certain circumstances a routine may be dropped because of the cascade effect of dropping some other database object, see the Mimer SQL User's Manual for details. If such a routine is contained in a module, it is implicitly removed from the module and dropped. The other routines contained in the module remain unaffected.
In general, care should be taken when using DROP or REVOKE in connection with routines, modules or objects referenced from within routines because the cascade effects can often affect many other objects, see the Mimer SQL User's Manual.
A synonym is an alternative name for a table, view or another synonym. Synonyms can be created or dropped at any time.
A synonym cannot be created for a function, procedure or a module.
Using synonyms can be a convenient way to address tables that are contained in another schema.
For example, if a view called ROOM_VIEW is contained in the schema called SAMMY, the full name of the view is SAMMY.ROOM_VIEW. This view may be referenced from the schema called JIMMY by its fully qualified name as given above.
Alternatively, a synonym may be created for the view in schema JIMMY, e.g. RM_VIEW. Then the name RM_VIEW can simply be used to refer to the view SAMMY.ROOM_VIEW.
Note: The name RM_VIEW is contained in schema JIMMY and can only be used in that context.
Mimer SQL Shadowing is a product that can create and maintain one or more copies of a databank on different disks. This provides extra protection from the consequences of disk crashes, etc. Shadowing requires a separate license.
A trigger defines a number of procedural SQL statements that are executed whenever a specified data manipulation statement is executed on the table or view on which the trigger has been created.
The trigger can be set up to execute AFTER, BEFORE or INSTEAD OF the data manipulation statement. Trigger execution can also be made conditional on a search condition specified as part of the trigger.
Triggers are described in detail in the Mimer SQL Programmer's Manual.
A sequence is a private database object that can provide a series of integer values. A sequence can be defined as unique or non-unique.
A unique sequence generate unique values. If all values between the initial value and the maximum value has been used, the sequence becomes exhausted and can not be used any more.
A non-unique sequence will generate its series of values repeatedly.
A sequence has an initial value, an increment step value and a maximum value defined when it is created (by using the CREATE SEQUENCE statement).
A sequence is created with an undefined value initially.
It is possible to generate the next value in the integer series of a sequence by using the NEXT_VALUE function, see The NEXT_VALUE Function. When this function is used for the first time after the sequence has been created, it establishes the initial value for the sequence. Subsequent uses will establish the next value in the series of integer values of the sequence as the current value of the sequence.
It is possible to get the current value of a sequence that has been initialized by using the CURRENT_VALUE function, see The CURRENT_VALUE Function. This function cannot be used until the initial value has been established for the sequence (by using NEXT_VALUE for the first time).
An ident must hold USAGE privilege on the sequence in order to use it.
If a sequence is dropped, with the CASCADE option in effect, all objects referencing the sequence will also be dropped.
Upright Database Technology AB
Voice: +46 18 780 92 00
Fax: +46 18 780 92 40