问题
I have a database schema having more than 40 tables out of which 25 are enumerations having following fields
1. Id (Int)
2. Item (String)
I discussed this scenario here and found having different tables would be better approach.
I implemented this but now I am facing one more issue
I have a table Questionnaire
having following fields
1. Id
2. Question
in which I have to bind the List reference means which list belongs to which question. As suggested for keeping one lookup table better to use EnumerationType
table, in this way i can create a relation and can get the list of corresponding question. Tables would look like this
Questionnaire
1. Id(PK)
2. Question
3. EnumerationTypeId(FK)
EnumerationType
1. Id(PK)
2. EnumerationType
EnumerationItem
1. Id(PK)
2. EnumerationTypeId(FK)
3. EnumerationItem
On the other hand I am facing issue while using 25 different tables. I am unable to bind questions to these tables directly. I don't know how can I achieve this.
The solution that came into my mind is to make another table other than 25 tables which will be the junction table, lets say QuestionList
, between 'Questionnaire' and other 25 tables
1. Id
2. QuestionId
3. TableName
and all i can do is just reference it by name but will it be a good practice to write a query which contains the table names and will it create any problem to write complex queries using INFORMATION_SCHEMA.TABLES
?
Shell I provide more details?
thanks
来源:https://stackoverflow.com/questions/43310381/using-table-names-as-the-foreign-key-for-enumeration-table-type