0

I don't know how to phrase this question, but I'm trying to do this:

alter table [TEMP]
add SEQID int identity(1,1)

This works; however, what I really need is a float column instead of an int:

alter table [TEMP]
add SEQID **FLOAT** identity(1,1)

I think this is illegal. Please let me know if it is not. Is there a work around to getting a float ID column?

Edit: Is there a way to create the identity column as int, then remove the identity attribute, and then convert the column to a float?

4

2 回答 2

3

你可以做你想做的事:

create table temp (
    id int identity(1,1),
    fid as cast(id as float)
)

这会将 id 添加为整数,但随后会有另一列通过将其转换为浮点数来计算。

为什么要为遗留系统创建新的 ID?

或者,您可以将计算列添加到现有表中:

alter table temp add fid as cast(id as float)
于 2012-05-31T21:41:57.623 回答
-1

我不知道我是否理解你为什么想要一个浮点 ID。该列通常仅存储为 int(bigint、smallint,取决于表...),但 int 将充分唯一地标识表的每一行,以允许您在不污染数据的情况下查询每一行。您只需要确保正确加入表格即可。

如果您真的确定要使用浮点数,那么我认为这就足够了,除非我遗漏了一些东西:

alter table [TEMP]
add SEQID float identity(1,1)
于 2012-05-31T21:43:59.717 回答