[Tips] import the table structure to DB2 and execute SQL statements to create tables in batches.

Source: Internet
Author: User
Tags db2 connect db2 connect to

After the last write, how do I export the data structure and data ([Tips] exporting table structures and data from DB2). Now I have finally finished writing how to import the table structure.

The first step is to create a database. You can use control center or command line. However, for this new database, I prefer command editor.
After opening, you can directly write the following SQL text:

Create Database mydb2
On 'd :'
Using codeset IBM-eucjp
Territory JP
Collate using system;

It seems that only the drive letter is recognized after "ON". After the drive letter is successfully identified, continue to enable "CE" and select "mydb2" in "target". In fact, "connect to mydb2;" is executed ;', the purpose is to create a schema. The concept of schema is that every household has a TV set, but its ownership is different.
Write the following SQL statement:

CREATE SCHEMA UT001 AUTHORIZATION MyDB2;
CREATE SCHEMA UT002 AUTHORIZATION MyDB2;

So far, the database and schema have been created, and the SQL file for table creation has been imported. For example:


Now, every time we start to execute the table creation file. In this case, you can use DB2 command line to perform operations.

You can directly write SQL files in CE and execute them directly. However, if DDL is used to export SQL files and execute them one by one, it will be very troublesome. At this time, I suggest using batch processing. we can write a BAT file, placed under IBM/sqllib/bin:
 

DB2 connect to mydb2
DB2 set current schema ut001
DB2-tvf D:/data/test1. SQL
DB2-tvf D:/data/test.2sql
DB2 commit work
DB2 terminate
Note: first, if there are not multiple schemas, you do not need to use the second row. The parameter-tvf in the second and third rows is explained as follows,
-F: Read the input file.
-T: Specifies the statement termination character.
-V send back current command
If each statement in the file ends with a carriage return, use-VF. Adding-T indicates that no statement ends.

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.