开发者

MYSQL Database Schema Question

I need opinions on the best way to go about creating a table or collection of tables to handle this unique problem. Basically, I'm designing this site with business profiles. The profile table contains all your usual things such as name, uniqueID, address, ect. Now, the whole idea of the site is that it's going to be collecting a small string of informative text. I want to allow the clients to be able to store one per date, with as many as 30 days in advance. The program is only going to show the information from the current date on forward, with expired dates not being shown.

The only way I can really see this being done is a table consisting of the uniqueID, date, and the informative block of text, but this creates pretty extensive queries. Eventually this table is going to be at least 20 times larger than the table of businesses in the first place as these businesses are going to be able to post up to 30 items in this table using their uniqueID.

Now, imagine the search page brings up a list of businesses in the area, it's then got to query the new table for all of those ids to get that block of information I want to show based on the date. I'm pretty sure it would be a rather intensive couple of queries just to show a rather simple block of text, but I imagine this is how status updates work for social networking sites in general? Does facebook store updates in a table of updates tied to a users ID number or have they come up with a better way?

I'm just trying to gain a little more insight into DB design, so throw out any id开发者_如何学运维eas you might have.


The only way I can really see this being done is a table consisting of the uniqueID, date, and the informative block of text...

Assuming you mean the profile uniqueID, and not a unique ID for the text table, you're correct.

As pascal said in his comment, you'd need a primary index on uniqueID and date. A person could only enter one row of text for a given date.

If you want to retrieve the next text row for a person, your SQL query would have the following clauses:

WHERE UNIQUE_ID = PROFILE.UNIQUE_ID
AND DATE >= CURRENT_DATE
LIMIT 1

Since you have an index on uniqueID and date, this should be a fast query.

If you want to retrieve the next 5 texts for a particular person, you'd just have to make one change:

WHERE UNIQUE_ID = PROFILE.UNIQUE_ID
AND DATE >= CURRENT_DATE
LIMIT 5
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜