DB:要使用标识列吗? [英] DB: To use identity column or not?

查看:125
本文介绍了DB:要使用标识列吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在设计表时,我的同事在这里说,我应该避免标识列,因为它是特定于SQL Server和MS Access,但我不同的是他的意见,因为它使我的编码更简单。

While designing a table my colleague here says that I should avoid identity column as it is specific to SQL Server and MS Access, But I differ with his views as it makes my coding simpler.

我应该使用标识列吗?如果不是从应用程序代码创建标识列的最佳方法是什么?

Should I use identity column or not? If not what is best way to create the identity columns from application code?

推荐答案

数据库供应商。如果你这样做,你将无法利用数据库提供的任何功能。

You can't completely divorce an application from the database vendor. If you do you won't be able to take advantages of whatever features your database provides you.

我想说使用标识列。如果转移到Oracle(例如),您可以使用序列。非常大的变化。

I'd say use the identity column. If you move over to Oracle (for example), you can use a Sequence. Hardly a big change.

我不知道你使用什么技术,但有一点可以帮助使用一个工具,如Hibernate或iBATIS(我认为它们都可用于Java和.NET),它将您从数据库实现细节中分离出来。然后,如果您更改数据库供应商,您将不需要更改应用程序代码,只需配置。 (理论上,至少!)

I don't know what technology you're using, but one thing that would help is using a tool such as Hibernate or iBATIS (I think they're both available for Java and .NET) which separates you a bit from the database implementation details. Then if you change database vendor you won't need to change application code, just configuration. (In theory, at least!)

这篇关于DB:要使用标识列吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆