xykj-plus/xykj-admin-plus/script/sql/update/sqlserver/update_invoice_table.sql
2026-06-13 13:48:51 +08:00

41 lines
1.7 KiB
Transact-SQL

-- ----------------------------
-- 发票表结构更新脚本 (SQL Server)
-- 说明:此脚本用于为发票表添加发票号码、结算关联和税率字段
-- 请根据实际情况谨慎执行,建议先备份数据
-- ----------------------------
-- ----------------------------
-- 第一步:备份原有数据(可选,建议执行)
-- ----------------------------
-- select * into biz_invoice_backup from biz_invoice;
-- ----------------------------
-- 第二步:添加发票号码字段
-- ----------------------------
if not exists (select * from sys.columns where object_id = object_id('biz_invoice') and name = 'invoice_no')
begin
alter table biz_invoice add invoice_no varchar(100) null;
execute sp_addextendedproperty 'MS_Description', '发票号码', 'SCHEMA', 'dbo', 'TABLE', 'biz_invoice', 'COLUMN', 'invoice_no';
end
go
-- ----------------------------
-- 第三步:添加结算关联字段
-- ----------------------------
if not exists (select * from sys.columns where object_id = object_id('biz_invoice') and name = 'settlement_id')
begin
alter table biz_invoice add settlement_id bigint null;
execute sp_addextendedproperty 'MS_Description', '结算ID', 'SCHEMA', 'dbo', 'TABLE', 'biz_invoice', 'COLUMN', 'settlement_id';
end
go
-- ----------------------------
-- 第四步:添加税率字段
-- ----------------------------
if not exists (select * from sys.columns where object_id = object_id('biz_invoice') and name = 'tax_rate')
begin
alter table biz_invoice add tax_rate varchar(10) null;
execute sp_addextendedproperty 'MS_Description', '税率(1:6%+2% 2:10%+2% 3:13%+2%)', 'SCHEMA', 'dbo', 'TABLE', 'biz_invoice', 'COLUMN', 'tax_rate';
end
go