How to efficiently store custom attributes in Azure SQL?
So, we've got this system that stores and processes records off persons. Each person has a number of standard attributes like Name, Date of birth and Gender. This looks the same for all our customers.
In order to make the system more versatile, we now need to store attributes alongside each person that can vary depending on the customer. Customer X wants to store shoe size, customer Y wants to store their maiden name. The attributes can be of varying number and type.
How should we organize/store this efficiently? We use a SQL server with an ORM to query our data. And the custom attributes must be queryable through the ORM.
Example 1: Table Customer:
- Name
- Gender ...
- Field1Int
- Field1String
- Field1Date
- Field2Int ...
Example 2: Table CustomAttributes
- CustomerID
- AttributeID
- IntVal
- StringVal
- DateVal
I guess alt 1 would be the fastest but feels hacky and is not so easy to extend, but alt 2 is more elegant and extendable, but I expected much slower?
We got max 1.000.000 persons and maby 0-20 custom attributes per customer.
Azure SQL Server with EF on .Net.
Really grateful for your advice!
Posted Jan 17, 2019, 8:46 PM UTC
This scenario is one of the arguments for introducing json support in MS SQL. To have the attributes in a json blob. I haven’t used it myself. There is a good example in the docs. It’s about products instead of customers.
Otherwise, the second approach is ok I believe.
Thanks. Json sounds pretty great, but I'm a bit worried about performance. Will have to make some tests I presume...