If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > General > Database Concepts & Design > database schema for a multiuser/multiblog system

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 03-06-07, 06:23
SelArom SelArom is offline
Registered User
 
Join Date: Jul 2005
Posts: 20
Question database schema for a multiuser/multiblog system

hi everyone, I'm wanting to make a simple blogging system, where a user can create their own blog.

But I also want a user to be able to create multiple blogs. This means that one person can have many blogs and also many people can have one blog. I'm wondering the best way to store this information in the database. I'm thinking one big table for all the posts, but how can I map a specific post to the specific blog of a specific user?

I thought about using something like how wordpress uses table prefix, but that requires that I make my queries dynamically and all my research says this is a bad idea. but then how am I supposed to implement this?

can this be done using just one database?

thanks
-SelArom
Reply With Quote
  #2 (permalink)  
Old 03-06-07, 06:30
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
Quote:
Originally Posted by SelArom
... but how can I map a specific post to the specific blog of a specific user?
one table for the blogs
Code:
create table blogs
( blog_id integer not null primary key 
, foo varchar(99)
);
one table for the users
Code:
create table users
( user_id integer not null primary key 
, bar varchar(99)
);
one table for which user(s) can post on which blog(s)
Code:
create table blogusers
( blog_id integer not null 
, user_id integer not null 
, primary key (blog_id,user_id)
);
and one table for the posts
Code:
create table posts
( post_id integer not null primary key 
, blog_id integer not null 
, user_id integer not null 
, foreign key (blog_id,user_id)
     references blogusers 
);
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 03-06-07, 10:30
SelArom SelArom is offline
Registered User
 
Join Date: Jul 2005
Posts: 20
this is pretty much exactly what I ended up doing, thanks i'm glad I wasn't off base. thanks for replying!

-SelArom
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On