DB2 database Import and Export and table structure Import and Export (db2look, move)

Source: Internet
Author: User

To log on to the database, follow these steps:

DB2 uses the command window to connect to the database

1. Export to a file to obtain the SQL statement
Db2look-D cqyancao-e-o dB. SQL-I db2user-W psw
Database Name to output file name username and password

Example: db2look-D department-u Walid-e-o db2look. SQL

-- This generates DDL statements for all tables and associated objects created by user Walid.
-- The db2look output is sent to a file named db2look. SQL.

Example: db2look-D department-Z myscm1-e-o db2look. SQL

-- This will generate DDL statements for all tables with the schema name myscm1
-- DDL of all associated objects created by $ user is also generated.
-- The db2look output is sent to a file named db2look. SQL.

Example: db2look-D department-u Walid-m-o db2look. SQL

-- This generates an update statement to capture statistics about the table/alias created by the user Walid.
-- The db2look output is sent to a file named db2look. SQL.

Example: db2look-D department-u Walid-e-wrapper W1-O db2look. SQL

-- This will generate DDL statements for all tables created by user Walid
-- DDL will also be generated for all Union objects created by user Walid of the package W1
-- The db2look output is sent to a file named db2look. SQL.

Example: db2look-D department-u Walid-e-server S1-O db2look. SQL

-- This will generate DDL statements for all tables created by user Walid
-- DDL for all associated objects created by user Walid of server S1 will also be generated
-- The db2look output is sent to a file named db2look. SQL.

2. Use the db2move command to export the database
To export initialization data from another database, first enter the exported directory, for example, D: \ dB,
Command: db2move dbname export-u username-P password. Note: dbname is the name of the original database, and username is the username and password is the password.

Restore command D: \ dB> db2move dbname import-u username-P Password

3. Use db2move to export and import a single table
Export db2move dbname export-Tn yc_news-u db2user-P Password
Import db2move dbname import-u db2user-P Password

4. Other problems
DB2 takes the first 10 records
For example:
DB2 => select * From tablename fetch first 10 rows only

DB2 Modify Field Length
DB2 alter table db2admin. config alter cvalue set datatype varchar (255)
For example:
DB2 = & gt; alter table news alter author set data type varchar (250)
DB2 => describe table news

Add a field in DB2
Alter table table_name
Add column column_name datatype

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.