create table 电费表
(用户编号 char(11) not null check (用户编号 like '[N][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'),
用户姓名 char(10) not null,
抄表年月 char(6) not null check (抄表年月 like '2[0-9][0-9][0-9]0[1-9]' or 抄表年月 like '2[0-9][0-9][0-9]1[0-2]'),
电表量程 decimal(9,1) ,
电表倍率 int not null default 1,
电表型号 char(10) default 'DD862',
上月读数 decimal(9,1) not null,
本月读数 decimal(9,1) not null default -1,
外加电量 decimal(9,0) not null default 0,
本月电量 decimal(9,0) default 0,
电价类型 tinyint not null default 1 check ([电价类型] >= 1 and [电价类型] <= 50),
本月电费 decimal(9,2) not null default 0.00,
类型1 tinyint default 0,
比例1 decimal(9,3) default 0.000,
电量1 decimal(9,0) default 0,
电费1 decimal(9,2) not null default 0.00,
类型2 tinyint default 0,
比例2 decimal(9,3) default 0.000,
电量2 decimal(9,0) default 0,
电费2 decimal(9,2) not null default 0.00,
类型3 tinyint default 0,
比例3 decimal(9,3) default 0.000,
电量3 decimal(9,0) default 0,
电费3 decimal(9,2) not null default 0.00,
primary key (用户编号,抄表年月)
)
go
insert into 电费表 (用户编号,用户姓名,抄表年月,电表量程,电表倍率,上月读数,本月读数,外加电量,电价类型,类型1,比例1)
values ('N3050110101','李红艳','200104',9999.9,1,9987,16,0,1,1,1.000)
insert into 电费表 (用户编号,用户姓名,抄表年月,电表量程,电表倍率,上月读数,本月读数,外加电量,电价类型,类型1,比例1,类型2,比例2)
values ('N3050110101','李红艳','200605',9999.9,1,567,567,40,1,1,0.500,2,0.500)
insert into 电费表 (用户编号,用户姓名,抄表年月,电表量程,电表倍率,上月读数,本月读数,外加电量,电价类型,类型1,比例1,类型2,比例2,类型3,比例3)
values ('N3050110102','黄宗树','200604',99999.9,10,15671,16123,-2,1,1,0.700,2,0.150,3,0.150)
insert into 电费表 (用户编号,用户姓名,抄表年月,电表量程,电表倍率,上月读数,本月读数,外加电量,电价类型,类型1,比例1)
values ('N3050110103','黄乐忠','200511',9999.9,100,9671,128,0,4,4,1.000)
insert into 电费表 (用户编号,用户姓名,抄表年月,电表量程,电表倍率,上月读数,本月读数,外加电量,电价类型,类型1,比例1)
values ('N3050110104','董瑞云','200511',9999.9,1,528,556,0,1,1,1.000)