Using Table Names as the Foreign Key for Enumeration table type

走远了吗. 提交于 2019-12-12 04:37:50

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!