Friday, March 30, 2012

Relationships, keys, UniqueIDs - why... really?!

I've done my database studies and know about normalizing, relationships, primary keys and so forth. However, when it comes to actual developing of web sites, I've always skipped setting up relationships, and at times, the primary and (especially) foreign keys.

Now I'm designing my first db in Asp.Net 2, and the thought struck me - Why should I do this?

I guess the reason for setting up relationships is that the website should not get any trouble if rules are violated or poorly written, that is, data is input in an Orders table but not the Oredered_products table or the like. The only reason I can think of for using primary keys (when not defining relationships anyway) is to get the Insert, Delete, and Update statements of GridViews etc to work.

Or am I missing something? For many years, I've been told that the keys plus relationships taken together speed up the SQL queries, but, honestly, I can't see why they should. And I guess millions of web developers do like I do - skip the relationship thing altogether.

Please enlighten me, someone! (Or let's have an interesting discussion on this topic - if there is something to discuss, that is!)

Pettrer

pettrer:

Or am I missing something? For many years, I've been told that the keys plus relationships taken together speed up the SQL queries, but, honestly, I can't see why they should. And I guess millions of web developers do like I do - skip the relationship thing altogether.

Actaully indexes speed up SQL queries, keys are only constraints used to enforce the integrity of database (but keep in mind in SQL Server a unique,cluster index is automatically created when a PRIMARY KEY) . And I guess relationships you mentioned should be about data tables in application, or reference integrity between database tables. Here are some links that may help you understand:

Constraints:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/architec/8_ar_da_0777.asp

Indexes:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_05_30s5.asp

Creating an Index:http://msdn.microsoft.com/library/default.asp?url=/library/en-us/createdb/cm_8_des_05_8185.asp

|||

Thanks a lot for the links!

P

No comments:

Post a Comment