DB2 column modification and restrictions

Source: Internet
Author: User

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

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.