Solved

Database, simple question

Posted on 2011-09-24
2
393 Views
Last Modified: 2012-05-12
Hello experts!

Question about relations in database.

I have two tables:

1. Person
Name
Surname
Age

2.Features
Nice
Aggressive
Polite
Pretty
Ugly

Now I want to save "Features" data against "Person" data.
One person can have none, all or selected features.

1. What is the best way to save such data?
2. What is the best way to make two or more features mutually exclusive- for example someone
cannot be ugly and pretty at the same time.

Thank you

panJames


0
Comment
Question by:panJames
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Assisted Solution

by:Peter Kwan
Peter Kwan earned 50 total points
ID: 36592227
I don't know if your Feature table have columns "Nice", "Agressive" etc; or the listed are the values. However, you may do like this:

1. You may combine both tables into one like this:

Person_Feature
(Name, Surname, Age, Nice, Agressive, Polite, Pretty, Ugly)

2. The best way is to implement the logic in your application code, rather than using database operations.
0
 
LVL 24

Accepted Solution

by:
johanntagle earned 450 total points
ID: 36592230
1. I would assign a numeric personid and featureid for the Persons and Features table, respectively.  Then you store the relationship on a third table, storing the personid and featureid pair.

2.  Unfortunately MySQL doesnt support function based constaints, so I think you need to enforce this exclusivity in the application level.
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question