为什么不允许通过查询更改列,但服务器资源管理器可以轻松完成
我有一个问题,即当我尝试通过查询或直接修改数据类型来更改表的数据类型时,我经常收到一些错误,指出这是无法完成的。但是,就像我从 Visual Studio
在 server explorer
中打开同一个表并修改数据类型一样,它很容易完成,没有任何错误。
我尝试使用将某些表的主键
(它是某些表的外键
)从数据类型int
修改为varchar
Management Studio 它抛出了一些错误。
但是,当我通过 Visual Studio
中的Server explorer
完成同样的事情时,它只需一小部分即可完成。
谁能告诉我有什么区别
I am having a question i.e when i tried to alter a data type of a table by query or by modifying the data type directly i used to get some errors stating this can not be done. But where as if i open the same table in server explorer
from visual studio
and modify the data type it was easily done with out any errors.
I tried to modify the primary key
which is a foreign key
for some tables from data type int
to varchar
using Management Studio
it throw me some errors.
But the same thing when i done through Server explorer
from Visual Studio
it was done in a fraction.
Can any one tell what was the difference
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我想我遇到了这个问题(至少对于 sql server 2008):
工具->选项->设计器
。然后再试一次。
您可以在此处查看有关选中该选项时何时发生的详细信息。
I think I had this issue (at least with sql server 2008):
Tools->Options->Designers
.and try again.
You can see more info here about when it occurs if the option is checked.
在没有看到您的具体错误的情况下,我只能说 UI 所做的不仅仅是一个简单的命令。它有时会创建临时存储并根据需要复制数据,以使体验愉快。您应该使用 UI 中的脚本功能来捕获更改并查看它在做什么?
Without seeing your specific error, all I can say is that the UI does far more than a simple command. It sometimes creates temporary storage and the copies data as it needs to, to make the experience pleasant. You should use the scripting function in the UI to capture the change and see what it's doing?
它可以使用查询来完成,因为这正是 SQL Server 所做的。但是,该脚本比简单的 ALTER TABLE 语句要复杂得多;通常涉及创建具有更改的数据类型的临时表,从原始表复制数据,删除原始表,然后重命名临时表。
当在 SSMS 的设计视图中修改表的结构时,有一个选项可以生成更改的脚本,因此您可以在多个服务器等上运行它。这将向您显示实际发生的确切过程在幕后。
It can be done using a query, because that's exactly what SQL Server does. However, the script is considerably more complex than a simple
ALTER TABLE
statement; generally involving creating a temporary table with the changed datatype, copying the data from the original table, dropping the original table, then renaming the temporary table.When modifying the structure of a table in the Design view in SSMS there is an option to generate the script for the change(s), so you can run it on multiple servers, etc. This will show you the exact process that is actually happening behind the scenes.