我也遇到過,當我調試我的代碼,並與一個SQL Server存儲過程做了一個問題,我有UPDATE語句與FOREIGN KEY約束衝突 - 如何解決?
「UPDATE語句衝突與外鍵約束\」 FK_PATIENTS_DropdownCounty \」。該衝突發生於數據庫\「**** \」,表\「dbo.DropdownCounty \」,列「縣」
我使用DropdownCounty表填充一個下拉菜單,但是當我嘗試更新網頁它給了我上面的問題我已經嘗試過SQL本身的CASCADE選項
我使用的SQL Server存儲過程是低於
ALTER PROC [dbo].[PatientDetailsUpdate]
@PatientNumber INT,
@HospitalNumber NVARCHAR(50),
@HC_Number NCHAR(20),
@ID_Number_LegacyID NCHAR(20),
@ConsentToDatabase BIT,
@ConsentGivenDate DATETIME,
@Sex CHAR(6),
@Forename NVARCHAR(50),
@Surname NVARCHAR(50),
@MaidenName NCHAR(10),
@DateOfBirth DATETIME,
@Age NCHAR(10),
@AddressLine1 NVARCHAR(50),
@AddressLine2 NVARCHAR(50),
@AddressLine3_TownCity NVARCHAR(50),
@AddressLine4_Region NVARCHAR(50),
@County NCHAR(17),
@Country NCHAR(10),
@PostCode NVARCHAR(50),
@HomeTelNumber NVARCHAR(50),
@MobileTelNumber NVARCHAR(50),
@WorkTelNumber NVARCHAR(50),
@Email NVARCHAR(50),
@Notes NVARCHAR(MAX)
AS
BEGIN
UPDATE PATIENTS
SET HospitalNumber = ISNULL (@HospitalNumber, HospitalNumber),
HC_Number = ISNULL (@HC_Number, HC_Number),
ID_Number_LegacyID = ISNULL (@ID_Number_LegacyID, ID_Number_LegacyID),
ConsentToDatabase = ISNULL (@ConsentToDatabase, ConsentToDatabase),
ConsentGivenDate = ISNULL (@ConsentGivenDate, ConsentGivenDate),
Sex = ISNULL (@Sex, Sex),
Forename = ISNULL (@Forename, Forename),
Surname = ISNULL(@Surname, Surname),
MaidenName = ISNULL (@MaidenName, MaidenName),
DateOfBirth = ISNULL (@DateOfBirth, DateOfBirth),
Age = ISNULL (@Age,Age),
AddressLine1= ISNULL(@AddressLine1, AddressLine1),
AddressLine2= ISNULL(@AddressLine2, AddressLine2),
AddressLine3_TownCity = ISNULL(@AddressLine3_TownCity, AddressLine3_TownCity),
AddressLine4_Region = ISNULL(@AddressLine4_Region, AddressLine4_Region),
County = ISNULL(@County, County),
Country = ISNULL(@Country, Country),
PostCode = ISNULL(@PostCode, PostCode),
HomeTelNumber = ISNULL(@HomeTelNumber, HomeTelNumber),
MobileTelNumber = ISNULL(@MobileTelNumber, MobileTelNumber),
WorkTelNumber = ISNULL(@WorkTelNumber, WorkTelNumber),
Email = ISNULL(@Email, Email),
Notes = ISNULL(@Notes, Notes)
WHERE
PatientNumber = @PatientNumber
END
我需要使用LEFT JOIN的鏈接表?
由於提前,
我很抱歉,但我只新數據庫的東西 我已經包括了什麼DropdownCounty看起來像在表中的值
的我已經上傳的第二張圖片是爲了幫助您瞭解我在每次調用BtnUpdate時要撥打的電話號碼
它失敗的原因爲'@ Country'不會在您的FK表'DropdownCounty'存在的價值。那麼,@ @ Country'的值是多少?DropdownCounty表中的當前值是多少?可能是'@ Country'是空的(即空字符串和非空),並且你沒有在你的語句中檢查這個。 – Igor
如果知道UPDATE語句失敗時使用的確切值,這將非常有幫助。你能捕捉到嗎?運行時可能通過運行SQL Server Profiler? –
請檢查您的存儲過程中是否傳遞了'County'。無論你傳遞什麼聲音,它都需要存在於你的'DropdownCounty'''County' SQL表和列中,而不是。 – KSib