如何将值插入 Access 表的自动编号字段?

发布于 2024-12-01 06:32:39 字数 219 浏览 9 评论 0原文

我正在使用 jsp 和 Microsoft Access 开发一个项目。

有三个表,其中相同的字段用作 Receipt_No
这可以从 Recp 表中获取,该表只有一个字段:Receipt_No (AutoNumber, Primary Key)

现在我的问题是,如何在每一代收据中插入此自动编号字段?

I'm working on a project using jsp and Microsoft Access.

There are three tables in which a same field is used as Receipt_No.
This can get from Recp table, which has a only one field: Receipt_No (AutoNumber, Primary Key).

Now my question is, how can I insert in this AutoNumber field with every generation of receipt?.

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

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

发布评论

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

评论(2

撑一把青伞 2024-12-08 06:32:39

警告这是贫民窟。 (但我又认为只有一个自动编号字段的表也有点贫民窟,所以哦。)

INSERT INTO yourTable (your_autonumber_field) SELECT max(your_autonumber_field) + 1 FROM yourTable

不优雅,但它有效。这将在您的收据表中创建一条新记录。它违背了拥有自动编号字段的全部目的,但我没有看到另一种使用 SQL 在仅具有自动编号字段的表中创建记录的方法。然后,您可以使用 SELECT max(your_autonumber_field) FROM yourTable 检索新创建的收据 ID,以便在其他表中的 FK 字段中使用。

WARNING This is ghetto. (But then again I'm thinking a table with ONLY an autonumber field is kinda ghetto too, so oh well.)

INSERT INTO yourTable (your_autonumber_field) SELECT max(your_autonumber_field) + 1 FROM yourTable

Not elegant, but it works. That will create a new record in your Receipt table. It defeats the whole purpose of having an autonumber field but I don't see another way to use SQL to create a record in a table with only an autonumber field. You can then retrieve the newly created receipt ID with a SELECT max(your_autonumber_field) FROM yourTable for use in your FK fields in the other tables.

ˉ厌 2024-12-08 06:32:39

自动编号字段具有这样的属性:当记录输入到表中时,它会相应地编号。它就像自动增量一样

The autonumber field has the property that it gets numbered accordingly as the records are entered into the table. its smthng like autoincrement

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