建表、删除表:mysql oracle db2基本相同
create table test(id integer,name varchar(20),address varchar(20));
(oracle 多用varchar2,但也支持varchar)
drop table test;
但是修改表就有很大的不同了,如下:
1,增加列:相同
alter table test add mail varchar(128);
2,删除列:
oracle 与mysql相同:alter table test drop column mail;
db2 :不提供删除列功能(解决办法是删除表,重建)
3,更改列名
oracle : alter table test rename column mail to mail2;
mysql : alter talbe test change mail mail2 varchar(128);
db2 : 不提供更改列名功能(解决办法同删除,或者通过建立一个新视图解决)
4,更改列类型
oracle :alter table test modify column (mail2 integer);
mysql :alter table test modify column mail2 integer;
db2 :alter table test alter mail varchar(256) 只可以加宽,不能更改类型
5,更改列的限制(主键、非空)
db2 :alter table test alter mail null/not null;
mysql :alter table test modify mail2 varchar(29) not null;
oracle:alter table test modify mail2 null/not null;
关于db2不提供解决办法,参考这里
http://www-128.ibm.com/developerworks/cn/db2/library/techarticles/0207adamache/0430_adamache3.html
截取部分原文
-------------------------------------------------------------------------------
DROP COLUMN:DB2 不允许您删除一个列。我可以想到您希望删除列的三个理由:
回收空间:如果您希望这样做,可以导出您希望保存的数据,删除那个表,用您需要的那些列重新创建表,然后装入
这个表。这是否代价高昂?当然是,但是回收空间需要这样或者 REORG TABLE。这些本来就是代价高昂的操作。
这个列不再是行的逻辑部分:例如,您意识到您的雇员可能有两个地址,并且停止跟踪雇员(employee)表中的地址
(雇员表和雇员地址(employee_address)表之间现在有 n:m 关系)。在雇员表上创建一个不包含地址列的视图。
如果您真的要用新奇的方法,可以使用 RENAME TABLE 命令给基表一个新的名称,然后将原始表名作为该视图的
名称。您的视图也可以连接雇员表中的有用列和从雇员地址获得的地址。现在我们回到了关系的正道。
列变宽了。如果它是 VARCHAR,那您运气不错。DB2 允许您将 VARCHAR 列最多加宽至表空间(tablespace)
中定义的页大小宽度(缺省的 4K 页大小为 4,005,而在 32K 页上最多为 32,672):
---------------------------------------------------------------------------------
但是过程中问一个朋友,得到的结论是可以改,矛盾啊继续找资料:
http://www-1.ibm.com/support/docview.wss?uid=swg21004049
部分截取原文
-------------------------------------------------------------------------------
In DB2® Universal Database™ (DB2 UDB) Version 8.2, the Control Center automates
the process of altering a table where recreation of the table is necessary,
saving the user from performing a lengthy set of manual steps. Specifically,
the Control Center will automate the following operations: rename a column;
drop a column; change the data type of a column; change the length, scope,
or precision values for a column; change whether a column is nullable. If necessary,
the table that is being changed will be dropped and recreated, and DB2 UDB will
help the user restore any dependent objects and transform the existing data into
the target data type of each remaining column.
You cannot drop a column in DB2 UDB Version 8.1 or earlier. There are work-arounds.
For example, you can increase the width of a VARCHAR column up to the largest
column width supported by the page size used by the table (4005 bytes by default,
but possibly as large as 32672 byes on 32K pages). The page size is chosen
when the table space is created. To handle more complex changes:
-----------------------------------------------------------------------------
原来DB2 UDB Version 8.1 or earlier不支持,8.2才开始支持。
分享到:
相关推荐
ORACLE表生成MYSQL建表DDL
oracle导出ddl语句 表 所有 过程 包
oracle数据库转成mysql数据库的免费软件
oracle 获取用户ddl脚本,可获取用户ddl,在sqlplus 工具中打开
DB2数据库SQL语法(DDL,DML以及插入优化)总结,需要自己下载
MySQL to Oracle MySQL 转 Oracle亲自测试,好用
图形化实现sqlserver转换为mysql ddl(需字段注释) 应用于数据库、新老系统迁移,提升开发效率。
excel 生成oracle ddl , 工作中一般会出现这种情况,和其他单位合作开发项目时,对方会给我们一份他们的数据字典,excl或者world的,这种情况下我们要根据数据字典将表结构建好,但是一个字段一个字段的去复制粘贴会...
该文档基于windows DOS命令行环境下进行DDL,DCL,DML基础语法练习,包括数据库,表的创建,删除,修改,子查询,表连接,用户创建,授权等。
通过PL/SQL 自己手动生成DDL,不过目前我只写了 表、主键、注释、索引。其他的分区、约束还没写。后期加上 缺陷:每个字段后面都有","需要手动剔除,修改过后的已上传,csdn中不知道怎么修改,只好重新上传
简单整理的Mysql的基础用法,一共6个PPT基本覆盖了DDL、DQL等五项内容,查询最为重点内容进行了分类讲解,欢迎下载,关注我的博客有额外福利哟
三、oracle数据定义ddl和dml.pptx
ORACLE获取DDL的几种常用的方法[归纳].pdf
我们都知道在9i之前,要想获得建表和索引的语句是一件很麻烦的...在 Oracle 9i中,我们可以直接通过执行dbms_metadata从数据字典中查处DDL语句。使用这个功能强大的工具,我们可以获得单个对象或整个SCHEMA 的DDL语句。
goldengate配置ddl,网络资源大家学习参考。
关于Oracle DDL,DML,DCL,TCL 的一些基础概念,对于初学者很有帮助
VBA从ORACLE生成DDL例子,部分EXCEL文档的数据处理
数据库文档生成器,根据数据库表DDL生成markdown和word文档.zip