saich

saich

  • NA
  • 37
  • 3.9k

stored procedure to update data in multiple tables

Dec 1 2016 1:20 PM
Hi,
I am new to sql. I am practicing on foreign key relationships by doing a small application. It have 3 tables. One table named stpersonal with cloumns as stID, stname, stdateofbirth, stgender. stID column is identity column and primary key column. As the student contain multiple fields in education, i used second table named steducation with fields stID, stcollege, stgradyear.
stID in steducation table has foreign key relation with stID in stpersonal table.
And third table staddress for student addresses with columns stID, stAddress.
stID in staddress table has foreign key relation with stID in stpersonal table.
I got the stored procedure to get all student details and delete and insert. But I a unable to figure out stored procedure for update. I tried the following method to create stored procedure
`create procedure stupdate
(
@ID int,
@stname nvarchar(50),
@stdateofbirth nvarchar(50),
@stgender nvarchar(50),
@stcollege nvarchar(50),
@stgradyear datetime,
@stAddress nvarchar(50)
)
as begin
update stpersonal
set
stname = @stname,
stdateofbirth = @stdateofbirth,
stgender = @stgender,
stcollege = @stcollege,
stgradyear = @stgradyear,
stAddress = @stAddress
where stpersonal.stID = @ID
end ` This is the code I tried. I tried to use joins, but nothing worked out. So i hope I could overcome this.
Thanks in advance

Answers (2)