database relationships

2019-02-20 16:43发布

does setting up proper relationships in a database help with anything else other than data integrity?

do they improve or hinder performance?

8条回答
forever°为你锁心
2楼-- · 2019-02-20 16:58

Relationships in the data exist whether you declare them or not. Declaring and enforcing the relationships via FK constraints will prevent certain kinds of errors in the data, at a small cost of checking data when inserts/updates/deletes occur.

Declaring cascading deletes via relationships helps prevent certain kinds of errors when deleting data.

Knowing the relationships helps to make flexible and correct use of the data when forming queries.

Designing the tables well can make the relationships more obvious and more useful. Using relationships in the data is the primary power behind using relational databases in the first place.

查看更多
戒情不戒烟
3楼-- · 2019-02-20 16:59

About impact on performance: In my experience with MS Access 2003, if you have a multi-user application and use Relationships to enforce a lot of referential integrity, you can take a big hit in terms of response time for the end-user.

There are different ways to take care of enforcing referential integrity. I decided to take out some rules in Relationships, build more enforcement into the front-end and live with some loss of RI. Of course in the multi-user environment, you want to be very careful with that bit of liberty.

查看更多
神经病院院长
4楼-- · 2019-02-20 17:02

Do relationships in databases improve or hinder performance?

Like any tool in your toolbox, the results you'll get depend on how you use it. Properly specified relationships and a well-designed logical database can be an enormous boon to performance -- consider the difference between searching through normalized and denormalized data, for example.

查看更多
淡お忘
5楼-- · 2019-02-20 17:08

It neither helps nor hurts performance in any significant way. The only hindrance is the check for integrity when inserting/updating/deleting.

Foreign keys are an important part of database design because they ensure consistency. You should use them because it offers the lowest level of protection against data screw ups that can wreck your applications. Another benefit is that database tools (visualization/analysis/code generation) use foreign keys to relate data.

查看更多
不美不萌又怎样
6楼-- · 2019-02-20 17:11

As long as you have the obvious indexes in place corresponding to the foreign keys, there should be no perceptible negative effect on performance. It's one of the more foolproof database features you have to work with.

查看更多
可以哭但决不认输i
7楼-- · 2019-02-20 17:12

In my experience building performance-sensitive databases, Foreign Keys hurt performance pretty significantly, since they have to be checked every time the referring record is inserted/updated or master record is deleted. If you need a proof, just look at the execution plan.

I still keep them for documentation and for tools to use but I usually disable them, especially in high-performance systems where access to DB is only through the application layer.

查看更多
登录 后发表回答