Find the Primary Key of a DB2 Table

Mandalika
Updated on 12-Sep-2020 14:39:04

7K+ Views

We can find the primary key of any table using the SYSIBM.SYSCOLUMNS table. The SYSIBM.SYSCOLUMNS is a DB2 system table which contains one row for every column of each table. It also contains the data related to the views. Below SQL query can be fired in order to find the primary key of a particular table.SELECT NAME FROM SYSIBM.SYSCOLUMNS WHERE TBNAME = 'TAB1’ AND KEYSEQ > 0 ORDER BY KEYSEQ ASC;We will use our table name in the TBNAME column of SYSCOLUMNS table using the WHERE clause and KEYSEQ > 0 will return only primary keys.

Create an Alias Tab2 for DB2 Table Tab1

Mandalika
Updated on 12-Sep-2020 14:36:43

422 Views

The ALIAS is basically a different name given to a particular object in a database. An ALIAS can be defined for a table, view or another alias and the existence of the object is not verified during the creation of the alias. The ALIAS is used to hide the location qualifier and we need SYSADM authority to create a new ALIAS. When the object is dropped, its corresponding ALIAS is not dropped.We can use the below command in order to create a new ALIAS for a table.CREATE ALIAS T1    FOR DBSET1.TAB1The CREATE ALIAS reserved words are followed by the ... Read More

Copy Entire DB2 Table into a Dataset

Mandalika
Updated on 12-Sep-2020 14:32:30

2K+ Views

The image copy allows us to download or copy the DB2 table into a mainframe dataset. There are two types of Image copy i.e. Full image copy and Incremental image copy. The full image copy is used to take the backup of the entire table. The incremental image copy refers to the differential backup. In order to take the full image copy of the DB2 table we can use the below JCL step.//STEP1 EXEC DSNUPROC //SYSCOPY DD DSN=TEST.TAB1.COPY, UNIT=SYSDA, VOL=SER=CPY01I, // SPACE=(CYL, (15, 1)), DISP=(NEW, CATLG, CATLG) //SYSOUT DD SYSOUT=* //SYSIN DD * COPY TABLESPACE TAB1SPAC /*We can use the ... Read More

Create DB2 Segmented Tablespace in Storage Group

Mandalika
Updated on 12-Sep-2020 14:29:54

478 Views

A segmented table space is divided in multiple segments. A segment is defined as a contiguous set of fixed number of pages. This fixed number is defined during the table space definition using the SEGSIZE parameter. The SEGSIZE serves multiple purposes - It defines the tablespace as segmented and also defines the size of the segment.In a segmented tablespace, the rows of a table are stored in one or more segments and a particular segment can only have rows from one table.The segmented tablespace can be created by using the CREATE TABLESPACE command with SEQSIZE parameter as below.CREATE TABLESPACE TABSPA1 ... Read More

Create DB2 Tablespace Tabspac1 in Database Dbspac1

Mandalika
Updated on 12-Sep-2020 14:27:21

159 Views

A tablespace is a collection of data files which resides inside a DB2 database. It is used to organize the data logically. Any DB2 database contains at least one tablespace and in the real world scenario there are multiple tablespaces within a database which are allocated for different business units. In order to create a new tablespace, we have to provide the command as below−CREATE TABLESPACE TABSPA1    IN DBSPAC1    USING STOGROUP STG1    PRIQTY 50    SECQTY 50    BUFFERPOOL BP02    ERASE NOThe CREATE AND TABLESPACE are the reserved words which are followed by the name of ... Read More

Add Row Compression to a DB2 Table

Mandalika
Updated on 12-Sep-2020 14:25:22

523 Views

A compression is used to save the DB2 disk space. The compression can be used either at row level or at a page level. In order to add a row compression in a DB2 table, we can give the following command−ALTER TABLE DBSET1.TAB1 COMPRESS YES STATICWe have to use ALTER TABLE for the compression of the DB2 table. The ALTER TABLE reserved words are followed by the name of DB2 table qualified by database. COMPRESS YES STATIC will complete the row compression for the said table.

Delete All DB2 Packages in Collection COLL1

Mandalika
Updated on 12-Sep-2020 14:22:49

488 Views

A DB2 collection is a physical quantity which is used to group the packages. A collection can be simply termed as a group of DB2 packages. By using collections we can bind the same DBRM into different packages. In order to delete all the DB2 packers under a collection, we can issue below command.FREE PACKAGE(COLL1.*)The FREE PACKAGE reserved word is followed by the name of collection i.e. COLL1. The * after the collection name indicates that we need to perform delete action for all the packages under the said collection.

Delete a DB2 Table

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

947 Views

We can delete the unused tables in the DB2. However, we must keep in mind that if we delete a table then all the indexes associated with the table are also dropped. Moreover, the triggers and views for the deleted table will become inaccessible. To delete any table in DB2, we can issue below command.DROP TABLE DBSET1.TAB1The DROP TABLE reserved word will be followed by the name of the table qualified by the database. The mentioned table will be deleted from the DB2 permanently.

Change Length of Name Column from CHAR(20) to CHAR(50)

Mandalika
Updated on 12-Sep-2020 14:17:33

160 Views

DB2 gives us an option of modifying the attribute of the existing column in a table. We have to use the ALTER COLUMN parameter with ALTER TABLE as below in order to achieve this.ALTER TABLE DBSET1.TAB1    ALTER COLUMN NAME       SET DATATYPE CHAR(50);The ALTER TABLE reserved words are followed by the name of the table qualified by a database, which is DBSET1.TAB1 in this case. Similarly, ALTER COLUMN is followed by the name of the column which needs to be modified, which NAME (of the student) in this case.In the SET DATATYPE parameter, we can pass the ... Read More

Create Table Tab2 with Same Attributes as Table Tab1

Mandalika
Updated on 12-Sep-2020 14:13:49

282 Views

DB2 gives us an option to copy the structure of an existing table to a new table. To copy the attributes and column of table TAB1 to a new table TAB2 we can use the following command−CREATE TABLE DBSET1.TAB2    LIKE DBSET1.TAB1The CREATE TABLE reserved words are followed by table name. The table name needs to be qualified by a database in which it will reside. In this case this new table is TAB2 and its database is DBSET1.The LIKE parameter is used after that followed by the name of the original table qualified by its database i.e. DBSET1.TAB1The important ... Read More

Advertisements