This article mainly introduces some summaries of DB2 databases that beginners must read. I accidentally saw some general information about DB2 on a website. I think it is quite good to share with you today. The following is a detailed description of the article, hoping to help you in this regard.
DB2-
Create Database DB2 create database name and delete database DB2 drop DATABASE name in command DB2cmd)
Enabling database DB2start
Disable DB2 database DB2stop and force disable DB2stop force
Connect to database DB2 connect to Database Name user Username using user Password
Fracture current database connection DB2 disconnect current
List all tables in the database DB2 list tables
List the data structure of a table DB2 describe table name
After installing the DB2 database-
Step 1: Create a database:-go to the console and manually create the database. Then-
Start running enter "Beginner DB2 database cmd"
1. Find the drive letter that stores the SQL statement for table creation, such as the e disk.
Command: e:
Run: // table creation command
Connect first
- DB2 connect to ycportal user DB2admin using admin
Table creation methods)
1. Create a table SQL DB2-tvf lfdb. SQL> 0728.txt
2. create a separate DB2 create table name (id numeric not null, name varchar (20), constraint t_p primary key (id ))
After the execution, the input data warehouse password is not displayed. the token is displayed in 0728.txt!
2. Start data import-run-DB2admin-find the directory where the data backup is stored
Create a database connection:
DB2 connect to ycportal Database Name) user DB2admin user Name) using admin password)
Import data: Command 2 methods )-
1. import the backup data to DB2move ycportal import> dblog.txt
Clear the original data after import-DB2move database name import-io replace-u DB2 database admin-p admin
2. Separately import a table DB2 insert into table name values (1, 'chennan '), (2, 'spsoft ')
3. When querying a table-DB2 select * from Table Name
Backup:
1. Find the target drive letter to be exported, such as the drive E.
Command: e:
Find the directory where you want to store the data backup
Create a database connection: the name of the DB2 connect to ycportal database) user DB2admin username) using admin password)
Export data: Command-DB2move ycportal export> dblog.txt
Export a separate table DB2move ycportal export-tn + Table name +-u DB2admin-p admin
A simple DB2 import backs up data first and then restores the data to the database you just created. You do not need to create a table in advance !!! The following is the backup command for the DB2 database.
DB2 backup database name my database is jsdb)
I forgot to mention that you need to stop the database you want to back up before backup. I used the DB2stop force parameter to use the force parameter because it is so easy to stop and save time :) And DB2start. This ensures that the backup is successful.
After the backup is complete, the beginner DB2 will tell you a timestamp, for example, several digits after 20040831). This will generate a folder name with the same name as your database in the current directory, for example, jsdb. This folder directory level is very important. If an error occurs, the system will prompt that the file cannot be found during recovery.
After the backup is complete, it is restored. I use the restore command.
DB2 database restore database name jsdb) taken at timestamp 20040831)
Note the following two points when executing this statement: 1. To test the backup folder to the current directory, I used a cd c: \ command to set the current directory as a drive c, test the jsdb folder to the c root directory); 2. the timestamp must be consistent with that in the jsdb directory.
In this way, the database is restored.