Commonly used methods of implementation and common techniques of Informix dbaccess

Source: Internet
Author: User
Tags informix

Assume:

A. Database Servername:testserver

B. Database name: TestDB

C.sql script file:

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;

I. How to execute SQL script file

1. Call dbaccess Execute SQL script file

A. Simple execution of SQL files

dbaccess TestDB sqlfile.sql or dbaccess [email protected] Sqlfile.sql

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

B. Execute output Print execution statement and execution result

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. Redirecting execution results to a file (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.

Two. Interactive mode execution statement

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

Three. Menu Mode execution

Enter the database

Dbaccess Selecting a Database

Or

Dbaccess TestDB

dbaccess [email protected]

Executes the SQL statement by menu operation, where you can edit the script file using VI

Four. A few tips

1. When executing a SQL script file, print verbose error messages when an error occurs

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. When executing a SQL script file, print verbose error message when an error occurs and stop execution of subsequent statements when the first error is encountered

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.

Commonly used methods of implementation and common techniques of Informix dbaccess

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.