更改表中的列顺序时出现问题 (SQL Server 2008)

发布于 2024-07-22 20:28:49 字数 446 浏览 6 评论 0原文

当我尝试更改此列列表时:

Nombre
Imagen
Descripcion
Activo
IdLineaProducto

进入此(IdLineaProducto 是第一个)

IdLineaProducto
Nombre
Imagen
Descripcion
Activo

SQL Server Management Studio 表示不允许保存更改,因为必须删除并重新创建表(西班牙语...)。 我可以在 SQL Server 2005 中执行此操作,但不能在 SQL Server 2008 中执行此操作。

在其他情况下也会发生同样的情况,例如尝试将 int 非标识列转换为标识列。 为什么会出现这种情况呢? 我该如何解决这个问题? 也许是一些配置错误的问题? SQL Server 中的一些新功能?

When I try to change this columns list:

Nombre
Imagen
Descripcion
Activo
IdLineaProducto

into this (IdLineaProducto is first)

IdLineaProducto
Nombre
Imagen
Descripcion
Activo

SQL Server Management Studio says that it's not allowed to save changes because the table must be deleted and recreated (in spanish...). I could do this in SQL Server 2005, but not in SQL Server 2008.

The same happens in other situations, like trying to transform an int non-identity column to identity. Why happens this? How can I resolve this? Maybe some misconfigured issue? Some new feature in SQL Server?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妳是的陽光 2024-07-29 20:28:49

我找到了 此问题的解决方案

这是设计使然,可以很快
在 Management Studio 中通过以下方式修复
取消选中属性。 要修复此问题
Management Studio,转到“工具”->“
选项然后转到设计器页面
并取消选中“防止保存更改
需要重新创建表”。

请注意,它可能有 不良后果,例如丢失与此相关的其他表中的数据。

I found the solution to this problem.

This is by design and can be quickly
fixed in Management Studio by
unchecking a property. To fix this in
Management Studio, go to Tools ->
Options then go to the Designer Page
and uncheck "Prevent saving changes
that require table re-creation".

Beware that it may have undesired consequences, like losing data in other tables related to this.

日久见人心 2024-07-29 20:28:49

这就是它的工作方式...您只能将列添加到末尾,除非您DROP它并CREATE它(通常将数据复制出来并返回, IDE 可能会提供帮助)。 但是为什么你想改变顺序呢? 即使它不理想,您的 SELECT 等也可以处理这个...即

SELECT IdLineaProducto, Nombre, Imagen, Descripcion, Activo
FROM   TheTable
...

(仅使用 SELECT * 很少是一个好主意)


Re the 身份; 同样,这对于列来说是基础 - 尽管在这种情况下,您可以复制数据,DROP 列,然后将ADD 列重新添加为 IDENTITY< /code> (在右侧),然后将其复制回 - 但随后您会遇到 IDENTITY INSERTSEED 值的额外复杂情况(因此您不需要尝试获取现有身份值的重复项)。

That is just the way it works... you can only add columns to the end, unless you DROP it and CREATE it (normally copying the data out and back in, which the IDE might help with). But why do you want to change the order? Even if it isn't ideal, your SELECT etc can handle this... i.e.

SELECT IdLineaProducto, Nombre, Imagen, Descripcion, Activo
FROM   TheTable
...

(it is rarely a good idea to just use SELECT *)


Re the IDENTITY; again, this is fundamental to the column - although in this case you could copy the data out, DROP the column, and re-ADD the column as IDENTITY (on the right hand side), and copy it back in - but then you have extra complications with IDENTITY INSERT and the SEED value (so you don't try to get duplicates of existing identity values).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文