假设:

A.数据库servername: testserver

B.数据库名:testdb

C.SQL脚本文件:

sqlfile.sql

create table test_table(c1 integer);

insert into test_table(c1) values(12);

update test_table set c1=0;

delete test_table where 1=1;

drop table test_table;

sqlfile2.sql

create table test_table(c1 integer);

insert into test_table(c2) values(12);

insert into test_table(c1) values(12);

update test_table set c1=0;

delete test_table where 1=1;

drop table test_table;


一.执行SQL脚本文件方式

1.调用dbaccess执行SQL脚本文件

A.简单执行SQL文件

dbaccess testdb sqlfile.sql 或者  dbaccess testdb@testserver sqlfile.sql

Database selected.
     Table created.
     1 row(s) inserted.
     1 row(s) updated.
     1 row(s) deleted.
     Table dropped.
     Database closed.

B.执行输出打印执行语句及执行结果

dbaccess -e testdb sqlfile.sql

create table test_table(c1 integer);
       Table created.
     insert into test_table(c1) values(12);
       1 row(s) inserted.
     update test_table set c1=0;
       1 row(s) updated.

delete test_table where 1=1;
       1 row(s) deleted.

drop table test_table;
       Table dropped.
     Database closed.

C.将执行结果重定向到文件(shell: bash)

dbaccess -e testdb sqlfile.sql > output.log > 2&1

     cat output.log

     create table test_table(c1 integer);
       Table created.
     insert into test_table(c1) values(12);
       1 row(s) inserted.
     update test_table set c1=0;
       1 row(s) updated.

     delete test_table where 1=1;
       1 row(s) deleted.

     drop table test_table;
       Table dropped.
     Database closed.

二.交互模式执行语句

dbaccess - -
    > database testdb;

Database selected.

> create table test_table(c1 integer);
        Table created.

> insert into test_table(c1) values(12);
        1 row(s) inserted.
     > update test_table set c1=0;
        1 row(s) updated.

     > delete test_table where 1=1;
        1 row(s) deleted.

     > drop table test_table;
        Table dropped.

>^D

三.菜单模式执行

进入数据库

dbaccess  选择数据库

或者

dbaccess testdb

dbaccess testdb@testserver

按菜单操作执行SQL语句,其中可以使用vi进行脚本文件的编辑

四.几个小技巧

1.执行SQL脚本文件时,当出错时打印详细的错误信息

    dbaccess -e -m testdb sqlfile2.sql

Database selected.
 
create table test_table(c1 integer);
   Table created

insert into test_table(c2) values(1212);
  217: Column (c2) not found in any table in the query (or SLV is undefined).
Error in line 2
Near character position 26
 
   insert into test_table(c1) values(12);
1 row(s) inserted.
      update test_table set c1=0;
1 row(s) updated.
         delete test_table where 1=1;
1 row(s) deleted.
            drop table test_table;
Table dropped.
Database closed.

2.执行SQL脚本文件时,当出错时打印详细的错误信息并在出现第一个错误时,停止继续执行后续的语句

    dbaccess -e -m -a testdb sqlfile2.sql

Database selected.
 
create table test_table(c1 integer);
Table created.
 
insert into test_table(c2) values(1212);
  217: Column (c2) not found in any table in the query (or SLV is undefined).
Error in line 2
Near character position 26
 
Database closed.

informix dbaccess 常用执行方式及常见技巧的更多相关文章

  1. python常用执行方式&变量&input函数

    linux系统中执行py文件方式:  ./a.py 需要执行权限 chmod -R 777(最大权限) 常用执行方式: 1. ./a.py2. python a.py 文件内部头加上 #!/usr/b ...

  2. shell脚本的常用执行方式

    1.sh+脚本的相对路径 [jinghang@hadoop101 datas]$ sh helloworld.sh helloworld sh+脚本的绝对路径 [jinghang@hadoop101 ...

  3. iOS代码加密常用加密方式

    iOS代码加密常用加密方式 iOS代码加密常用加密方式,常见的iOS代码加密常用加密方式算法包括MD5加密.AES加密.BASE64加密,三大算法iOS代码加密是如何进行加密的,且看下文 MD5 iO ...

  4. 找到你的位置(JS在页面中的位置)最常用的方式是在页面中head部分放置<script>元素,浏览器解析head部分就会执行这个代码,然后才解析页面的其余部分

    找到你的位置(JS在页面中的位置) 我们可以将JavaScript代码放在html文件中任何位置,但是我们一般放在网页的head或者body部分. 放在<head>部分 最常用的方式是在页 ...

  5. python基础===Python 代码优化常见技巧

    Python 代码优化常见技巧 代码优化能够让程序运行更快,它是在不改变程序运行结果的情况下使得程序的运行效率更高,根据 80/20 原则,实现程序的重构.优化.扩展以及文档相关的事情通常需要消耗 8 ...

  6. 「持续集成实践系列 」Jenkins 2.x 构建CI自动化流水线常见技巧

    在上一篇文章中,我们介绍了Jenkins 2.x实现流水线的两种语法,以及在实际工作中该如何选择脚本式语法或声明式语法.原文可查阅:「持续集成实践系列」Jenkins 2.x 搭建CI需要掌握的硬核要 ...

  7. MySQL DDL执行方式-Online DDL介绍

    1 引言 大家好,今天与大家一起分享一下 mysql DDL执行方式. 一般来说MySQL分为DDL(定义)和DML(操作). DDL:Data Definition Language,即数据定义语言 ...

  8. jQuery中ajax的4种常用请求方式

    jQuery中ajax的4种常用请求方式: 1.$.ajax()返回其创建的 XMLHttpRequest 对象. $.ajax() 只有一个参数:参数 key/value 对象,包含各配置及回调函数 ...

  9. DataGridView 中添加CheckBox和常用处理方式 .

    DataGridView 中添加CheckBox和常用处理方式 文章1 转载:http://blog.csdn.net/pinkey1987/article/details/5267934 DataG ...

随机推荐

  1. Android EditText组件drawableLeft属性设置的图片和hint设置的文字之间的距离

    有的时候,我们需要在文本框里放置icon图片,并且设置默认提示文字的时候,需要设置两者之间的间距,如下图: 这里想设置的就是之前的手机icon和”请输入手机号“之间的距离,则可是使用以下的方式: &l ...

  2. RDIFramework.NET ━ Web中打印的各种方案参考-欢迎补充

    RDIFramework.NET ━ Web中打印的各种方案参考-欢迎补充 做Web开发的同志应该都深有体会,在web程序中打印不再象应用程序中那样便于控制了,web程序天生的一些特性造成了这个缺点, ...

  3. 应该具备的调试技能(java)

    ------Java部分---------- 1. tomcat在eclispe中怎样启动调试模式2. 带有main方法的Java应用程序怎样启动调试模式3. 调试在eclispe中的快捷键 F5 F ...

  4. FlashFXP5_gr坑爹的故事

    数据中心说已把数据存放到ftp上,但我通过flashfxp5工具链接到ftp server查看数据中心存放的数据,一天了都没有看到数据结果,经过我反复多次重新链接否没有发现数据中心所说的最新数据结果, ...

  5. php生成随机数的三种方法

    php生成随机数的三种方法 如何用php生成1-10之间的不重复随机数? 例1,使用shuffle函数生成随机数. <?php$arr=range(1,10);shuffle($arr);for ...

  6. My roadway of compilers principles.

    龙书学习过程代码记录--Python3.5(毕竟第一遍看书,书里面的例子全用python写的) One 将中缀表达式翻译成后缀表达式↓ class Parser(object): def __init ...

  7. Android DrawerLayout Plus 增强版抽屉菜单

    DrawerLayout是官方提供的侧滑菜单,相比SliddingMenu,它更加轻量级.默认情况下,DrawerLayout可以设置左侧或者右侧滑出菜单.如下,   xml布局: <!-- & ...

  8. jQuery全选/反选checkbox

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  9. (原创)关于SQL Server 2005 的自动远程数据库备份

    由于项目需要,需要对目标服务器上的数据库每天进行备份并转移,查阅网上的一些帮助,结合自己的实际需要,写了这篇文章,希望对有同样需求的朋友有所帮助.目标服务器:192.168.1.197,备份服务器:1 ...

  10. 20160411002 经典SQL语句大全

    一.基础 1.说明:创建数据库CREATE DATABASE database-name 2.说明:删除数据库drop database dbname3.说明:备份sql server--- 创建 备 ...