Updated March 13, 2023
Introduction to DB2 database
DB2 is a group of related information items, including a social database server created by IBM. Basically, a DB2 database is a collection of distinct information in a small kind of unit. We can use the database in different forms such as text, integers, media, bytes, etc. It stores all information on electronic media that we call memory. We can easily access and manage the database as per the requirement. DB2 database contains the tables, rows, index, and columns to store the data in a suitable way. DB2 provides the functionality to perform the different operations such as we can create databases, we can drop databases, etc. The main thing about the database is that it is capable of handling a large amount of data, sorting data, retrieving data, and managing the data.
How does the database work in DB2?
Now let’s see how databases work in DB2 as follows.
To see more about the working of DB2 databases, we need to painstakingly consider what are the various components that are useful for the working of DB2 databases. Allow us to begin with the first, and that is table spaces. The table space is a capacity structure that contains tables, records, objects, and so on; the information in the data set is organized into a legitimate gathering. These aids in the speedy recoverability of the information base and guarantees ideal space usage.
The following component is a pattern, which is a named object in the data set and is arranged coherently. This component frames the intelligent design of the information stockpiling. Another component record, which is a bunch of pointers alluding to the lines of the table. These records can be novel or non-special or might be grouped or non-bunched.
So now we have perceived what the components are; the DB2 database works by recovering information through SQL inquiries from the table spaces. The outlines and lists are the components that empower the simple recovery of information from the data set.
Database directory
Data set registry is a coordinated storehouse of information bases. When you make an information base, every one of the insights regarding the data set is put away in a data set catalog, like subtleties of default stockpiling gadgets, design documents, and impermanent tables list on.
Partition global directory is made in the case folder. This directory contains all worldwide data identified with the information base. This segment worldwide directory is named as NODEaaaa/SQLbbb, where aaaa is the information segment number and bbb is the data set token. In the parcel worldwide index, a part explicit catalog is made. This index contains neighborhood data set data. The part explicit registry is named as MEMBERaaaa, where aaaa is a part number. DB2 Enterprise Server Edition climate runs on a solitary part and has just a single part explicit registry. This explicit index is remarkably named as MEMBER0000.
Partitioned global directory
Directory Location: <instance_name>/NODEaaa/SQLaaa
The above-mentioned global directory contains information about the DB2 database that is listed below.
- Global halt write-to-document event observing records.
- Specified table space data documents.
- Capacity bunch control documents.
- It also contains the temporary file container.
- Global Configuration file.
- It also contains the history of database files.
- Logging-related records.
- Locking records
- Programmed Storage holders
Member specific directory
Directory specified location: /NODEaaaa/SQLaaaa/MEMBER0000
The above-mentioned directory contains the following information as follows.
- Articles related to
- Support pool data documents.
- It provides the local monitoring files.
- Logging-related records.
- Configuration files.
- Halt’s occasion screen record. The details about the deadlock occasions screen records are put away in the information base directory of the inventory node if there should be an occurrence of ESE and divided data set climate.
Create Database
We can make a database in case utilizing creates the “DATABASE” command. All databases are made with the default stockpiling bunch “IBMSTOGROUP”, which is made at the hour of making a case. In DB2, all the data set tables are put away in “table space, ” utilising their separate stockpiling gatherings.
Various operations performed in the DB2 database
Now let’s see the different operations of the DB2 database with examples as follows.
First, create a database by using the following command as follows.
Basically, there are two to create the database as follows.
1. Create a non-restrictive database
Syntax
create database specified database name
Examples
create database abc
Explanation
By using the above statement, we can create a new database name as abc. The end out we illustrate by using the following screenshot as follows.
2. Create a restrictive database:
create database specified database name restrictive
Example
create database xyz restrictive
Explanation
By using the above statement, we can create a new database name as xyz with a restrictive type. The end out we illustrate by using the following screenshot as follows.
Now perform different operations on the database as follows.
First, connect to any one of the databases that we have already created databases. After that, create a new table and perform an update operation as follows.
create table company (Comp_Id int not null, comp_name varchar(30) not null,
comp_address varchar(30) not null, primary key(Comp_Id));
Explanation
In the above example, we use a create table statement to create a new table name as a company with different attributes such as Comp_id, comp_name and comp_address with different data types and different sizes as shown in the above statement. Note here comp_name, and comp_address have varchar data type with size 30 as shown.
For confirmation, insert some records by using the following insert into the statement as follows.
insert into company (Comp_Id, comp_name, comp_address) values(1, "HP", "Mumbai"), (2, "Dell", "Pune"), (3, "LG", "Delhi"), (4, "Bajaj", "Kolkatta"), (5, "Usha", "Kochi");
select * from company;
Explanation
In the above example, we use to insert into a statement to insert new records into the company table. Here we insert string values in the comp_name and comp_address column with minimum length. The end out we illustrate by using the following screenshot as follows.
Now perform the update operation as follows.
Now suppose we need to update the address of LG Company at that time; we can use the following statement as follows.
update company set comp_address = ‘Mumbai’ where Comp_Id = 3 ;
Explanation
In the above statement, we use the update statement; here, we try to update the comp_address from the company table. The end out we illustrate by using the following screenshot as follows.
So in this way, we can perform, create databases, insert and update the different operations, and perform delete, SelectOne, SelectMultiple, and SelectAll, etc.
Conclusion
We hope from this article you learn the DB2 database. From the above article, we have learned the basic syntax of the DB2 database and how it works, and we also see different examples of DB2 databases. From this article, we learned how and when we use the DB2 database.
Recommended Articles
This is a guide to the DB2 database. Here we discuss the working of a database in DB2 along with Various operations performed in the DB2 database. You may also have a look at the following articles to learn more –