Can you use auto-increment in MySql with out it being the primary Key

后端 未结 6 1678
春和景丽
春和景丽 2021-01-03 08:52

I am using GUIDs as my primary key for all my other tables, but I have a requirement that needs to have an incrementing number. I tried to create a field in the table with

6条回答
  •  执念已碎
    2021-01-03 09:32

    If, for some reason, you can't change the identity column to be a primary key, what about manually generating the auto-increment via some kind of SEQUENCE table plus a trigger to query the SEQUENCE table and save the next value to use. Then assign the value to the destination table in the trigger. Same effect. The only question I would have is whether the auto-incremented value is going to make it back thru NHibernate without a re-select of the table.

提交回复
热议问题