DB2列的修改及限制

数据库
下文为您介绍了一些DB2列的修改语句的写法,以及其中的一些限制,如果您是刚刚接触DB2数据库的新手,不妨一看,对您会有所帮助。

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)
 

 

【编辑推荐】

DB2删除重复记录的五种情况

九个DB2常用命令

aix下DB2创建表空间的方法

DB2索引设计准则

对DB2故障处理及最佳实践的浅析

 

责任编辑:段燃 来源: 互联网
相关推荐

2010-11-03 14:52:26

DB2列转行

2010-11-01 11:45:06

DB2管理页大小

2010-11-03 11:26:39

DB2表空间

2010-11-03 15:35:27

DB2修改表

2010-11-03 16:25:51

DB2列函数

2010-09-01 13:43:06

DB2表空间

2010-09-06 14:08:00

DB2管理页大小

2010-07-27 10:57:27

2010-09-07 17:12:46

DB2故障处理

2010-08-26 11:37:38

DB2命令

2010-11-03 15:49:32

DB2删除表

2010-07-30 10:24:18

2010-08-11 09:14:33

DB2数据类型

2010-09-06 15:13:05

DB2

2010-11-04 15:39:40

DB2 SQL语句

2010-11-04 14:19:46

DB2事件监控

2010-11-04 11:07:56

DB2管理命令

2010-09-30 15:52:55

DB2循环查询

2010-11-02 14:08:29

DB2创建用户

2010-11-03 14:16:29

DB2增量备份
点赞
收藏

51CTO技术栈公众号