0

我们通过索引碎片整理、重新索引或删除和重建索引来调整 SQL Server 数据库。Foxpro 有这样的数据调整技术吗?

谢谢,查克。

4

6 回答 6

2

要记住的另一件事是 FoxPro 数据库只是服务器上文件的集合。因此,诸如服务器磁盘碎片和确保从这些文件中排除防病毒之类的事情也会产生很大的不同。

于 2009-10-16T14:54:20.827 回答
2

用于对表进行碎片整理...

USE YourTable EXCLUSIVE
PACK

如果您的表有任何备注字段

PACK MEMO

如果表有索引,包会自动重新索引它们。

正如 Arnis 所提到的,VFP 中的大多数东西都是基于表格...表单、类、报告,尽管它们具有不同的扩展名。所以你可以做

use YourForm.scx exclusive
pack memo 

use YourClassLib.vcx exclusive
pack memo

use YourReport.frx exclusive
pack memo

use YourProject.pjx exclusive
pack memo

此外,如果对于您的常规 .dbf 表,您想杀死单个索引...

use YourTable exclusive
delete tag MyIndexTag

或者,删除所有索引

delete tag all
于 2009-10-16T14:14:32.743 回答
1

对于重新索引,您最好自己使用如下过程进行:REINDEX 有时无法修复索引损坏。

procedure reindextable

lparameters cTable
local cDBC, nTagCount, cTag, nTag
local array arrTags[1]

if pcount() = 0
    ? "No parameter"
    return -1
endif

close tables all

use (cTable) exclusive

? "Reindexing " + alltrim(alias())

nTagCount = tagcount()
if nTagCount = 0
    ? "No tags found"
    return -1
endif

dimension arrTags[nTagCount, 7]
for nTag = 1 to nTagCount
    arrTags[nTag, 1] = tag(nTag)
    arrTags[nTag, 2] = key(nTag)
    arrTags[nTag, 3] = for(nTag)
    arrTags[nTag, 4] = unique(nTag)
    arrTags[nTag, 5] = primary(nTag)
    arrTags[nTag, 6] = candidate(nTag)
    arrTags[nTag, 7] = descending(nTag)
endfor

* OK, we have the info to re-create the tags. Now delete the existing tags.

delete tag all

* Now re-create the tags
for nTag = 1 to nTagCount
    if arrTags[nTag, 5]
        * Primary key; need to use ALTER TABLE
        cTag = "ALTER TABLE " + cTable + " ADD PRIMARY KEY " + arrTags[nTag, 2]

        * Thanks to Anders Altberg for the info that you can add a filter to a PK, as long
        * as the TAG appears *after* the filter.
        if not empty (arrTags[nTag, 3])
            cTag = cTag + " FOR " + arrTags[nTag, 3]
        endif

        cTag = cTag + " TAG " + arrTags[nTag, 1]
    else
        * Regular index (or possibly a Candidate)
        cTag = "INDEX ON " + arrTags[nTag, 2] + " TAG " + arrTags[nTag, 1]
        if not empty (arrTags[nTag, 3])
            cTag = cTag + " FOR " + arrTags[nTag, 3]
        endif

        if arrTags[nTag, 4]
            cTag = cTag + " UNIQUE "
        endif

        if arrTags[nTag, 6]
            cTag = cTag + " CANDIDATE "
        endif

        if arrTags[nTag, 7]
            cTag = cTag + " DESC "
        endif

    endif

    * This will create the tag
    &cTag

    ? cTag


endfor

? "Success."

return 0
于 2009-10-17T18:18:38.703 回答
0

重新索引和打包表会有所帮助。甚至类库 (.vcx) 也是可以打包的表。但不幸的是,我不记得确切的命令。

于 2009-10-16T07:39:49.323 回答
0

如果您没有创建重新索引过程,请运行并获取 Stonefield Database Toolkit:

http://stonefield.com/sdt.aspx

它所做的其中一件事是构建有关索引的元数据。它有一个命令来重新索引所有表,或者一次一个表。您添加或删除索引,无需跟踪它或更改您的重新索引例程。验证元数据(内置功能),并将更新的元数据与您的 DBC 文件一起发送并更新。生产表(结构和索引)会更新以匹配您在开发中的内容。

大多数使用数据库包含 DBF 的 VFP 开发人员发现这个工具是必不可少的。

至于打包您的源代码(SCX、VCX、FRX、LBX、MNX、PJX),您所要做的就是在构建项目时进行 Rebuild All。VFP 将打包构建后的所有源代码。这将减少生成的可执行文件的大小,而不是优化或调整数据库。

瑞克

于 2009-11-05T17:33:01.007 回答
0

PACK 可能很危险 - 如果在命令期间发生某些事情(崩溃、断电等),则表可能已损坏。总是在打包表之前进行备份。

我们很少在我的办公室使用 PACK,因为我们很少删除临时表中的记录以外的任何内容——其他所有内容都保留用于历史目的。

不过,一定要每隔一段时间使用一次 REINDEX。

于 2009-11-06T03:03:03.623 回答