DB2 database application is very common, for some beginners, these command Daquan is the first to grasp, then I will not say much nonsense, directly for you to present DB2 commonly used command Daquan.
Common Commands 1. Establish database DB2_GCB
CREATE DATABASE DB2_GCB on G:alias DB2_GCB
Using CodeSet GBK TERRITORY CN COLLATE USING SYSTEM DFT_EXTENT_SZ 32
2. Connect to the database
Connect to Sample1 user db2admin using 8301206
[@[email protected]]
3. Creating aliases
Create alias Db2admin.tables for Sysstat.tables;
CREATE ALIAS db2admin. Views for SYSCAT. Views
Create alias Db2admin.columns for Syscat.columns;
Create alias Guest.columns for Syscat.columns;
4. Create a table
CREATE TABLE Zjt_tables as
(SELECT * from tables) definition only;
CREATE TABLE Zjt_views as
(SELECT * from) definition only;
5. Inserting records
INSERT INTO Zjt_tables select * from tables;
INSERT INTO Zjt_views select * from views;
6. Building a View
CREATE View V_zjt_tables as select Tabschema,tabname from Zjt_tables;
7. Create a Trigger
CREATE TRIGGER Zjt_tables_del
After DELETE on Zjt_tables
referencing old as O
For each ROW MODE Db2sql
Insert into zjt_tables1 values (substr (o.tabschema,1,8), substr (o.tabname,1,10))
8. Establishing a unique index
CREATE UNIQUE INDEX I_ztables_tabname
On Zjt_tables (tabname);
9. View the table
Select TabName from tables
where tabname= ' zjt_tables ';
10. View Columns
Select SUBSTR (colname,1,20) as column name, TYPENAME as type, length as Long
From columns
where tabname= ' zjt_tables ';
11. View Table Structure
DB2 describe table User1.department
DB2 describe select * FROM User.tables
12. View the index of a table
DB2 describe indexes for table user1.department
13. View View
Select ViewName from views
where viewname= ' v_zjt_tables ';
14. View Index
Select Indname from Indexes
where indname= ' i_ztables_tabname ';
15. View the storage process
SELECT SUBSTR (procschema,1,15), SUBSTR (procname,1,15)
From SYSCAT. procedures;
16. Type conversion (CAST)
IP Datatype:varchar
Select CAST (IP As Integer) +50 from log_comm_failed
17. Reconnect
Connect Reset
18. Interrupt Database Connection
Disconnect DB2_GCB
View Application
LIST Application;
. Kill Application
Force application (0);
DB2 force applications all (forcing all applications to disconnect from the database)
. Lock table
Lock table test in exclusive mode
22. Sharing
Lock table test in Share mode
23. Show all tables for the current user
List tables
24. List all the system tables
List Tables for system
25. Display the current active database
List Active databases
26. View command Options
List command options
27. System Database Directory
LIST DATABASE DIRECTORY
28. Table Space
List tablespaces
29. Table Space Container
LIST tablespace CONTAINERS for
Example:list tablespace CONTAINERS for 1
30. Displaying access rights to the user's database
GET authorizations
31. Launch an instance
Db2start
32. Stopping an instance
Db2stop
33. Table or view privileges
Grant Select,delete,insert,update on tables to user
Grant all on tables to user with GRANT OPTION
34. Package Privileges
GRANT EXECUTE
On package Package-name
to public
35. Mode Privileges
GRANT Createin on SCHEMA schema-name to USER
36. Database Privileges
Grant Connect,createtab,dbadm on the database to user
37. Indexing Privileges
Grant control on index index-name to user
38. Information Help (? XXXNNNNN)
Cases:? SQL30081
SQL Help (Description of SQL statement syntax)
Help statement
For example, the Help SELECT
SQLSTATE help (stating the status and category Code of SQL)
SQLState or? Class-code
41. Change the password associated with the "Management Server"
Db2admin setid username Password
42. Create a SAMPLE database
Db2sampl
Db2sampl F: (Specify installation disk)
43. Using Operating system commands
! Dir
44. Convert data type (CAST)
SELECT EMPNO, CAST (RESUME as VARCHAR (370))
From Emp_resume
WHERE Resume_format = ' ASCII '
UDF.
To run a DB2 Java stored procedure or UDF, you also need to update the
DB2 Database Manager configuration to include the path to the JDK installed on the machine
DB2 update dbm CFG using Jdk11_path d:sqllibjavajdk
TERMINATE
Update dbm CFG using Spm_name sample
46. Check the DB2 database management program configuration
DB2 get dbm CFG
DB2 Common Command Daquan