如何将值插入 Access 表的自动编号字段?
我正在使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
警告这是贫民窟。 (但我又认为只有一个自动编号字段的表也有点贫民窟,所以哦。)
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.自动编号字段具有这样的属性:当记录输入到表中时,它会相应地编号。它就像自动增量一样
The autonumber field has the property that it gets numbered accordingly as the records are entered into the table. its smthng like autoincrement