Customized Auto-Number IDs for tables?

泪湿孤枕 提交于 2019-11-28 06:00:53

问题


Is there a way to use my own number in a table like an auto-number; that is to automatically assign the next available to a new record. We have system ID numbers for each employee that I want to tie into this database. I just want the table to auto assign the next number.

Can I do this?
Could this be done with a mixture of numeric and alpha?
Could criteria be used, like Code A = certain set of numbers, Code B = another?


回答1:


Of course you can, but you will have to design this yourself.

There are hundreds of ways of doing this but one way might be that you may have a parameters table with "nextQuote", "nextEmployeeNo", "nextJob"... of course your table design could have anything, including prefix example;

PARAMETERS
Prefix    Number
Q          1145
E            54
J           999

So now you can SELECT PreFix + MAX(Number) AS NextEmployee FROM Parameters WHERE Prefix = E

And in your code you can increment the number after dealing with it.

UPDATE Parameters SET Number = number + 1 WHERE Prefix = E 

If this isn't up to the job then hopefully it will get you thinking in how you can do something similar.

Hope this helps.




回答2:


For ADO users:

How To Implement Multiuser Custom Counters in Jet 4.0

For DAO users:

How To Implement Multi-user Custom Counters in DAO 3.5



来源:https://stackoverflow.com/questions/1900452/customized-auto-number-ids-for-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!