The statements related to DB2 table management are the basic knowledge of DB2 database systems. The following describes some DB2 table management statements in detail, hoping to help you learn about DB2 table management.
Create a table
CREATE TABLE BOOKS
(Bookid integer,
Bookname varchar (100 ),
Isbn char (10 ))
Use like to create a table
CREATE TABLE MYBOOKS LIKE BOOKS
Create a tablespace
Db2 create table T1 (c1 int...) in TS1
Db2 create table T2 (c1 float...) in TS1
Delete table
Drop table tab_name
Add and delete Columns
Db2 => create table test (c1 int)
DB20000I The SQL command completed successfully.
Db2 => alter table test add c2 char (8)
DB20000I The SQL command completed successfully.
Db2 => alter table test drop c2
DB20000I The SQL command completed successfully.
Column modification and restrictions
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)
Policy Selection for DB2 environment variable Management
Several Simple DB2 operation statements
Read stability at the DB2 isolation level
Security risks in the directory view of DB2 System
Introduction to DB2 information directory Center