我有这个表Sql
和插入Form
重复更新我阻止用户进入同一HDate为同一HNumber如何防止SQL存储过程
RecID HDate HNumber HComb
----------------------------------------------
1 2017-1-30 1 12
3 2017-1-29 1 15
5 2017-1-30 2 12
6 2017-1-30 3 12
9 2017-1-30 4 12
但在编辑表单我不”知道如何防止这种情况,
我尝试在存储过程的代码,但它的一些HNumber工作,但它防止一些其他HNumber在它自己的日期进行编辑
Create Procedure UpdCombHarByRecID
@RecID int,
@HarvestDate Date,
@HiveNumber int,
@HoneyComb Float,
as
if NOT Exists (Select * From tHoneyHarvest Where [email protected])
return 0
//there is no record to be updated
if Exists (Select * From tHoneyHarvest Where [email protected] AND
HiveNumber=HiveNumber And
[email protected])
// I hoped this should do the job
//(RecID is PrimaryKey and it is identity)
return 2
Update tHoneyHarvest
Set [email protected],
[email protected],
[email protected],
[email protected]
Where [email protected]
return 1
现在问题在哪里?
使用*单* UPDATE ... FROM ... WHERE语句,它的'WHERE'条款消除重复。多个'Exists'语句使得代码更难阅读和理解。 –
@PanagiotisKanavos用户无法更改HNumber,但可以编辑HDate,我想检查HNumber是否已在新编辑的HDate中有记录,以防止更新任何字段并且什么都不做 – SaraniO
HiveNumber = HiveNumber将始终为真。应该是HiveNumber = @ HiveNumber? – Vijay