
DB2
月下山川
这个作者很懒,什么都没留下…
展开
-
db2更新语句
update。原创 2021-01-16 15:37:35 · 1067 阅读 · 1 评论 -
db2删除语句
delete from tableName where condition;delect from(select * from tableName where condition);alter table tableName activate not logged initially with empty table;原创 2021-01-16 15:36:43 · 1837 阅读 · 1 评论 -
复制数据表结构
create table newTableName as ( select * from oldTableName ) definition only in 表空间;create table newTableName like oldTableName in 表空间;原创 2021-01-16 15:36:21 · 150 阅读 · 1 评论 -
db2更新并查询更新前后的数据
(update schema.tableName set age = 'xxx' where condition); ---更新后的数据select * from oldtable(update schema.tableName set age = 'xxx' where condition); --更新前的数据原创 2021-01-16 15:37:53 · 1305 阅读 · 1 评论 -
db2查询数据集合-- 并集、交集
关键字后面都可以接 all 如果不接all 操作集合将会去除重复值。用来求在第一个集合中存在,而在第二个集合中不存在的记录。用来求两个集合的并集;用来求两个集合的交集;原创 2021-01-16 15:38:08 · 533 阅读 · 0 评论 -
db2分页查询
select * from(select b.*,rownumber() over() as rn from( select * from <tableName> ) as b) as a where a.rn between <start_number> and <end_number>;原创 2021-01-09 22:15:20 · 336 阅读 · 0 评论 -
导入数据设置字符集
modified by codepage = 1208db2 "export to tableName.ixf of ixf modified by codepage = 1208 select * from schema.tableName" ;原创 2021-01-09 22:14:53 · 394 阅读 · 0 评论 -
删除schema
drop schema "schemaName" restrictdb2 "drop schema |"schemaName"| restrict"原创 2021-01-09 22:12:56 · 1509 阅读 · 0 评论 -
创建索引
普通索引create indes "schema"."indexName" on "schema"."tableName"("字段1" asc, "字段2" asc)compress no allow reverse scans;唯一索引create unique index "schema"."indexName" on "schema"."tableName"("字段" asc)xompress no allow reverse scans;主键约束索引alte...原创 2021-01-09 22:12:18 · 618 阅读 · 1 评论 -
查找并解锁表
select * from sysibmadm.locks_held; ---查看锁表情况db2 "force applications(56001)" --解锁原创 2021-01-09 22:10:27 · 335 阅读 · 0 评论 -
只查询一条数据或抽样查询数据
select * from tableName fetch first 1 rows only;select * from tableName order by rand() fetch first 1 rows only;-------------------------------select * from staff tablesample bernoulli(8) repeatable(586) order by id;--说明:从staff 表中,采用bernoulli 抽样...原创 2021-01-09 22:09:04 · 883 阅读 · 0 评论 -
数据迁移(迁移数据库)
db2 connect to cbrcdbdb2look -d cbrcdb -z schema -e -o schema.sql --不带dropdb2look -d cbrcdb -z schema -e -dp -o schema.sql --带dropdb2 -tvf schema.sql | tee schema.logdb2 disconnect all原创 2021-01-09 22:04:00 · 103 阅读 · 0 评论 -
数据导入导出
db2 connect to schemadb2 "export to tableName.ixf of ixf select * from schema.tableName"db2 "export to tableName.del of del select * from schema.tableName"db2 "load from tableName.ixf of ixf replace into schema.tableName"db2 "load from tableName...原创 2021-01-09 22:02:23 · 113 阅读 · 0 评论 -
增加字段
alter table tableName add column columns varchar(100);comment on column tableName.columns is "xxxcolumns"原创 2021-01-09 22:00:25 · 155 阅读 · 0 评论 -
修改表结构
alter table tableName alter column columns set data type varchar(50);原创 2021-01-09 21:58:19 · 88 阅读 · 0 评论 -
重组数据表
db2 connect to cbrcdb //连接数据库db2 reorg table table_name //重组对应的数据表原创 2020-02-19 16:43:45 · 438 阅读 · 0 评论