2023-07-04|閱讀時間 ‧ 約 2 分鐘

MSSQL: 資料表異動-修改欄位定序

~~~ 從 Xuite 搬過來 ~~~
ALTER TABLE TableName ALTER COLUMN ColumnName 欄位類型及長度 COLLATE 定序格式;
-- sample
ALTER TABLE TBORG_AREA_MAPPING ALTER COLUMN TELLERID varchar(10) COLLATE Chinese_PRC_CS_AS;

★若欄位有被設成索引(index),需先將index移除重建
-- sample
ALTER TABLE TBAST_STK_LOG DROP CONSTRAINT PK_TBAST_STK_LOG;
DROP INDEX IDX_TBAST_STK_LOG_01 ON TBAST_STK_LOG;
ALTER TABLE TBAST_STK_LOG ALTER COLUMN MKT_CODE varchar(8) NOT NULL;
ALTER TABLE TBAST_STK_LOG ADD CONSTRAINT PK_TBAST_STK_LOG PRIMARY KEY (ORDERDT, ACCOUNT, STKID, TRANSACTIONID, MKT_CODE);
CREATE INDEX IDX_TBAST_STK_LOG_01 ON TBAST_STK_LOG(MKT_CODE, ORDERDT);
分享至
成為作者繼續創作的動力吧!
© 2024 vocus All rights reserved.