Click here to Skip to main content
15,894,343 members
Home / Discussions / Design and Architecture
   

Design and Architecture

 
GeneralUnrelated data layer question. Pin
MatthewSmith27-Jan-08 9:35
MatthewSmith27-Jan-08 9:35 
GeneralRe: Unrelated data layer question. Pin
led mike28-Jan-08 6:13
led mike28-Jan-08 6:13 
GeneralRe: Unrelated data layer question. Pin
MatthewSmith28-Jan-08 7:34
MatthewSmith28-Jan-08 7:34 
GeneralRe: Unrelated data layer question. Pin
led mike28-Jan-08 8:34
led mike28-Jan-08 8:34 
GeneralRe: Unrelated data layer question. Pin
Mark Churchill28-Jan-08 20:11
Mark Churchill28-Jan-08 20:11 
GeneralRe: Unrelated data layer question. Pin
dojohansen11-Feb-08 8:10
dojohansen11-Feb-08 8:10 
GeneralRe: Unrelated data layer question. Pin
dojohansen11-Feb-08 8:04
dojohansen11-Feb-08 8:04 
GeneralDAL Design Question Pin
Waleed Eissa24-Jan-08 2:42
Waleed Eissa24-Jan-08 2:42 
Hi gurus, I'm creating a web application for the internet with scalability in mind. In my application, I'll have forums used by different groups of people (each group will have their own forums). I will start from 1000 or 2000 groups with the potential to grow until 5000 groups (it's guaranteed that I won't exceed that number of groups, 5000, based on the nature of my application). I was thinking that having all the forum posts in one table will cause many problems like having a very large index and slow search among other problems (as I want to have many indexes on the table like the PostID, ForumID, GroupID and PostDate), so, I was thinking that it might be better to have a separate table for each group's forum posts in order to have small indexes so that I have faster searches and inserts take less time (esp. that some groups are expected to have a large number of posts per day) and also to be easier to move the tables to other database servers in case the application grows and so the web farm. Now I'm really confused how to design my DAL.

Assuming that the structure of the forum posts table is like that (this is just a simplified structure not the real one):

CREATE TABLE ForumPosts_x
(
PostID INT IDENTITY(1,1) PRIMARY KEY,
ForumID INT NOT NULL, -- which refers to the ForumID in another table named Forums which includes all forums for all groups
ParentPostID INT NULL,
PostSubject NVARCHAR(200) NOT NULL,
PostText NVARCHAR(5000) NOT NULL,
PostDate DATETIME NOT NULL DEFAULT GETUTCDATE()
)

Note that there's no group ID as x in the table name will be the group id e.g. ForumPosts_19 for group id 19

Now as to designing my DAL, should I:

1. Create stored procedures with dynamic SQL and pass the group id to the procedure i.e. use EXEC and sp_executesql (there's an interesting article on the subject here: http://www.sommarskog.se/dynamic_sql.html)

For example:

CREATE PROCEDURE InsertForumPost
@GroupID INT,
@ForumID INT,
@ParentPostID INT,
@PostSubject NVARCHAR(200),
@PostText NVARCHAR(5000)
AS
DECLARE @tablename NVARCHAR(50), @sql NVARCHAR(4000)
SET @tablename = N'ForumPosts_' + @GroupID
SET @sql = N'INSERT INTO dbo.' + quotename(@tblname) +
' (ForumID, ParentPostID, PostSubject, PostText) VALUES (' +
'@ForumID, @ParentPostID, @PostSubject, @PostText)'
EXEC sp_executesql @sql, N'@ForumID INT, @ParentPostID INT, @PostSubject NVARCHAR(200), @PostText NVARCHAR(5000)', @ForumID, @ParentPostID, @PostSubject, @PostText

2. Create the procedures with static SQL for each group. i.e. each group has its own set of procedures which would make us have a large number of procedures

For exmaple, the procedure for inserting a new forum post for GroupID #19 would be:

CREATE PROCEDURE InsertForumPost_19
@GroupID INT,
@ForumID INT,
@ParentPostID INT,
@PostSubject NVARCHAR(200),
@PostText NVARCHAR(5000)
AS
INSERT INTO dbo.ForumPosts_19
(ForumID, ParentPostID, PostSubject, PostText)
VALUES
(@ForumID, @ParentPostID, @PostSubject, @PostText)

3. Use SQL text directly in my code, C# in my case (which I'm highly considering but a little concerned about how to execute multiple SQL statements - as you have in stored procedures - without having to call ExecuteNonQuery() multiple times, which I believe could affect performance)

4. Drop the whole thing and stick to using one table for all the groups


What would you do if you were designing such application? Any suggestions are highly appreciated...


GeneralRe: DAL Design Question Pin
Mark Churchill25-Jan-08 4:24
Mark Churchill25-Jan-08 4:24 
GeneralRe: DAL Design Question Pin
led mike25-Jan-08 4:40
led mike25-Jan-08 4:40 
GeneralRe: DAL Design Question Pin
Mark Churchill25-Jan-08 4:55
Mark Churchill25-Jan-08 4:55 
GeneralRe: DAL Design Question Pin
Waleed Eissa27-Jan-08 3:16
Waleed Eissa27-Jan-08 3:16 
GeneralRe: DAL Design Question Pin
Mark Churchill27-Jan-08 5:19
Mark Churchill27-Jan-08 5:19 
GeneralRe: DAL Design Question Pin
Waleed Eissa1-Feb-08 18:58
Waleed Eissa1-Feb-08 18:58 
GeneralRe: DAL Design Question Pin
Ashfield30-Jan-08 4:24
Ashfield30-Jan-08 4:24 
QuestionBeta Testing? Develop Tech? Pin
Chrispie12323-Jan-08 19:00
Chrispie12323-Jan-08 19:00 
AnswerRe: Beta Testing? Develop Tech? Pin
Paul Conrad25-Jan-08 15:56
professionalPaul Conrad25-Jan-08 15:56 
GeneralVisual Studio 2005 collaboration Pin
Mike Nelson22-Jan-08 1:47
Mike Nelson22-Jan-08 1:47 
GeneralRe: Visual Studio 2005 collaboration Pin
led mike22-Jan-08 4:59
led mike22-Jan-08 4:59 
GeneralRe: Visual Studio 2005 collaboration Pin
Mike Nelson22-Jan-08 7:49
Mike Nelson22-Jan-08 7:49 
GeneralRe: Visual Studio 2005 collaboration Pin
led mike22-Jan-08 7:58
led mike22-Jan-08 7:58 
GeneralRe: Visual Studio 2005 collaboration Pin
Mike Nelson28-Jan-08 2:55
Mike Nelson28-Jan-08 2:55 
GeneralRe: Visual Studio 2005 collaboration Pin
led mike28-Jan-08 5:58
led mike28-Jan-08 5:58 
GeneralRe: Visual Studio 2005 collaboration Pin
Mike Nelson28-Jan-08 7:41
Mike Nelson28-Jan-08 7:41 
GeneralRe: Visual Studio 2005 collaboration Pin
led mike28-Jan-08 8:42
led mike28-Jan-08 8:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.