Comment Hierarchy Comments Section DataBase in SQL Server


Comment Hierarchy Comments Section DataBase in Asp.net

In this article i'm going to explain about comment hierarchical comment section database designs as i shown in above images. So first we need to create database table's UserTable, ParentCommentTable and ChildCommentTable.

DataBase : UserTable

 create Table UserTable(
  Username varchar(25),
  Password varchar(25),
  Primary Key(Username))
 Go

 Insert into UserTable values('Paul','Paul1')
 Insert into UserTable values('Robert','Rober1')
 Insert into UserTable values('James','James1')
 Insert into UserTable values('Mary','Mary1')
 Insert into UserTable values('Albert','Albert1')

DataBase Table : UserTable

This table i'm creating with default data for the purpose of avoiding to insert user data through web pages. By using this table i'm going to create Login page and verifying user credentials, if user exists then he allow to enter Comments otherwise not.

DataBase : ParentCommentTable

create table ParentCommentTable(
 CommentID int identity(1,1),
 Username varchar(25),
 CommentMessage varchar(300),
 CommentDate date,
 Primary Key(CommentID),
 Foreign Key(Username) References UserTable(Username))
 

DataBase Table : ParentCommentTable

If user post comments directly through comment section in your Websites (i.e Social Networking Sites, Forum Site, Blogs, Youtube.....) is called parent comments. CommentID is autogenerateid in sql which generate commentid no once data is inserted along with ussername to the ParentCommentTable.

Blogger Comments
For Example :
Once you click on publish button whatever comment you enter is called Parent Comment.

DataBase : ChildCommentTable

create table ChildCommentTable(
 CommentID int identity(1,1),
 Username varchar(25),
 CommentMessage varchar(300),
 CommentDate date,
 ParentCommentID int,
 Primary Key(CommentID),
 Foreign Key(ParentCommentID) References ParentCommentTable(CommentID),
 Foreign Key(Username) References UserTable(Username)) 

DataBase Table : ChildCommentTable

If user Reply the existing comment in any site is called Child Comment. Here existing comment is nothing but a Parent Comment and we store reply comment to child comment table along with parentcommentID. for more info we see in programmatically.

Blogger Comments
1 2 3 4 5 6

0 Komentar untuk "Comment Hierarchy Comments Section DataBase in SQL Server"

Back To Top