Oracle和SQL Server中的主键 [英] Primary Keys in Oracle and SQL Server

查看:82
本文介绍了Oracle和SQL Server中的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Oracle或SQL Server上使用ORM处理主键的最佳实践是什么?

What's the best practice for handling primary keys using an ORM over Oracle or SQL Server?

Oracle -我应该使用序列和触发器,还是让ORM处理?还是还有其他方法?

Oracle - Should I use a sequence and a trigger or let the ORM handle this? Or is there some other way ?

SQL Server -我应该使用标识符数据类型还是其他方式?

SQL Server - Should I use the identifier data type or somehow else ?

推荐答案

记住,数据库倾向于独立于前端应用程序,这是一个好主意.可以通过批处理,Web服务,与其他数据库的数据交换,甚至共享同一数据库的不同应用程序来插入记录.

It is a good idea to remember that databases tend to have a life independent from a front end application. Records can be inserted by batch processes, web services, data exchange with other databases, heck, even different applications sharing the same database.

因此,如果数据库表负责其自身的标识或至少具有该功能,则将很有用.例如,在Oracle中,BEFORE INSERT触发器可以检查是否已为其主键提供了值,如果没有,则生成其自己的值.

Consequently it is useful if a database table is in charge of its own identify, or at least has that capability. For instance, in Oracle a BEFORE INSERT trigger can check whether a value has been provided for its primary key, and if not generate its own.

Oracle和SQL Server都可以生成GUID,因此这不是将身份生成委托给客户端的充分理由.

Both Oracle and SQL Server can generate GUIDs, so that is not a sufficient reason for delegating identity generation to the client.

这篇关于Oracle和SQL Server中的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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