Hi,
We can not alter the index dependent columns: Try below code.
CREATE TABLE TEST_ALTER
(
ID INT , NAME NVARCHAR(500)
)
--
SELECT * FROM TEST_ALTER
-- ALTER A COLUMN
ALTER TABLE TEST_ALTER ALTER COLUMN NAME NVARCHAR(MAX) -- IT WILL ALTER A COLUMN FINE.
-- CREATE A CLUSTERED INDEX ON ID COLUMN
CREATE CLUSTERED INDEX INDEX_TEST_ALTER_ID ON TEST_ALTER(ID)
--DROP INDEX ID_TEST_ALTER_NAME ON TEST_ALTER
ALTER TABLE TEST_ALTER ALTER COLUMN ID NVARCHAR(MAX)
-- FOLLWOING IS THE ERROR MESSAGE
MSG 5074, LEVEL 16, STATE 1, LINE 1
THE INDEX 'INDEX_TEST_ALTER_ID' IS DEPENDENT ON COLUMN 'ID'.
MSG 4922, LEVEL 16, STATE 9, LINE 1
ALTER TABLE ALTER COLUMN ID FAILED BECAUSE ONE OR MORE OBJECTS ACCESS THIS COLUMN.
Thanks.
bala krishna
No comments:
Post a Comment