Interview Questions   Tutorials   Discussions   Programs   

DB2 - How we create a tables in db2,what is the process/syntax to create a table ?




327
views
asked mar August 25, 2014 11:06 AM  

How we create a tables in db2,what is the process/syntax to create a table ?


           

1 Answers



 
answered By Mswami   0  
CREATE TABLE statement:

The CREATE TABLE statement defines a table. The definition must include its name and the names and attributes of its columns. The definition can include other attributes of the table, such as its primary key or check constraints.

Syntax:

CREATE TABLE SCHEMA.TABLENAME
(column1 DATATYPE,
column2 DATATYPE,
column3 DATATYPE)
IN tablespace_name
INDEX IN index_tablespace;

Example:

The example below creates a table named CORP.DIVISION in the table space TS111 of the database DSNMAIN. The table is created with four columns: DIVNUM, DIVNAME, MGR, and LOCATION, allowing only MGR and LOCATION to contain nulls, and designating DIVNUM as the only column in the table's primary key. All four columns hold character string data.

CREATE TABLE CORP.DIVISION
 (DIVNUM  CHAR(3)   NOT NULL,
 DIVNAME VARCHAR(36) NOT NULL,
 MGR   CHAR(6)       ,
 LOCATION CHAR(16)      ,
 PRIMARY KEY(DIVNUM)     )
 IN DSNMAIN.TS111;

flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert