I have to copy data for one student (clone student) that encompass three tables:
- tblStudent (where PK is studentId)
- tblStudentSubjects (where PK is StudentsubjectId and FK is StudentId)
- tblStudentSubjectComments (where PK doesn't exist and FK is StudentSubjectId)
To accomplish this I would have to
- Create Student record by coping existing student record and obtain new studentid
- create student subject record for each existing student subject using new studentid and obtain new StudentSubjectId
- create student subject comment record for each existing student subject comment using new studentSubjectId
... hope you got idea
So, is there a elegant way to accomplish this using CTE in one Store Procedure? (I'm using SQL Server 2005)