insert into test1 (LNAME,FNAME,AGE) values ('LL','FF',7);
insert into test1 (AGE,LNAME,FNAME) values (8,'LL','FF');
insert into test1 (age,lnameE,fname) values (9,'LL','FF');
select * from test1
db2 -r file1.txt "select * from test3 order by fname"
db2 "select * from test3 order by fname" > file2.txt
db2 'export to test1.txt of del select * from test1'
db2 'import from test1.txt of del insert into test1'
db2 'import from test1.txt of del replace into test1'
Saving DDL for the database
(or for selected tables and their indexes) in a file:
db2look -d acct -e >myfile.txt
db2look -d acct -e -a -t test1 test2
db2look -d acct -e -a -t test1 test2 -o myfile.txt
db2look -d acct -e -a -t test1 test2 > myfile.txt
db2 list database directory
db2 ? list tables
db2 list tables for user
db2 list tables for schema db2inst1
db2 "select * from test1"
db2 'select * from test1 fetch first 10 rows only'
db2 describe table test1
db2 "select TABNAME from SYSCAT.TABLES where TABNAME like 'A+_%' escape '+'"
db2 "select TABNAME from SYSCAT.TABLES where TABNAME like 'A%'"
db2 describe table A_ACCOUNT
db2 "create unique index ia_transactions on a_transactions (tran_id,dt_tran) cluster"
vi test.sql
select * from test1 where fname='Lev';
select * from test1 where fname='Vera';
-- run many commands from a file.
-- Don't forget to separate SQL statments with ";"
db2 -tvf test.sql
db2 "create table session.ss ( fname varchar(60),lname varchar(60), age int)"
db2 "insert into session.ss values ('aa','bb',5)"
db2 "select * from session.ss"
db2 list tables for user
db2 list tables for schema session
db2 terminate
exit
db2 connect to ACCT user db2inst1 using ibmdb2
db2 list tables for schema session
-- calling shell commands from inside db2 using '!':
db2 '! ls -ltr'
db2 "! ls -ltr"
Some commands for Windows:
db2ic - inform.center
db2cca -client configuration assistant
db2cmd - db2 command window
insert into test1 (AGE,LNAME,FNAME) values (8,'LL','FF');
insert into test1 (age,lnameE,fname) values (9,'LL','FF');
select * from test1
db2 -r file1.txt "select * from test3 order by fname"
db2 "select * from test3 order by fname" > file2.txt
db2 'export to test1.txt of del select * from test1'
db2 'import from test1.txt of del insert into test1'
db2 'import from test1.txt of del replace into test1'
Saving DDL for the database
(or for selected tables and their indexes) in a file:
db2look -d acct -e >myfile.txt
db2look -d acct -e -a -t test1 test2
db2look -d acct -e -a -t test1 test2 -o myfile.txt
db2look -d acct -e -a -t test1 test2 > myfile.txt
db2 list database directory
db2 ? list tables
db2 list tables for user
db2 list tables for schema db2inst1
db2 "select * from test1"
db2 'select * from test1 fetch first 10 rows only'
db2 describe table test1
db2 "select TABNAME from SYSCAT.TABLES where TABNAME like 'A+_%' escape '+'"
db2 "select TABNAME from SYSCAT.TABLES where TABNAME like 'A%'"
db2 describe table A_ACCOUNT
db2 "create unique index ia_transactions on a_transactions (tran_id,dt_tran) cluster"
vi test.sql
select * from test1 where fname='Lev';
select * from test1 where fname='Vera';
-- run many commands from a file.
-- Don't forget to separate SQL statments with ";"
db2 -tvf test.sql
db2 "create table session.ss ( fname varchar(60),lname varchar(60), age int)"
db2 "insert into session.ss values ('aa','bb',5)"
db2 "select * from session.ss"
db2 list tables for user
db2 list tables for schema session
db2 terminate
exit
db2 connect to ACCT user db2inst1 using ibmdb2
db2 list tables for schema session
-- calling shell commands from inside db2 using '!':
db2 '! ls -ltr'
db2 "! ls -ltr"
Some commands for Windows:
db2ic - inform.center
db2cca -client configuration assistant
db2cmd - db2 command window
本文介绍了DB2数据库中常用的SQL命令及其应用场景,包括插入数据、查询数据、创建表、建立索引、导出数据定义等操作。通过具体的SQL语句示例,帮助读者更好地理解和掌握DB2数据库的基本管理和维护技能。
1364

被折叠的 条评论
为什么被折叠?



