Solved

In SQL how do I delete records from two tables?

Posted on 2009-07-02
3
154 Views
Last Modified: 2012-05-07
I have the attached table structure within my sql server 2005 database. I have written the attached stored procedure hoping it would allow me to delete records within my ApplicantInterviews table but I get an error on my foreign key value constraint (InterviewID) due to items being under this key. How can I alter my stored procedure to delete the interview in my ApplicantInterviews table aswell as the interviewers that come under that interview (InterviewID) in my ApplicantInterviewInterviewers table??

Thanks.
ALTER PROCEDURE [Applicant].[proc_DeleteApplicantInterview]
	
	@InterviewID int,
	@InterviewInterviewerID int
	
AS
	DELETE FROM Applicant.ApplicantInterviews
	WHERE InterviewID = @InterviewID
	
RETURN

Open in new window

database.jpg
0
Comment
Question by:Shepwedd
  • 2
3 Comments
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 500 total points
ID: 24764784


ALTER PROCEDURE [Applicant].[proc_DeleteApplicantInterview]
     
      @InterviewID int,
      @InterviewInterviewerID int
     
AS
      SET NOCOUNT ON
      DELETE FROM Applicant.ApplicantInterviewInterviewers
      WHERE InterviewID = @InterviewID

      DELETE FROM Applicant.ApplicantInterviews
      WHERE InterviewID = @InterviewID
     
RETURN
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 24764792
Dont you want to maintain a History of this information before deleting this ?
0
 

Author Comment

by:Shepwedd
ID: 24764921
That worked! Thanks.

I would like to maintain a history but I'm hoping my users will only use the delete if they had entered incorrect data.
0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Recently, when I was asked to create a new SQL 2005 cluster, Microsoft released a new service pack for MS SQL 2005 what is Service Pack 3. When I finished the installation of MS SQL 2005 I found myself troubled why the installation of SP3 failed …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question