主题:SQLserver2005数据库存储过程用户代码可以重复修改问题
我想让user_code,和 meter_num 他们组成的信息不能重复,也就是user_code和meter_num所对应的数据可以重复,但是他们两个不能同时对应:例如 user_code 对应的 123456 meter_num 对应的数为 65887 这条信息不能重复,就是user_code 对应的 123456 能和meter_num所对应其他数据组成其他信息
下面存储过程怎么改啊?
ALTER PROCEDURE [dbo].[create_newuser_new_meter_pro]
@user_code char(12),@user_china_name char(20),@user_address varchar(100),@user_iden_num char(18),@user_tele char(20),@area_code int,
@addr_code int,@build_code int,@door_num int,@user_state char(4),
@meter_num char(10),@meter_type int,@price_code int,@diploid bigint,@alarm_min decimal(18,2),@alarm_max decimal(18,2),@meter_max decimal(18,2),@pur_max decimal(18,2),
@over_zero_pow decimal(18,2),@pow_limit bigint,@user_type tinyint,@pre_pow decimal(18,2),
@Rst int output
AS
set nocount on
declare @@price_adjust_count int
set @@price_adjust_count=(select max(price_adjust_count) from price_info where price_code=@price_code and is_active='活动')
begin tran
insert into user_info(user_code,user_china_name,user_address,user_iden_num,user_tele,area_code,addr_code,build_code,door_num,pur_count,pur_money,user_state,user_type) values(@user_code,@user_china_name,@user_address,@user_iden_num,@user_tele,@area_code,@addr_code,@build_code,@door_num,0,0,@user_state,@user_type)
/*新 修改 */
if @@error<>0
begin
rollback tran
set @Rst=0
goto err_out
end
/*新 修改 */
insert into user_meter_info values(@user_code,@meter_num,@user_state,1,@meter_type,@price_code,@@price_adjust_count,@diploid,0,0,0,0,0,1,@alarm_min,@alarm_max,@meter_max,@over_zero_pow,@pow_limit,@pur_max,@pre_pow,getdate(),null,@user_code,null,null);
commit tran
if @@error<>0
begin
rollback tran
set @Rst=0
end
set @Rst=1
err_out:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
/****** Object: Stored Procedure dbo.create_newuser_meter_pro Script Date: 2007-11-9 09:52:38 ******/
/****** Object: Stored Procedure dbo.create_newuser_meter_pro Script Date: 2007-10-13 13:24:53 ******/
/*说明:
新建用户的新的电表信息,用于换表,新建用户的电表
*/
ALTER PROCEDURE [dbo].[create_newuser_meter_pro]
@user_code char(12),@new_meter_num char(10),@old_meter_num char(10),@meter_type int,@price_code int,@price_adjust_count int,@diploid bigint,@alarm_min decimal(18,2),@alarm_max decimal(18,2),@meter_max decimal(18,2),@pur_max decimal(18,2),
@workid bigint,@oper_power decimal(18,2),@oper_date datetime,@old_diploid bigint,@change_reason varchar(50),@Rst int output
AS
set nocount on
begin tran
declare @@meter_index int
set @@meter_index=(select max(user_index) from user_meter_info where user_code=@user_code )
set @@meter_index=@@meter_index+1
update user_meter_info set in_use='未用' where user_code=@user_code and in_use='使用' and meter_num=@old_meter_num
/* 实际的换 表程序此处需要修改*/
insert user_meter_info values(@user_code,@new_meter_num,'换表',@@meter_index,@meter_type,@price_code,@price_adjust_count,@diploid,0,0,0,0,0,1,@alarm_min,@alarm_max ,@meter_max ,0,0,0,@pur_max,getdate(),null,null,null,null)
insert meter_change_info values(@workid,@user_code,@old_meter_num,@new_meter_num,@oper_power,@oper_date,@old_diploid,@diploid,@change_reason)
commit tran
if @@error<>0
begin
rollback tran
set @Rst=0
end
set @Rst=1
下面存储过程怎么改啊?
ALTER PROCEDURE [dbo].[create_newuser_new_meter_pro]
@user_code char(12),@user_china_name char(20),@user_address varchar(100),@user_iden_num char(18),@user_tele char(20),@area_code int,
@addr_code int,@build_code int,@door_num int,@user_state char(4),
@meter_num char(10),@meter_type int,@price_code int,@diploid bigint,@alarm_min decimal(18,2),@alarm_max decimal(18,2),@meter_max decimal(18,2),@pur_max decimal(18,2),
@over_zero_pow decimal(18,2),@pow_limit bigint,@user_type tinyint,@pre_pow decimal(18,2),
@Rst int output
AS
set nocount on
declare @@price_adjust_count int
set @@price_adjust_count=(select max(price_adjust_count) from price_info where price_code=@price_code and is_active='活动')
begin tran
insert into user_info(user_code,user_china_name,user_address,user_iden_num,user_tele,area_code,addr_code,build_code,door_num,pur_count,pur_money,user_state,user_type) values(@user_code,@user_china_name,@user_address,@user_iden_num,@user_tele,@area_code,@addr_code,@build_code,@door_num,0,0,@user_state,@user_type)
/*新 修改 */
if @@error<>0
begin
rollback tran
set @Rst=0
goto err_out
end
/*新 修改 */
insert into user_meter_info values(@user_code,@meter_num,@user_state,1,@meter_type,@price_code,@@price_adjust_count,@diploid,0,0,0,0,0,1,@alarm_min,@alarm_max,@meter_max,@over_zero_pow,@pow_limit,@pur_max,@pre_pow,getdate(),null,@user_code,null,null);
commit tran
if @@error<>0
begin
rollback tran
set @Rst=0
end
set @Rst=1
err_out:
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
/****** Object: Stored Procedure dbo.create_newuser_meter_pro Script Date: 2007-11-9 09:52:38 ******/
/****** Object: Stored Procedure dbo.create_newuser_meter_pro Script Date: 2007-10-13 13:24:53 ******/
/*说明:
新建用户的新的电表信息,用于换表,新建用户的电表
*/
ALTER PROCEDURE [dbo].[create_newuser_meter_pro]
@user_code char(12),@new_meter_num char(10),@old_meter_num char(10),@meter_type int,@price_code int,@price_adjust_count int,@diploid bigint,@alarm_min decimal(18,2),@alarm_max decimal(18,2),@meter_max decimal(18,2),@pur_max decimal(18,2),
@workid bigint,@oper_power decimal(18,2),@oper_date datetime,@old_diploid bigint,@change_reason varchar(50),@Rst int output
AS
set nocount on
begin tran
declare @@meter_index int
set @@meter_index=(select max(user_index) from user_meter_info where user_code=@user_code )
set @@meter_index=@@meter_index+1
update user_meter_info set in_use='未用' where user_code=@user_code and in_use='使用' and meter_num=@old_meter_num
/* 实际的换 表程序此处需要修改*/
insert user_meter_info values(@user_code,@new_meter_num,'换表',@@meter_index,@meter_type,@price_code,@price_adjust_count,@diploid,0,0,0,0,0,1,@alarm_min,@alarm_max ,@meter_max ,0,0,0,@pur_max,getdate(),null,null,null,null)
insert meter_change_info values(@workid,@user_code,@old_meter_num,@new_meter_num,@oper_power,@oper_date,@old_diploid,@diploid,@change_reason)
commit tran
if @@error<>0
begin
rollback tran
set @Rst=0
end
set @Rst=1