create procedure USP_Insert_Update_emp(@IntId int ,@chvmobile (20),@Chvename varchar(20),@intOutparameter int)
as
begin
if (@IntId = 0) --Means user want to insert. /*
/* Then I check here that, if mobile already
exists then (In table id is auto generated) and
for inserting user will enter @IntId as 0 that
means he/she want to insert and now In table id is
autogenerated and name and mobile is inserted */
set @intOutparameter = -1 */
else /*If user enter @IntId as nonzero i.e. id which he/she want update.*/
update tblemp set name =@Chvename,
mobile = @chvmobile
where id = @IntId
end
Вот сейчас:
1
. если пользователь вставляет, например, значения «9975072314» и «rishi» вставляются в базу данных. Который является приемлемым.
2
. Если пользователь вводит значения с тем же номером мобильного телефона, он дает @intoutputparameter как -1, что является приемлемым.
3
. Сейчас в базе данных tablemps есть:
id name mobileNo
1 nn 123
2 cvb 1234
.
.
**.
10 Rishi 9975072314**
4
. Теперь пользователь обновляет Id = 2, что делает значения в таблице:
id name mobileNo
1 nn 123
2 cvb 9975072314 /* Updatable values which I don't want. */
.
.
**.
10 Rishi 9975072314**
Теперь, как можно избежать повторяющихся обновлений в таблице?