数据库设计可动态创建表 [英] Database design to create tables on the fly
问题描述
我需要在数据库中动态创建动态表.例如,在数据库中,我将有名为:
I need to create dynamic tables in the database on the fly. For example, in the database I will have tables named:
Table
Column
DataType
TextData
NumberData
DateTimedata
BitData
在这里,我可以在名为table的表中添加一个表,然后可以将所有列添加到columns表中的该表,并将数据类型与每个列相关联.
Here I can add a table in the table named table, then I can add all the columns to that table in the columns table and associate a datatype to each column.
基本上,我想创建表而不在数据库中实际创建表.这有可能吗?如果是这样,您可以将我定向到正确的位置以便我进行研究吗?另外,我更喜欢sql server或任何免费的数据库软件.
Basically I want to create tables without actually creating a table in the database. Is this even possible? If so, can you direct me to the right place so I can research? Also, I would prefer sql server or any free database software.
谢谢
推荐答案
What you are describing is an entity-attribute-value model (EAV). It is a very poor way to design a data model.
尽管数据模型非常灵活,但是查询这样的数据模型却非常复杂.如果要选择或过滤n
个不同的属性,您经常不得不不得不自联接表n
次.这变得越来越慢,并且变得相对难以快速优化.
Although the data model is quite flexible, querying such a data model is quite complicated. You frequently end up having to self-join a table n
times if you want to select or filter on n
different attributes. That gets slow rather slow and becomes rather hard to optimize relatively quickly.
此外,您通常最终会构建数据库或ORM将提供的许多功能.
Plus, you generally end up building a lot of functionality that the database or your ORM would provide.
这篇关于数据库设计可动态创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!