Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 relationship question

Author  Topic 

-Dman100-
Posting Yak Master

210 Posts

Posted - 2004-09-15 : 22:40:13
I'm stumped on how I should design the following relationship in my database. I'm building a weblog and want to design for the following functionality.

I have a table = tblWeblog with the following fields
blogID
blogDate
blogHeader
blogComment
blogPostTime

The field for blogComment will contain the original post that has a specific date associated with the entry.

My question is, I think I would need another table for additional comments that are related to a specific blogComment field in tblWeblog?

So, if I created another table...i.e. tblUserComments with the following fields:
blogUserID
blogUserComments
blogUserName

How would I create the relationship that ties the new user comments to a specific comment in tblWeblog where the original post is stored?

Any help is greatly appreciated. Thanks.
-D-

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-09-15 : 22:45:54
Just add blogID to the UserComments table (please get rid of the tbl prefixes, they don't do anyone any good). That will let you link/relate the comment to the blog entry in the WebLog table.
Go to Top of Page

-Dman100-
Posting Yak Master

210 Posts

Posted - 2004-09-15 : 23:18:42
Thanks for the reply. Just to clarify, so I understand correctly. I need to create a foreign key in the UserComments table by adding the field blogID. Then I need to create a one to many relationship from the Weblog table with the "blogID" field related to the UserComments table with the "blogID" field, correct?

Thanks again,
-D-
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2004-09-15 : 23:22:33
Well, creating the foreign key "creates the relationship", as it were. Tables can be related to each other without declaring foreign keys, however, adding them ensures data integrity; you can't insert a UserComment that refers to a non-existent blog entry. It also prevents you from deleting a blog that has additional user comments. As an added benefit, declaring the foreign key also allows data modeling software to establish that relationship automatically when scanning or modeling your existing databases.
Go to Top of Page
   

- Advertisement -