Help me to understand. How to use SQL to establish relationships between tables:
- one to one;
- one to many;
- much to many;
Help me to understand. How to use SQL to establish relationships between tables:
For example, there is a user table with a unique ID.таблица 1 пользователь id primary key
there is a second table with a foreign key to the 1st tableтаблица2 направление user_id FOREIGN KEY на id 1 таблицы Должность ...и т.д.
This example of communication 1 to 1
one record from 1 table will correspond to 1 record from the second
connection 1 to many, for example, we need to store which tasks are assigned to the user, the first table is unchangedтаблица 3 работыwork_ID primary key user_id FOREIGN KEY на id 1 таблицы
1 user can be assigned several tasks
many to many connection, for example, we need to store the equipment recorded for a particular user, the first table without changes, add two new tables a table with a list of equipmentтаблица 4 оборудованиеdevice_ID primary key Name .....
and table with user equipmentтаблица 5 Перечень оборудованияuser_ID FOREIGN KEY из 1 таблицыdevice_ID FOREIGN KEY из 4 таблицы
Source: https://ru.stackoverflow.com/questions/514321/
All Articles