简体   繁体   English

如何向系统间缓存数据库中的现有列添加自动增量(IDENTITY)

[英]How to add auto increment(IDENTITY) to existing column in intersystems cache database

In intersystems cache, I have an existing table with example data as below 在系统间缓存中,我有一个现有表,其示例数据如下

ID Name
1  Allen
2  Benny

I want to modify column ID so that it will be auto incremented. 我想修改列ID,以使其自动递增。 After adding this, if I insert charlie into the table then the id should be 3. 添加完之后,如果我将charlie插入表中,则id应该为3。

I think I have to use IDENTITY but not sure how to use it. 我认为我必须使用IDENTITY,但不确定如何使用它。 Thanks for your help 谢谢你的帮助

If you want to change default ID column to anything else, you can use any other Property of class, and Index by this property which marked as IdKey . 如果要将默认ID列更改为其他任何内容,则可以使用类的任何其他Property,并使用标记为IdKey的此属性进行索引。 But, you have to manage incrementing this property by yourself. 但是,您必须自行管理增加此属性。 And You can do it with InitialExpression for setting value for any new object even if it will not be saved, or in %OnBeforeSave method, which will be called just before saving object. 而且,即使不保存任何新对象,也可以使用InitialExpression设置它的值,也可以使用%OnBeforeSave方法在保存对象之前调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM