Hello Sirs/Mams,A pleasant day to every one.I have the following tables and a sample dummy data (once again, we will assume that this is already stored):--------------------------------------------------------PERSON table:person_id first_name last_name1 PETER PARKER
--------------------------------------------------------STUDENT table:person_id student_number1 STUD-001
--------------------------------------------------------ADDRESS table:person_id address1 Daily Bugle, New York City
--------------------------------------------------------PHONE table:person_id landline1 123-45-67
The person_id in PERSON table is a primary key and the person_id in STUDENT,ADDRESS and PHONE are foreign keys respectively. I want to update/delete this record but instead of using person_id, my query will be student_number. I tried the following SQL but the query complains about something that is not update-able because the modification affects multiple base tables:ALTER PROCEDURE [dbo].[SP_UPDATE_STUDENT_RECORD] -- Add the parameters for the stored procedure here @idstudent AS NVARCHAR(20), @studfname AS NVARCHAR(50), @studmname AS NVARCHAR(50), @studlname AS NVARCHAR(50), @studaddress1 AS NVARCHAR(50), @studphone1 AS NVARCHAR(50) ASBEGIN SET NOCOUNT ON; WITH STUDENT_RECORD AS ( SELECT s.STUDENT_NUMBER AS ID, p.FIRST_NAME, p.MIDDLE_NAME, p.LAST_NAME, a.ADDRESS, c.LANDLINE FROM PERSON AS p, STUDENT AS s, ADDRESS AS a, PHONE AS c WHERE (p.PERSON_ID = s.PERSON_ID) AND (p.PERSON_ID = a.PERSON_ID) AND (p.PERSON_ID = c.PERSON_ID) ) UPDATE [STUDENT_RECORD] SET [FIRST_NAME] =@studfname, [MIDDLE_NAME] = @studmname, [LAST_NAME] = @studlname, [ADDRESS] = @studaddress1, [LANDLINE] =@studphone1 WHERE [ID] = @idstudent END
I hope someone could help me to revise my query. I know if this query will be change into something that is update-able, this will be the same stuff as deleting it.Thank you and more power.Warm regards,Mark Squall"Listen to advice and accept instruction, and in the end you will be wise." -Proverbs 19:20