SQL Server Compact 是否可以通过约束更改列大小?
我正在尝试修改表中列的大小,但是该列是主键列,并且在其他表中使用(也需要修改其大小)
我有一个名为 table1 的表,其中有一个名为 column1 的列作为主键 我还有 table2、table3 和 table4,分别有 table2column1、table3column1 和 table4column1。 table2column1、table3column1 和 table4column1 是外键(从 table1 引用 column1),它们也用作各自表中的复合主键。
我尝试这样做来改变列的大小
ALTER TABLE UtilisateurNotes ALTER COLUMN IDNotes nvarchar(250)
但没有成功。
这是错误消息:无法更改属于键或索引一部分的列。
有人知道我应该做什么吗?谢谢吉比特
I am trying to modify the size of a column in a table, however that column is a primary key column and is used in other table ( which would need to have its size modified too)
I have a table called table1 with a column named column1 as primary key
I also have table2,table3 and table4 that has table2column1, table3column1 and table4column1 respectively.
table2column1,table3column1 and table4column1 are foreign keys ( reference column1 from table1) and they are also used as a composite primary key in their respective table.
I tried doing this to alter the size of the column
ALTER TABLE UtilisateurNotes ALTER COLUMN IDNotes nvarchar(250)
It did not work.
This is the error message : Cannot alter a column that is part of a key or an index.
Anyone has an idea what I should do? thank you Gibit
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须删除外键和主键索引才能修改列,然后重建它们。
如果您在 SQL Server Management Studio 中并使用对象资源管理器,则可以右键单击错误消息中指定的特定主键或外键,然后使用脚本作为 > CREATE AND DROP 可帮助您生成更新所需的脚本。
You have to drop the foreign keys and primary key index in order to modify the column and then rebuild them after.
If you're in SQL Server Management Studio and you use the Object Explorer then you can right click on the specific Primary Key or Foreign Key specified in the error message and use Script as > CREATE AND DROP to help you generate the necessary scripts for the update.