Solved

Database, simple question

Posted on 2011-09-24
2
385 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
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

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

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

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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…

821 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