C
C#16mo ago
Ownix

❔ If you needed to bulk sync data from an API into a DB, what would you use as a PK for child data?

For example imagine you get this data back HOURLY from GET /users:
{
"users": [
{
"Id": 1,
"Addresses": [
{
"Street": "123 Main St",
"City": "Anytown",
"State": "CA"
},
{
"Street": "123 Main St",
"City": "Anytown",
"State": "CA"
}
]
},
{
"Id": 2,
"Addresses": [
{
"Street": "456 Main St",
"City": "MyTown",
"State": "CA"
},
{
"Street": "123 Main St",
"City": "Anytown",
"State": "CA"
}
]
}
]
}
{
"users": [
{
"Id": 1,
"Addresses": [
{
"Street": "123 Main St",
"City": "Anytown",
"State": "CA"
},
{
"Street": "123 Main St",
"City": "Anytown",
"State": "CA"
}
]
},
{
"Id": 2,
"Addresses": [
{
"Street": "456 Main St",
"City": "MyTown",
"State": "CA"
},
{
"Street": "123 Main St",
"City": "Anytown",
"State": "CA"
}
]
}
]
}
You obviously would have a dbo.user table and a dbo.user_address table. dbo.user would have PK Id and dbo.user_address would have an FK of UserId. But what about a PK for the address table? How could you possibly update an address without having a unique identifier from it? SHould I just TRUNCATE followed by INSERT?
1 Reply
Accord
Accord16mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server