Let's understand Mainframe
Home Tutorials Interview Q&A Quiz Mainframe Memes Contact us About us

Module 3: DB2 Objects


Table

A table is the DB2 object that actually holds data. It consists of columns and rows and defines the physical characteristics of the data to be stored. Tables are related to each other through their key fields.

Organization of a table

  • Each table has one or more rows (records).
  • Each row contains one or more columns (fields).
  • The data in a specific column of a specific row is called a value.
  • A table may have a primary key that uniquely identifies each row.
  • An index can be applied to any column of a table for faster access.

CREATE TABLE - example

  • A CUSTOMER table with a primary key, created in the CUSTTS tablespace:-
    CREATE TABLE MM01.CUSTOMER (CUSTNO CHAR(6) NOT NULL, FNAME CHAR(20) NOT NULL, LNAME CHAR(30) NOT NULL, ADDR CHAR(30) NOT NULL, CITY CHAR(20) NOT NULL, STATE CHAR(2) NOT NULL, ZIPCODE CHAR(10) NOT NULL, PRIMARY KEY (CUSTNO)) IN MMADBV.CUSTTS;
  • MM01 is the creator (schema), each column has a data type and length, NOT NULL means the column cannot hold nulls, and PRIMARY KEY (CUSTNO) makes CUSTNO the unique identifier of each row.
  • Tables are changed with ALTER TABLE and removed with DROP TABLE.





© copyright mainframebug.com
Privacy Policy
MainframeBug Assistant