DB2列的修改方法未必人人都会,下面对DB2列的修改及限制作出详细的介绍,如果您对DB2列的修改方法感兴趣的话,不妨一看。
1.修改长度
alter table tab_name alter c1 set data type varchar(20)
2.设置为非空
alter table tab_name alter c1 set not null
create table tab_name (id interger not null)
3.设置默认值
create table tab_name (id integer,name varchar(10) with default 'none')
4.为列创建序列
使用关键字 generated always as identity
create table tab_name (id integer generated always as identity (start with 1,increment by 1))
5.唯一性约束
使用关键字primary key
create table tab_name (id int not null primary key)
使用关键字unique
alter table tab_name add constraint unique (id)
create unique index idx_name on tab_name (id)
6.检查性约束
使用关键字check
ALTER TABLE BOOKS ADD BOOKTYPE CHAR(1) CHECK (BOOKTYPE IN ('F','N') )
7.参照约束
使用关键字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)
【编辑推荐】