Foreign key declaration can be replaced by its equivalent check constraint True or False?

StackOverflow https://stackoverflow.com/questions/22115371

  •  18-10-2022
  •  | 
  •  

문제

I wanna know that a foreign key declaration can be replaced by its equivalent check constraint.. If yes why? I tried to google it but couldn't find the answer Word of advice please...

도움이 되었습니까?

해결책 2

Yes you can replace foreign key with check constraint but remember to use Enums

다른 팁

It depends on what you mean by replaced.

At the conceptual level, you can consider a foreign key constraint to be roughly a set of valid values. And, at the conceptual level, you can consider an equivalent check constraint to be roughly a set of valid values.

If that's all you mean by replaced, then you can replace a foreign key constraint with an equivalent check constraint.

But the set of valid values for a foreign key constraint can be changed with SQL DML: SQL insert, update, delete statements. The set of valid values for an equivalent check constraint cannot be changed that way. You have to use SQL DDL to change a check constraint.

Also, different users might have different privileges on the referenced table of a foreign key constraint. Some might have only insert privileges, some might have insert and update privileges, etc. You can't control changes to a check constraint that way. A user that's allowed to change the check constraint can change it in any way.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top