I'm trying to create a blog / comment section for our website and am unsure if this is correct. I currently have 3 tables created.
1st - tblBlog (id, title)
2nd - tblPost (id, blogID (FK), author, ....);
3rd - tblComment(id, postID (FK), commentReply (FK), ...)
Anyway the commentReply field will reference the comment id and i am unsure as to whether the code below does what I think it does.
Code: Select all
CREATE TABLE tblComment (
commentID int(11) AUTO_INCREMENT NOT NULL,
name varchar(50) NOT NULL DEFAULT '',
email varchar(100) NOT NULL DEFAULT '',
comment text NOT NULL,
commentDate date NOT NULL,
FOREIGN KEY(postID) REFERENCES tblPost(postID),
FOREIGN KEY(commentReply) REFERENCES tblComment(commentReply));
I am sure I could make a few change i.e. have the user info in another table but does this code link the commentReply back to the comment table so that I can handle replies to comments.
NOTE: been along time since I have done any SQL and that was in Oracle so slightly different and I have forgotten most of it.