0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Tahnks,please give me Your Mail to Send Complete Description My Emails: ESH_Computer110@yahoo Esmaeil From Shiraz-Iran
[email protected] is my email address, Its appreciated if the complete question and answer be negotiated on stack-overflow for others to use. by the way don't forget to mark the answer as the answer of your question, if fitting you.
0

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.

2 Comments

Isn't this EAV? (for better or worse)
I suppose it kinda is, hence my suggest's a) and b)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.