Recently I’ve asked a question about the best way to go to design a DB schema to support multiple types of users and interactions between them, one of the answers suggested that I use one table for each user type and Distributed Keys.
The thing is the only databases I actively work with are MySQL and SQLite and I’ve always done this kinda of work of maintaining the integrity of the DB on the programming side and never directly in the database, can someone point me to a detailed yet easy to understand guide on foreign keys, references and related subjects?
Thanks in advance!
EDIT: I’m interested specifically in MySQL usage examples and documentation, I’ve already searched in the MySQL manual but nothing useful comes up.
This isn’t MySQL-specific, but there is some good stuff in here
http://www.simple-talk.com/sql/database-administration/ten-common-database-design-mistakes/
I don’t agree with him about the use of natural keys versus surrogate keys. I have found surrogate keys in general work better for primary keys, but if you have a natural key you should put a unique index on it to prevent duplication of data. Pay particular attention to the sections on:
– Not using SQL facilities to protect data integrity
– Trying to code generic T-SQL objects
– One table to hold all domain values
Another good starting place is:
http://www.deeptraining.com/litwin/dbdesign/FundamentalsOfRelationalDatabaseDesign.aspx [dead link Feb 17, 2015]