DB2 table management statements

Source: Internet
Author: User
Tags db2 create table

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.