What is the best way to implement a table with a variable number of columns and different types? (The number of columns is unknown)
We use a column of type XML. What do you think?
It sounds like using document based databases ,if possible.
Technically you can not have a variable column designed table in SQL-Server.
By the way having a table based on columns bellow, may help:
EntityName: Full qualified entity name
EntityIdentifier: Id
PropertyName:
PropertyType:
PropertyValue:
EntityStatus: may be useful on delete action
In these approach, like XML scenario you will need a parser to extract the entity. At list sql query will be more readable and updates will be more convenient.
Hope be helpful.
Surely you would create another table where the key, is a composite key of the ID and ColumnName.
Table Def :
ID ColumnName ColumnValue
The Id is the key from the primary table with a FK to enforce integrity.
You now have two choices make the datatype of the value a dumping ground and insert anything, or create a table like the above for each datatype you need.
Then you can write a view with a pivot to make this look like a normal table for queries etc.
Ps I don't suggest this will be a) the best solution or b) the quickest.