[問題記錄] Column does not have the same ANSI trimming semantics in tables

Msg 4952, Level 16, State 1, Line 48
ALTER TABLE SWITCH statement failed because column 'PlayerCode' does not have the same ANSI trimming semantics in tables 'Demo.dbo.Log_Import' and 'Demo.dbo.Log_archive'.

 

紀錄最近在做 partition table switch 遇到的一個問題

故事是這樣的

有一台主機已經建立相同 schema 的 Log_archive 以及 Log_Import

看似一切正常的情況下 要從 Log_Import 把 data switch 到  Log_archive

ALTER TABLE Log_Import SWITCH PARTITION 1 TO Log_archive PARTITION 1
GO

結果發生錯誤訊息如下

Msg 4952, Level 16, State 1, Line 48
ALTER TABLE SWITCH statement failed because column 'PlayerCode' does not have the same ANSI trimming semantics in tables 'Demo.dbo.Log_Import' and 'Demo.dbo.Log_archive'.

訊息明確 所以檢查一下 ANSI_PADDING 果不其然發現異常

執行語法把該欄位設成相同的 ANSI trimming semantics

ALTER TABLE Log_Import ALTER COLUMN PlayerCode varchar(50) NOT NULL
GO

又可以正常的使用 switch 功能了

小朋友千萬亂用 ANSI_PADDING 去陰別人喔~XD