Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am fresher in database side. I am developing entertainment site. That site having user comment, reply comment for that user comment and rating for that user comment. For this, how I can design a database to store user comment, reply comment for that user comment and rating for that user comment.
User can post their comment only when login into the site. But this restriction is not apply for rating. User can give a rating without login into the site.
Any help will be helpful. Thanks.
2 tables; Comments & Replies
table comments:
#Comment_id(int)(pk)
*Users_id(int)(fk)
*Comment_content (varchar(500))
*Comment_rating(int)
*Comment_date(date)
table replies:
#Reply_id(int)(pk)
*Comment_id(int)(fk)
*Users_id(int)(fk)
*Reply_rating(int)
*Reply_content(varchar(500))
pk-> primary key
fk-> foreign key
#-> unique identifier
*->mandatory
The table "Users" is the table where your users are stored. Keep note this stores the content of a reply as flat text. I did not take into account the possibility of uploading images.
The rating fields are mandatory because the comments and replies have ratings. The fact that you need to be logged in to comment or reply is enforced because an user id is required. however to enable anonymous users to rate, that should not be done in the database at all. That should be done on the website itself. That would be a button that updates the field of the comment/reply with the corresponding ID.
note; this is not a perfect example. you should do research on database design and normalization. Nevertheless this will get you started.
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I'm trying to find the best solution for my needs. I have a budgeting application that each user will have their own budget which will include potentially hundreds or thousands of budget entries. Initially I thought I would have a table for the users and basic info, and then each user would have their own sql table with all of their budget items held within. However, if the user list grows to hundreds or thousands then I would have a large amount of tables since each user would have their own. I also considered a single table to hold everyone's budget entries but I'm not sure that's the correct solution either.
Any advice? Thank you in advance
I think a single table that holds all the budget entries, with a primary key that's referenced by a foreign key in the "users" table, is a good way to go. You can always use something like select * from users u join budgets b on u.userID = b.userID where userID = xxx to get the budget items for a particular user.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 4 years ago.
Improve this question
I am currently logged in as the first student. I want to retrieve a list of the students I did not send a request to yet. I also want to retrieve a list of students I sent a request to.
Both sender_id and Rec_id are foreign keys referencing to Students.id.
DB schema
Hi Souleiman and welcome to stackoverflow! Your question is not quite clear, you say that sender_id and Rec_id in requestts are both referencing to students, but you can't see to which field exactly. Your requestts table contains different entries in these fields.
Next time you should post the output of SHOW CREATE TABLE students and SHOW CREATE TABLE requestts and a little INSERT statement for the data. Furthermore it would be nice if you would explain the relations and show what you have already tried (see Barmars comment).
I suppose that the relevant foreign key in requestts is Rec_id, so you could try this query:
SELECT s.email FROM students s WHERE s.id NOT IN
(SELECT Rec_id FROM requestts WHERE Rec_id = s.id);
Hope this helps. Have fun learning SQL!
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
everyone
I'm building a photo forum website like 500px, I met some problem when trying to construct the database for those images. Do I need to create a new table for each photo the user updated where there are photo id, photo "likes", photo description, photo comments, photo update time, etc? Would it make my server explode to create too much tables in mysql? Or, what's the best practice to store all those informations in database except image itself(I would store them in a directory)? Thanks!
You need just one table photos. And for each photo you should add a new record to this table. I'd suggest you to read more theory on database design. Then there will be no reason to ask such questions.
Edit: For comments you should create another table with fields: id, user_id, photo_id, comment, created_at etc.
Why would you want to create a new table for each user? If you've got one database table with proper index you should be fine and if the table gets bigger over time, you can just do sharding and put it on multiple servers.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I currently have 3 table and I am unsure if they should be merged or not. They do have similar fields, and a supplier would need to login at some point or another, and even clients
User
Username
Password
Name
Surname
Mobile
Telephone
Email
Client
Name
Telephone
Email
Fax
VatNo
Supplier
Name
Telephone
Email
Fax
VATNo
LastRefreshDate
OpeningHoursId
Can somebody give me a suggestion as he best way to go forward.
The tables should probably not be merged. However, that's a judgement call based on guesses about what the tables mean.
It looks like clients and suppliers can be corporate entities (VAT numbers, for example), but users should be individuals rather than collective accounts. You may well have a list of users associated with a given supplier; similarly, you may well have a list of users associated with a given client. In some circumstances, a supplier may also be a client. You would need a User ID number in the Users table; you would need a Client ID number in the Clients table and a Supplier ID number in the Suppliers table. You would have simple mapping tables to list the Users associated with a Client and another to list the Users associated with the Suppliers.
However, a lot depends on whether the guesses I've made (plausible ones, but nonetheless guesses) are remotely on target.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm new to programming, and hope this question isn't too basic. I've searched the questions here but can't find anything exactly like it.
I'm making a website in which people have to complete a sign-in form and then answer a survey. The survey answers will drive how the site performs for each user (there will be different monthly reminders in email personalized to the survey responses). I have two MySQL databases, one for the sign-in and one for the survey.
How do I get the member ID in the member database to be the same as the survey ID in the survey database? Or am I thinking about this all wrong, and there's another solution?
I'm most familiar with PHP and JavaScript, so I hope that there will be a way to do this in the coding if not in the database design. Again, sorry if this is too basic and many thanks in advance for your help.
This is a terribly generic question to answer, but I hope I can help you a little along:
Now, assuming that you have a good reason for separating the user registration and the surveys in two different databases (you did not give a reason for it being so), after a successful user registration you can assume that the user is 'logged in'. This should mean that the ID of the registered user is available to you in code.
You do not have to have identical survey IDs and user IDs, it usually makes more sense to have a separate table knitting users and surveys together (with a user_id field and a survey_id field).
After setting up or saving the survey, store a record in this table, connecting the user with the survey.
If you were hoping for a more specific answer, I suggest you delve into a little more detail in your question.
Good luck!
Just some hints, they won't rock the house but probably good for a start:
Put the two tables in the same database. This is less a technical requirement, but it's easier for you. The two tables belong together, keep them in the same database.
It's okay to have two tables.
The member ID and the survey ID do not need to be the same. Instead add a memberID column to the survey table and set it to the appropriate ID of the member table.