Found 6705 Articles for Database

How to create a view on table TAB1 for column Name, age, enrollmentId & age > 10 years. >

Mandalika
Updated on 12-Sep-2020 13:20:28

306 Views

A view is an alternative way of representing the data stored in a table. A view can be used to increase the performance of the query since the view contains very limited rows as compared to its source table. We can use the below command to create a view on an existing table TAB1.CREATE VIEW AGEVIEW (NAME, AGE, ENROLLMENT_ID)    AS SELECT NAME, AGE, ENROLLMENT_ID FROM TAB1       WHERE AGE > 10;We have to use CREATE VIEW reserved words in order to create a new view. This will be followed by the name of the view (AGEVIEW).The columns ... Read More

Foreign key referencing of two DB2 tables

Mandalika
Updated on 12-Sep-2020 13:18:09

577 Views

A foreign key is a column in a table that establishes a referential link with another table. A foreign key can be defined during creation of table (CREATE TABLE command) or it can be defined by modifying the table (ALTER TABLE command). However, before defining any key as foreign key, make sure that an index is built up on that column. We can use the below command to define an existing column CLASS in table TAB1 as a foriegn key which links to table TAB2.ALTER TABLE TAB1 ADD FOREIGN KEY (CLASS) REFERENCES CLASSDATA (CLASS_ID);The ALTER TABLE reserved words are followed ... Read More

How to add a new column Address in the above DB2 table TAB1?

Mandalika
Updated on 11-Sep-2020 14:41:49

1K+ Views

We can add a new column in an existing table as per the business requirements. Similarly, we can also remove a column from the table. This could be done using the ALTER table command as below.ALTER TABLE TAB1 ADD COLUMN ADDRESS VARCHAR(100);The ALTER TABLE reserved words are followed by the name of the table which we want to amend. In this case it is TAB1.To add a new column we will use ADD COLUMN and to remove the column we will use the REMOVE COLUMN parameter. This is followed by the name of the column. If this is an addition ... Read More

How will you add a constraint on above DB2 table TAB1 for ages between 3 to 16 years?

Mandalika
Updated on 11-Sep-2020 14:29:47

245 Views

Constraints are used to restrict the data inserted at a particular column. Constraints can be used in such a way that a value can only be inserted if it satisfies the condition given in constraints. We can give the below parameter during CREATE TABLE command to add a constraint.CREATE TABLE DBSET1.TAB1    (STUDENT_ID CHAR(10) NOT NULL,    ENROLLMENT_ID CHAR(20) NOT NULL,    NAME VARCHAR(50),    AGE SMALLINT CONSTRAINT NUMBER CHECK    (AGE >=3 AND AGE

How to add a unique index on the above table TAB1 for column Enrollment ID (ascending)?

Mandalika
Updated on 11-Sep-2020 14:21:42

226 Views

An index is a lookup table that optimizes the searching of data. An index defined on any table can increase the query speed. The index can be built up on any column of the table and DB2 will generate a logical structure at backend. This will facilitate the search on the table using indexed columns effectively.An index can be unique and non-unique. To create a new unique index at any table we can use below command.CREATE UNIQUE INDEX ENROTAB1    ON TAB1 (ENROLLMENT_ID) ASC;The CREATE UNIQUE INDEX reserved words are followed by the name of the unique index which we ... Read More

How to create a DB2 table TAB1 with 4 columns, Student ID, Enrollment ID, Name and Age?

Mandalika
Updated on 11-Sep-2020 14:12:28

363 Views

A table is a logical structure of a data in a DB2. A table consists of a column which represents the attribute and rows represents the entity. Below command can be issued in order to create a new DB2 table.CREATE TABLE DBSET1.TAB1    (STUDENT_ID CHAR(10) NOT NULL,    ENROLLMENT_ID CHAR(20) NOT NULL,    NAME VARCHAR(50),    AGE SMALLINT    PRIMARY KEY (STUDENT_ID));The CREATE TABLE reserved words are followed by the name of the table which we have to create in the format . Here DBSET1 is the database and TAB1 is the table.The name of the column has to be ... Read More

How to create a DB2 bufferpool with pagesize 4096?

Mandalika
Updated on 11-Sep-2020 14:04:29

152 Views

Bufferpool is the unit of the main memory which is used to cache the data in the DB2 table. The data is stored in the cache once the database manager reads the data from the disk to the main memory. The bufferpool can be defined by giving the pagesize.The page is the smallest unit of Input/Output that a DB2 database manager can handle. We can create a DB2 bufferpool using the below command−CREATE BUFFERPOOL BP3 PAGESIZE 4096;The CREATE and BUFFERPOOL reserved words are followed by the bufferpool name which we want to create. Finally we will use PAGESIZE parameter to ... Read More

How to add volume VOL34 and remove volume VOL29 from storage group STG1?

Mandalika
Updated on 11-Sep-2020 14:07:28

101 Views

A Volume is a group of physical disks which are used to store the data. A storage group is a collection of volumes. We can add or remove the volumes in a storage group in order to adjust the space. Below command can be issued in order to amend the volume in a storage group.ALTER STG1    ADD VOLUMES(VOL34)    REMOVE VOLUMES(VOL29);The ALTER reserved word has to be followed by the name of the storage group which needs to be altered. Which is STG1 in this case. The ADD VOLUMES parameter has the list of volumes which needs to be ... Read More

How to create a DB2 Tablespace in storage group STG1 and bufferpool BP01?

Mandalika
Updated on 11-Sep-2020 13:15:59

215 Views

A table space is a logical entity in DB2 architecture. It is basically a collection of data files. A tablespace contains tables, indexes, objects, etc. To create a new tablespace we have to issue the following command.CREATE TABLESPACE TABSPA1    IN DBSET1    USING STOGROUP STG1    PRIQTY 50    SECQTY 50    BUFFERPOOL BP03The CREATE AND TABLESPACE are the reserved words which are followed by the name of tablespace we want to create. In this case it is TABSPA1.IN is a reserved word which is followed by the name of the database in which we want to create this ... Read More

How to create a DB2 database DBSET1 in the storage group STG1?

Mandalika
Updated on 11-Sep-2020 12:51:47

120 Views

A database is a structured collection of data which can be organized, maintained and updated easily. There can be multiple databases in a DB2 installation. The DB2 database can be created by giving the name of the database, storage group and bufferpool, as below−CREATE DATABASE DBSET1       STOGROUP (STG1)    BUFFERPOOL BP3;The CREATE and DATABASE are the reserved words which are followed by the name of the database we want to create. The STOGROUP parameter should be given with the name of the storage group and finally BUFFERPOOL parameter followed by the name of bufferpool.

Advertisements