Creating Primary Key while creating DB2 Table
Creating Primary Key while creating DB2 Table
How to define a Primary Key while creating a DB2 table?
Generally when we create a DB2 table, we create the primary key
using the same query. You can use the following query to do this.
CREATE TABLE Table_Name(Column_one datatype,column_two datatype,::PRIMARY KEY (Column_one))
Where
Table_Name is the name of the table
Column_One and Column_two are the columns in the table
An example is shown below
CREATE TABLE Emp_Table(Emp_Number CHAR(10) NOT NULL WITH DEFAULT,Emp_Salary DECIMAL(10,0) NOT NULL WITH DEFAULT,Emp_Sec_code SMALLINT NOT NULL WITH DEFAULT,PRIMARY KEY(Emp_Number))