Chinaunix首页 | 论坛 | 博客
  • 博客访问: 814525
  • 博文数量: 328
  • 博客积分: 7000
  • 博客等级: 少将
  • 技术积分: 3810
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-15 22:00
文章分类

全部博文(328)

文章存档

2009年(2)

2008年(84)

2007年(207)

2006年(35)

我的朋友

分类: Sybase

2007-01-29 18:54:27

1. 备份数据库

  为防止在数据库碎片整理过程中出现不可预见的问题,有必要先备份数据库。

2. 创建bcp out脚本并导出数据

  • 创建包含下列SQL语句的文件:
    cre_bcp_out.sql
    select “bcp” + name + “out ./” + name + “_out.txt -Udboname -Pdbopwd -Ssys_name -c”
    from sysobjects where type = ‘U’
    order by name
    go
  • isql -Udboname -Pdbopwd -Ssystemname < cre_bcp_out. sql > b_out
  • 编辑输出文件,去掉文件第一行和最后两行无关的字符:vi b_out
  • 执行脚本,将数据库的数据导出到文本文件:sh b_out

3. 创建truncate table脚本并截断数据库

  • 创建包含下列SQL语句的文件:
    cre_trunc_out.sql
    select “truncate table” + name from sysobjects where type = ‘U’
    order by name
    go
  • isql -Udboname -Pdbopwd -Ssystemname < cre_ trunc_out. sql > trunc_out. sql
  • 编辑输出文件,去掉文件第一行和最后两行无关的字符,并在最后一行加入 go构成完整的SQL语句:vi trunc_out
  • 执行以下语句,清空数据库的数据:
    isql -Udboname -Pdbopwd < trunc_out. sql

4. 创建bcp in脚本并导入数据

  • 创建包含下列SQL语句的文件:
    cre_bcp_in. sql
    select “bcp” + name + “in ./” + name + “_out.txt -Udboname -Pdbopwd -Ssys_name -c”from sysobjects where type = ‘U’
    order by name
    go
  • isql -Udboname -Pdbopwd -Ssystemname < cre_ bcp_in. sql > b_in
  • 编辑输出文件,去掉文件第一行和最后两行无关的字符:vi b_in
  • 从文本中导入数据:sh b_in

5. 更新数据库状态

  Sybase不自动维护索引的统计信息,当用truncate table截断数据库时,索引并没有改变,所以必须用update statistics来确保索引的统计信息对应当前表数据的统计。

  • 创建包含下列SQL语句的文件:
    cre_upd_st. sql
    select “update statistics” + name from sysobjects where type = “U” order by name
    go
  • isql -Udboname -Pdbopasswd -Ssystemname < cre_upd_st. sql > upd_st. sql
  • 编辑输出文件,去掉文件第一行和最后两行无关的字符,在最后一行加入 go构成完整的SQL语句:
    vi upd_st. sql
  • 更新数据库状态:
    isql -Udboname -Pdbopasswd -Ssystemname < upd_st. sql
    至此,基本上完成了数据库用户表的碎片整理工作。

阅读(1482) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~