数据库结构.. Ugg ?
好吧,这可能看起来很愚蠢,但我想确保我是对的。
我有一个足够简单的数据库设置:
Table_Customer
ID (PK)
Acc_number
First
Last
etc.
Table_Notes
ID (PK)
Note_Type_FK (links to Table_Note_type)
Note
Account_FK (Links to Table_Customer)
Table_Note_Type
ID (PK)
Note_Type_Name
Note_Type_Desc
Notes
用于与该客户相关的所有注释,并且可以用于技术支持、销售跟进等。该表有一个链接到Note_Type
的FK code> 和 FK 返回到 Customer
中的 Acc_number
。
我的问题:
- 此设置正确吗?
- 使用 SQL,当我添加/更新客户并选择注释类型(例如技术支持)并输入该客户的注释时,当我运行插入语句时,我应该做什么/注意什么?
这是一个简单的问题,但我想确保我做得正确。
Ok, So this may seem silly but I want to make sure I am right.
I have a simple enough database setup:
Table_Customer
ID (PK)
Acc_number
First
Last
etc.
Table_Notes
ID (PK)
Note_Type_FK (links to Table_Note_type)
Note
Account_FK (Links to Table_Customer)
Table_Note_Type
ID (PK)
Note_Type_Name
Note_Type_Desc
Notes
is for all notes relating to that customer and can be for tech support, sales follow up, etc. This table has a FK linked to Note_Type
and a FK back to Acc_number
in Customer
.
My Questions:
- Is This set up correctly?
- Using SQL, when I add/update a customer and select a note type (eg, Tech Support) and type in a note for that customer, is there anything I should be doing / watching out for when I run the insert statement ?
Its a simple question, but I want to make sure I am doing this correctly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
对于简单的 CRM 类软件来说,该设置似乎是正确的,但如果没有完整的系统要求,我们无法回答它是否正确。
至于插入,只要
Customer
和Note_Type
都已经存在,一切都应该没问题。一开始让一些人困惑的一件事是确保级联规则按照他们想要的外键方式设置。根据要求,您可能希望在删除Customer
(级联删除)时删除所有Notes
,或者您可能希望要求所有Notes< /code> 首先显式删除,在允许删除
Customer
之前(级联限制)The setup seems correct for a simple CRM sort of software, but without the full system requirements, we can't answer if it is correct or not.
As far as inserting, as long as both the
Customer
and theNote_Type
already exist, everything should be fine. The one thing that trips some people up at first is making sure the cascade rules are set the way they want them on the Foreign Keys. Depending on the requirements, you might want to have allNotes
deleted when you delete aCustomer
(cascade delete), or you might want to require that allNotes
are explicitly deleted first, before theCustomer
is allowed to be deleted (cascade restrict)您的结构是正确的,但您可能需要重新考虑您的命名方案。尽管命名方案可能有很大差异,但在所有数据库表中添加
tbl
或Table_
前缀通常不被认为是好的做法。 Narayana Vyas Kondreddi 撰写的这篇文章似乎是关于 SQL Server 命名约定最广泛接受的指南之一:http ://vyaskn.tripod.com/object_naming.htm
SQL命名约定的问题之前也在这个网站上得到过解答,参见:
Microsoft 的数据库命名约定?
Your structure is correct, but you may want to rethink your naming scheme. Although naming schemes can vary widely, it's generally not considered good practice to prefix all your database tables with
tbl
orTable_
. This article authored by Narayana Vyas Kondreddi seems to be one of the most widely accepted guides on SQL Server naming conventions:http://vyaskn.tripod.com/object_naming.htm
The question of SQL naming conventions has also been answered on this site before, see:
Database Naming Conventions by Microsoft?
你的方法将会奏效。有一件事值得一提;如果帐号是唯一的,则不需要客户表中的 ID。
这是一个适合您目的的简单 ERD。
Your approach will work. One thing to mention; you don't need ID in customer table if account number is unique.
Here's a simple ERD for your purpose.