1.刪除主鍵
ALTER TABLE DGMOCPC DROP CONSTRAINT PK_DGMOCPC
2.更改數據類型ALTER TABLE DGMOCPC ALTER COLUMN PC001 varchar(20) NOT NULL;
ALTER TABLE DGMOCPC ALTER COLUMN PC003 varchar(10) NOT NULL;
ALTER TABLE DGMOCPC ALTER COLUMN PC005 nvarchar(30);
3.重新添加主鍵ALTER TABLE DGMOCPC ALTER COLUMN PC003 varchar(10) NOT NULL;
ALTER TABLE DGMOCPC ALTER COLUMN PC005 nvarchar(30);
ALTER TABLE DGMOCPC ADD CONSTRAINT PK_DGMOCPC PRIMARY KEY (PC001,PC002,PC003)
4.壓縮資料庫ALTER DATABASE DGON_TEST SET RECOVERY SIMPLE
DBCC SHRINKDATABASE(DGON_TEST, 10)
ALTER DATABASE DGON_TEST SET RECOVERY FULL
5.重新查看表所占用空間DBCC SHRINKDATABASE(DGON_TEST, 10)
ALTER DATABASE DGON_TEST SET RECOVERY FULL
exec sp_spaceused 'DGMOCPC'