Can any one help me to update the primary key using stored procedure as I'm having an error
but when I tried to update the record using a condition it work, (LaptopID is the primary key).
But when I try to update the primary key with the second code it doesn't work as the condition (Where LaptopID=@LaptopID) will be changed, and I don't want to make another stored procedure with another condition when I update the record with the primary key.
the code I used to update the stored procedure is:
ALTER PROCEDURE Update_Data_SP
(
@LaptopID varchar(50),@StudentID varchar(50),@Manufacturer varchar(50),@Model varchar(50),@AcquistionYear varchar(50),@History nvarchar(MAX),
@Comments nvarchar(MAX)
)
AS
Update Laptops_Table set LaptopID=@LaptopID, StudentID=@StudentID, Manufacturer=@Manufacturer,
Model=@Model, AcquistionYear=@AcquistionYear, History=@History, Comments=@Comments
When I used a condition worked:
ALTER PROCEDURE Update_Data_SP
(
@LaptopID varchar(50),@StudentID varchar(50),@Manufacturer varchar(50),@Model varchar(50),@AcquistionYear varchar(50),@History nvarchar(MAX),
@Comments nvarchar(MAX)
)
AS
Update Laptops_Table set LaptopID=@LaptopID, StudentID=@StudentID, Manufacturer=@Manufacturer,
Model=@Model, AcquistionYear=@AcquistionYear, History=@History, Comments=@Comments WHERE LaptopID=@LaptopID
The thing is I want to update even the primary key which will not work because if I changed the the primary key the condition (Where LaptopID=@LaptopID) will not be valid.
Any suggestion or idea if there is any way I can update the record including the primary key in one stored procedure???
Loading

Mahmoud AlyanPosted Feb 26, 2011, 10:50 PM
Syed ShakeerPosted Feb 25, 2011, 9:53 AM
The updating laptopId might be having in a table.so it is rasing error.
eg:
LaptoId
------
1
2
3
4
Update laptopTable set laptopid=2 where laptopId=1
It raise error.bcz already there is a laptoid 2 in a table.Hope you had understand it.
Note:-Primary key column cannot allow multiple or duplicate data.
Suthish NairPosted Feb 19, 2011, 12:19 PM
What is a Primary Key?
Primary Key of a table uniquely identifies each record in a table.
If want to select/update/delete a particular row using Primary Key then,
select * from Laptops_Table where LaptopID = 1;
update Laptops_Table set Manufacturer=@Manufacturer where LaptopID = 1;
delete from Laptops_Table where LaptopID = 1;