且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在SQL Express 2005 Server数据库表的int主键和varchar()类型字段中保留相同的数据.

更新时间:2023-02-08 15:46:31

似乎您正在跟踪插入表中的行数.以后是否删除它们都没关系.我认为您应该去审核表.每当发生插入/更新/删除时,触发器都可以更改此表.以后,您可以将其用于所需的任何报告工作.尽管正如人们所说的那样,触发器是邪恶的,但仍有一些方法可以做到这一点:

更改varchar列的数据类型.它应该是整数.并创建一个autoicnrement列.这应该达到目的.尽管您将必须检查行删除对增量值的影响.我相信它应该与Oracle中的序列相同,因此应该更改.
It seems you are keeping track of the number of rows that were inserted in the table. It does not matter whether they were deleted later on. I think you should be going for Audit tables. Whenever Insert/Update/Delete happens, a trigger can change this table. Later you can use this for any reporting job that you need. Although as people say that triggers are evil, there are to ways of doing this:

Change the datatype for the varchar column. It should be integer. And make a autoicnrement column. This should serve the purpose. Alhtough you will have to check the effect of row deletion on the incremental value. I believe it should be same as sequence in Oracle so it should change.