开发者

SQL Server Compact alter column size with constraint?

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 in开发者_开发知识库dex.

Anyone has an idea what I should do? thank you Gibit


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜