Foxpro中如何自动增加一个字段

发布于 2025-01-02 21:51:01 字数 373 浏览 2 评论 0原文

我正在使用 vfp9,但该程序可能是用更早的语言编写的。 当我通过 vfp 打开数据库时,该字段是只读的,与其他字段不同。 手动执行此操作(选择 max + 1)对插入不起作用,它只会使字段 = 0。

我在网上查找正确语法的示例时遇到困难,有人可以帮忙吗?

编辑: 好的,解决方案是将字段留空。该字段位于一个表中,该表最终会附加到一个更大的表(带有自动编号字段的表)。不过,在附加之前,该字段已用于多次搜索。

我不想通过简单地在附加之前将字段设置为 null 来修复所有代码。但是,将字段替换为 null 会出现错误。 将表字段设置为空的正确语法是什么?

再次编辑:删除列有效。显然你不能将数字字段设置为空。

I'm using vfp9 but the program may have been written in an earlier language.
When i open up the database through vfp, the field is read only, unlike the other fields.
Doing it manually (select max + 1) doesn't work on the insert, it just makes the field = 0.

I'm having trouble finding examples online for the proper syntax, can anyone help?

Edit:
OK, the solution was to leave the field blank. The field is in a table that is eventually appended to a larger table (the one with an autonumber field). Before it's appended, the field is used in several seeks, though.

I'd prefer not to fix the code everywhere by simply setting the field to null before the append. replace field with null gives an error though. What's the proper syntax for setting a table field to null?

Edit again: dropping the column worked. Apparently you can't set a number field to null.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

两人的回忆 2025-01-09 21:51:01

如果您的表结构如下:

Structure for table:    D:\SO9162291.DBF
Number of data records: 2       
Date of last update:    02/06/12
Code Page:              1252    
Field  Field Name      Type                Width    Dec   Index   Collate Nulls
    1  COUNT           Integer                 4                            Yes
    2  CONTENTS        Character              24                             No
** Total **                                   30

count字段设置为允许为空,那么您可以使用以下任意一种方法将整数类型的字段设置为空值。

USE so9162291
INSERT INTO so9162291 (count, contents) VALUES (null, "Test record")
UPDATE so9162291 set count = null WHERE contents = "Test record"
REPLACE count WITH null

If your table structure is as follows:

Structure for table:    D:\SO9162291.DBF
Number of data records: 2       
Date of last update:    02/06/12
Code Page:              1252    
Field  Field Name      Type                Width    Dec   Index   Collate Nulls
    1  COUNT           Integer                 4                            Yes
    2  CONTENTS        Character              24                             No
** Total **                                   30

The count field is set to allow nulls, so you can set a field of type integer to a null value using any of the following methods.

USE so9162291
INSERT INTO so9162291 (count, contents) VALUES (null, "Test record")
UPDATE so9162291 set count = null WHERE contents = "Test record"
REPLACE count WITH null
不知所踪 2025-01-09 21:51:01

我将执行以下 SQL 查询:

SELECT MAX(id)+1 AS laCount FROM so9162291 INTO CURSOR temp

INSERT INTO so9162291 (count, contents) VALUES(temp.laCount,"Test record")

I would perform the following SQL queries:

SELECT MAX(id)+1 AS laCount FROM so9162291 INTO CURSOR temp

INSERT INTO so9162291 (count, contents) VALUES(temp.laCount,"Test record")
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文