DB2初学者学习

我是一名新学习DB2的学员,本文档供初学者借鉴!

 

1.下载地址:(我是在一个博客上看到的,很详细,直接提供他博客地址)

http://happyqing.iteye.com/blog/2082305

(备注:windows10不适用这个链接下的版本!)

 

2.安装完成,打开方式

window+R(运行)输入db2cc 或者 db2cmd就可以db2的控制中心

 

3.写SQL语句

选择数据库-右键-查询:弹出【命令编辑器的窗口】,在这个窗口你可以写sql语句命令

下面直接用例子操作,以便于更加明白

a.创建tstudent学生表并实现id自增

create table tstudent(
    id numeric not null primary key
      generated always as identity(start with 1 increment by 1 minvalue 1 maxvalue 9999 no cycle cache 20 no order) ,
    name varchar(30) ,
    sex varchar(10),
    classcode varchar(30)
);

 

b.为字段添加注释

comment on table tstudent is   '测试学生表';
comment on column tstudent.id is '学生编号';

comment on column tstudent.name is'学生姓名';

 

c.增加一列
alter table tstudent  add column hobby varchar(200);

alter table tstudent add column birthdate date;

 

d.建立索引

create index l_TSTUDENT_CLASSCODE on tstudent(classcode);

 

e.插入数据

insert into tstudent(name,sex,classcode,hobby) values('小明','男','C131','唱歌,游泳');
insert into tstudent(name,sex,classcode,hobby) values('小张','男','C132','读书,听音乐');

 

f.修改数据

update tstudent set sex='女' where name='小张';

 

g.删除数据

1).delete from tstudent;

2).alter table tstudent activate not logged initially with empty table;(删除不记录日志)

3)drop table tstudent;(把数据删了连同表结构一起删除)

 

h.分页查询

select * from (
select row_number() over (order by id asc ) as row_number ,t.* from   tstudent  t  )  a

  where a.row_number > 10

  fetch first 10 rows only

(备注:第一页,row_number>0每页查询10条记录,第二页,row_number>10 以此类推)

 

 

 

 

 

 

 

 

 

 

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值