I have 3 entities in my database:
- Client
- Project
- Contract
The principle is very simple, a client establishes a contract for a specific project. a project can only be assigned to a client. a contract can only be assigned to a unique combination of client and project.
what is an efficient and clear way to translate this into SQL tables?
CodePudding user response:
My suggestion would be a 3 tables
- A table with all your clients where the primary key is some sort of unique id.
- A table with you projects where the primary key is some sort of unique id.
- A table with your contracts where the primary key is some sort of unique id.
The projects table will need client_id column which is a foreign key to the clients table. The contracts table will need a project_id column which is a foreign key to the projects table.