想象一下這樣的設置:如何處理可能是FK的數據庫記錄?
create table ObservationType
(
ObservationTypeId int primary key identity(1,1),
Name nvarchar(32) not null
)
create table Observation
(
ObservationId int primary key identity(1,1),
ObservationTypeId int foreign key references ObservationType(ObservationTypeId),
Title nvarchar(32) not null,
Description nvarchar(1024) not null,
StudentId int foreign key references Student(StudentId)
)
create table Student
(
foo bar
)
現在想象一下這個充滿數據的,它的正常工作。當用戶想要刪除觀察類型時,你如何處理?你會自動刪除任何具有特定類型的觀察結果嗎?
在現實世界中,你是如何處理這種情況的?
我通常會這樣做,添加一列以標記它是否是活動/非活動條目,這樣您就不必刪除數據 – Brett 2011-05-21 18:46:05