• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 403
  • Last Modified:

Database, simple question

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
panJames
Asked:
panJames
2 Solutions
 
Peter KwanCommented:
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
 
johanntagleCommented:
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now