The modification method of DB2 columns may not be available to everyone. The following describes the modification and restrictions of DB2 columns in detail. If you are interested in the modification method of DB2 columns, take a look.
1. Modify the length
Alter table tab_name alter c1 set data type varchar (20)
2. Set to non-empty
Alter table tab_name alter c1 set not null
Create table tab_name (id interger not null)
3. Set the default value
Create table tab_name (id integer, name varchar (10) with default 'None ')
4. Create a sequence for the column
Use the keyword generated always as identity
Create table tab_name (id integer generated always as identity (start with 1, increment by 1 ))
5. uniqueness constraints
Use the primary key keyword
Create table tab_name (id int not null primary key)
Use the keyword unique
Alter table tab_name add constraint unique (id)
Create unique index idx_name on tab_name (id)
6. Check Constraints
Use the keyword check
Alter table books add booktype char (1) CHECK (booktype in ('F', 'n '))
7. Reference Constraints
Use keyword references
Create table authors (authorid integer not null primary key,
Lname varchar (100 ),
Fname varchar (100 ))
Create table books (bookid integer not null primary key,
Bookname varchar (100 ),
Isbn char (10 ),
Authorid integer references authors)
Five situations in which DB2 deletes duplicate records
Nine common DB2 commands
How to Create a tablespace in DB2 under aix
DB2 index design guidelines
Analysis on DB2 troubleshooting and best practices