---
title: "DB2 数据表增加非空字段"
author: "ezerg"
date: "2011-07-14T13:56:46Z"
tags: []
categories: ["数据库"]
slug: "db2"
draft: false
lastmod: "2011-07-14T13:56:46Z"
id: 1124262
url: "https://ezerg.iteye.com/blog/1124262"
---

DB2 数据库的表中增加一个非空字段居然会报错，因为以前使用过的 Oracle 和 MySQL 都是可以直接增加的。
有两种方法：
1、增加允许为空的字段，新增字段写入数据后再改为 not null
2、指定非空的同时，指定默认值：alter table test add id int not null default 0