Ben bir çapraz başvuru tablosu yaparak bu yapardı.
Örnek:
Table: Posts
Columns: pstkey | userid | postMessage | etc...
pstkey is the key for the post body. userid is the person who created the post. postMessage is the actual post entry.
Table: Comments
Columns: comkey | pstkey | userid | commentMessage | etc...
comkey is the key for the comment made. referenced to the post using the pstkey. userid is the person who made the comment. and then commentMessage is the text body of the actual comment.
Table: xref_postComm
Columns: xrefkey | pstkey | comkey | comkey2 |
Now for the fun part. ALL posts go into post table. ALL comments go into comment table. The relationships are all defined in the Cross Reference Table.
Benim programlama tüm bu şekilde yapmak. Ben dünyalardan birinin emekli ve bana bir kaç numara öğretilen veritabanı mühendis bests ile çalışmak için ayrıcalıklı oldu.
How to use the Cross Reference table:
xrefkey | pstkey | comkey | comkey2
All that you look for is the population of a given field.
xref (Auto Incremented)
pstkey (Contains the pstkey for the post)
comkey (Contains the comkey for the comment post)
comkey2 (Contains the comkey for the comment post)
(but only populate comkey2 if comkey already has a value)
and of course you populate comkey2 with the key of the comment.
SEE, no reason for a 3rd tabel!
With this method you can add as many relationships as you want.
Now or in the future!
comkey2 bir cevapta için cevap. Nerede hangi Bu tek satır .... yazının anahtarı, yorumun anahtarını ve cevap yorumuna cevap anahtarı içerir. Tüm xref nüfus tarafından yapılır.
EXAMPLE:
PAGES.... Page table
POSTS
pstkey | pageid | user| Post
-------------------------------------
| 1 | 1 | 45 | Went to the store the....|
| 2 | 2 | 18 | Saw an apple on tv.....
COMMENTS
comkey | pstkey | user | Comment
-----------------------------------------------
| 1 | 1 | 9 | Wanted to say thanks...
| 2 | 1 | 7 | Cool I like tha.....
| 3 | 2 | 3 | Great seeing ya....
| 4 | 2 | 6 | Had a great....
| 5 | 2 | 2 | Don't sweat it man...
xref_PostCom
xrefkey | pageid | pstkey | comkey | comkey2 |
----------------------------------------------
| 1 | 1 | 1 | NULL | NULL | Post1 on Page1
| 2 | 1 | 1 | 1 | NULL | Comment1 under Post1
| 3 | 1 | 1 | 2 | NULL | Comment2 under Post1
| 4 | 2 | 2 | NULL | NULL | Post2 on Page2
| 5 | 2 | 2 | 3 | NULL | Comment3 under Post2 on Page2
| 6 | 2 | 2 | 4 | NULL | Comment4 under Post2 on Page2 (a second Comment)
| 7 | 2 | 2 | 4 | 5 | Explained below....
Comment key 5 is matched with comment key 4....under post2 on Page 2
Katılmak hakkında bir şey biliyorsanız, dış / iç işiniz çok daha kolay olur, veri dizileri bu ilişkileri kullanarak elde SELECT en oluşturarak katılmak, doğru katılmak, katılmak bıraktı.
Ben mühendisin çağrısını tanımlanan ilişkilerin bu temelde "veri haritası" inanıyorum. Hüner, bu ilişkileri kullanarak erişmek nasıl şimdi. Bu ilk başta zor yolunmuş, ama ben bildiklerimi biliyorum, ben bunu başka bir şekilde yapmayı reddediyorum.
Ne sonunda olur siz diyor 1. Senaryoyu yazarken sonuna kadar olduğunu, tamam, ahh yapmak gitmek her şeyi ve geri gel. Sen sayfa 1 sorar 1 işlev çağrısı ile sona erecek. Bu sayfadır1 ile döner, 1, comment1 & 2 & 3 ve 1 dizi yanıta cevap gönderebilir. çıktı yankı ve aferin.
UPDATE FOR COMMENT
I said the same exact thing the first time it was shown to me. As a matter of fact it really was making me mad that the database programmer was forcing me to do it this way. But now I get it. The advantages are so many.
Avantaj 1) 1 sorgu 1 atış tüm dışarı çekmek için yazılmış olabilir.
2) çoklu sorgularda Cevapları sayfayı yazdırırken bir döngü içinde bir döngü sayfayı görüntülemek edebileceği bir yapıda diziler doldurabilirsiniz.
3) bu hiç aklınıza gelebilecek olası tasarım değişikliğini destekleyen kullanan yazılım yükseltme. Kusursuz genişleme.
Bunu öğretti bana adam Sears ve JCPenny veritabanlarını yeniden tasarlanmış işe silah oldu. Onlar çünkü yinelenen kayıtları sorunları aynı evde gidiyor 9 kitap var ne zaman geri.
Çapraz referans tabloları tasarımı konularda bir sürü engeller.
Bu teoriye kalp bir sütun veri içeren ama aynı zamanda bir doğru veya yanlış beyanı olarak hizmet değil sadece, olduğunu. Bu kadar kendini o yer kazandırır. Eğer bir arama varken neden 20 tablolar mı arıyorsunuz? 1 endeksli çapraz başvuru tablosu size ihtiyacınız yok ne gerek ne içeriği, diğer 20 tablolar hakkında bilmeniz gereken her şeyi söyleyebilir ve hatta tüm diğer tabloyu açmak gerekiyor.
IN SHORT:
1 Cross reference containing nothing but INT(2/11) that tells you everything thing you need to know before you ever open another table, not only contains flawless expandability but lighting speed results. Not to mention little possibility of duplicate records. To you and me duplicate records may not be an issue. But to Sears with 4 billion records at $11 a book, mistakes add up.