語法
-- 備份整個表和數據 select * into xxxx_20210528 from xxxx; --- 添加字段 -- 給某個表添加一個tinyint類型的字段,添加默認是為1 alter table [表名] add 字段名 tinyint default 1; -- 給某個表添加一個varchar類型的字段,長度是100, 默認為空(不是null)也可以是(default null) alter table t_zhsq_ks add is_ksa varchar(100) default '' -- 添加注釋 EXECUTE sp_addextendedproperty N'MS_Description','[這是注釋]',N'user',N'dbo',N'table',N'[表名]',N'column',N'[要添加的列]'; 注意:---- [xx] 括號也要更換
例子
-- 備份表 select * into t_zhsq_ks_20210528 from t_zhsq_ks; -- 添加字段 -- 增加數字字段,字節型,缺省值為0 alter table t_zhsq_ks add is_ks tinyint default 1; -- 添加注釋 EXECUTE sp_addextendedproperty N'MS_Description','承辦單位是否要在app端顯示 1--是,0--否',N'user',N'dbo',N'table',N't_zhsq_ks',N'column',N'is_ks';