“每个表只能有一个IDENTITY列” - 为什么 [英] "There can only be one IDENTITY column per table" - Why?

查看:676
本文介绍了“每个表只能有一个IDENTITY列” - 为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每个表只能有一个IDENTITY列

为什么会这样?拍摄车辆的场景,存在一个独特的chasis号码以及证明是唯一的注册号码。为了在 sql server 中描述这种情况,我们需要对列的自定义实现。相反,在 Oracle 中,您可以在表上具有所需的序列数量。为什么IDENTITY列有限制,具体原因?

Why is it so? Take a scenario of a vehicle, there exists a chasis number which is unique as well as the registration number which turns out to be unique. To depict this scenario in sql server we need a custom implementation for on of the columns. Conversely, in Oracle you can have as many sequences as you want on a table. Why is there a restriction on the IDENTITY Column, any specific reasons?

拥有车辆模式的场景是一个虚构的问题,我质疑为什么有一个限制标识列。

The scenario of having a vehicle schema is something imaginary am questioning myself as to why there's a restriction on the identity column.

推荐答案

SQL Server中的标识列具有种子和自动增量。如果我们知道第一个id列的值,我们总是可以计算出第二个假设id值应该是什么。

An Identity Column in SQL Server has a seed and an auto increment. We could always calculate what the 2nd hypothetical id value should be if we knew the value of the first id column anyway.

如果这是合法的语法

create table #foo
(
bar int identity(1,10),
baz int identity(1000,1)
)

需要存储baz,因为它可以从bar计算如下。

We wouldn't need to store baz as it could be calculated from bar as follows.

baz = 1000 + (bar-1)/10

这篇关于“每个表只能有一个IDENTITY列” - 为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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