实现许多实体的Notes表的最佳方法SQL中的表 [英] Best way to implement a Notes Table for many entities Tables in SQL

查看:105
本文介绍了实现许多实体的Notes表的最佳方法SQL中的表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有很多表:客户,潜在客户,朋友..

他们都有一些笔记。



问题1:
我应该有一个Notes表与所有的父表共享。

OR

我应该有一个NotesCustomer,NotesProspects,NotesFriends表吗?



问题2:

如果最好的解决方案是第一个解决方案,那么这个通用Notes表应该有一个FK到父表,父表的类型?



我使用EntityFramework,但这个问题也是一般的我猜...



感谢
Jon

解决方案

第一个选项是Prospects,Customers和Friends的独特Notes表,可能是一个更清洁的解决方案。 / p>

如果使用通用笔记表,您将需要有三个可空的FK列来确定FK属于哪个相关表,其中只有一个填充在每行中



一般来说,良好关系模型的目标不是(或不一定)将类似数据存储在一起,而只能存储特定数据一次。所以在设计这个问题时要问问自己的一个好问题是通过将所有笔记存储在同一张表中获得什么?


i have many tables : customers, prospects, friends..
They all have some Notes.

Question 1: Should i have one Notes Table shared with all the parent Tables.
OR
Should i have a NotesCustomer, NotesProspects, NotesFriends Tables ?

Question 2:
If the best solution is the first one then this general Notes table should then have a FK to the parent table but ALSO the type of the parent table ?

I'm using EntityFramework but this question is also general i guess...

Thanks Jon

解决方案

The first option, a distinct Notes table for Prospects, Customers, and Friends, is likely a cleaner solution.

If you use a general notes table, you will need to have three nullable FK columns to determine which related table the FK belongs to, with only one of them populated in each row.

Generally speaking, the goal of a good relational model is NOT (or not necessarily) to store like data together, but to only store specific data once. So a good question to ask yourself when designing this would be "what am I gaining by storing all notes in the same table?"

这篇关于实现许多实体的Notes表的最佳方法SQL中的表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆