More columns with less data or less columns with more data?
I want to know what is better.
- save all data (for example skype,icq,facebook,stackoverflow,etc,etc,etc) profiles in one column
- save data in separated columns (separated column for skype, icq, fac开发者_StackOverflow中文版ebook, stackoverflow, etc,etc)
What is better and easy for mysql server?
Saving them all in one column would violate first normal form and make querying and aggregating the data very difficult.
Use one column to store each piece of information.
If you are storing profile data for each service, you might even be better of with a separate table per service, with a foreign key to the user id.
Beyond discussions with respect to normalization which might seem abstract, asking the right questions can help make it clear why one approach might be superior to another.
Would you want to query for specific accounts? E.g., find all Skype accounts or find a specific Skype account. Of your two approaches, which makes that easier?
Which approach do you suppose would be easier to correct if there was a problem with the storage of one of the account types?
Which approach do you suppose would be easier to expand the types of accounts? E.g., today you build for Skype, ICQ, Facebook and StackOverflow. Tomorrow, you realize you want to store Twitter accounts. Which approach do you suppose would make that easier?
Which approach do you think would be easier for another developer to grasp, maintain and expand? E.g., your system becomes so popular that you hire developers to take over your work. The approach that is more inline with industry best practices will be easier for other developers to understand.
When you analyze the problem like this, it should be clear that storing the information into separate columns or perhaps a table with accounts where each user can have multiple rows that represents multiple accounts is the superior approach.
You will gain much more flexibility if you use multiple columns.
If you would like to query the database based on one of these fields, it would be very difficult if it is all packed together into one column. It also makes maintaining the database more difficult for yourself and whoever comes after you.
精彩评论