天极Yesky
  • 笔记本电脑
    笔记本
  • 台式电脑
    台式机
  • 手机
    手机
  • 电脑硬件DIY
    DIY硬件
  • CPU
    主板
    音箱
  • 硬盘
    显卡
    键鼠
  • 内存光驱
    显示器
    机箱电源

  • 数码相机DC
    数码相机
  • MP3播放器
    MP3/MP4
  • 数码摄像机DV
    摄像机
  • 电脑外设
    外设
  • 网络
    网络
  • 服务器
    服务器
  • 数字家庭
    数字家庭
  • 群乐
    群乐
  • 产品报价 行情 商家 新闻 评测 | 软件 设计 网页 开发 安全 论坛 E时代 游戏 图片 壁纸 下载 网摘 博客 索尼专区 Vista 科技奥运
    天极网
    Copy table records from one environment to another
    作者: Tim DiChiara
    出处:
    责任编辑:
    [ 2004-06-17 18:42 ]


    There is always a need to sync a DB2 database from one environment with another. Instead of using unload or load utilities that may require authorization, the following SQL (SELECT) statement can be executed in the source environment. The result can then be stored in a file/dataset that can be run in the destination environment to replicate the records. This SQL can be used in any DB2 version; I tested it on DB2 v7. Execute it one environment (e.g., Production) and its output can be executed on the other environment (e.g., Test). I think it can be used in any other RDBMS too, except that the single quote might need to be replaced with double quotes depending on the database.

    Here is the table structure:

     EMP
     
     EMPNO INTEGER
     EMPNAME CHAR(15)
     MGRNO INTEGER
     SALARY DECIMAL(7,2)
     JDATE DATE
    

    Here are the records:

     EMPNO EMPNAME MGRNO SALARY JDATE
     25    ADAMS   15    70000  2001-02-02
     30    BILL    15    60000  2000-06-01
    

    Here is the SQL:

      
     SELECT 'INSERT INTO EMP VALUES ( '||
           EMPNO         ||','||
     ''''||EMPNAME ||'''' ||','|| 
           MGRNO  ||','||
           SALARY  ||','||
     ''''||JDATE ||'''' ||');'
     FROM EMP
    

    Here is the output:

     
     INSERT INTO EMP VALUES (25,'ADAMS',15,70000,'2001-02-02');
     INSERT INTO EMP VALUES (30,'BILL',15,60000,'2000-06-01');
     

    The idea is to write a single quote(') to your output, so you have to use four quotes ('''').

    For More Information

    • Feedback: E-mail the editor with your thoughts about this tip.
    • More tips: Hundreds of free DB2 tips and scripts.
    • Tip contest: Have a DB2 tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize -- submit your tip today!
    • Ask the Experts: Our SQL, database design, Oracle, SQL Server, DB2, metadata, and data warehousing gurus are waiting to answer your toughest questions.
    • Forums: Ask your technical DB2 questions--or help out your peers by answering them--in our active forums.
    • Best Web Links: DB2 tips, tutorials, and scripts from around the Web.
    笔名:
    请您注意:

     遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。

     天极网拥有管理笔名和留言的一切权利。
    相关内容