在运行时动态创建表 [英] Creating tables dynamically at runtime

查看:118
本文介绍了在运行时动态创建表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行时根据用户的互动动态创建一个表,一个好的还是坏的一个web应用程序? (我在说java,但问题可能适用于更多)。

解决方案

表对于用户与数据库。因此,没有桌子是致命的。



从这一点开始,在运行时,即时创建表是一个不好的做法,因为这意味着不能保证用户的体验。如果CREATE TABLE语句失败,无论什么原因,填充用户。



所以,避免依赖于表的运行时创建的业务流程是个好主意。除非在特定情况下,通常还有解决方法。



在某种程度上这取决于支持应用程序的RDBMS的风格。例如,Oracle具有全局临时表的概念,它在几乎所有情况下都会删除动态表创建的调用。但是,即使没有这样的花哨功能,通常也可以使用它:例如,将USERNAME列添加到表中,并在其上构建视图,其中包含WHERE子句过滤 USERNAME = USER



基本上,DDL在经过的时间和系统资源方面执行成本高昂。它创建事务复杂性。而且有风险:如果失败,则用户无法继续。所以因为所有这些原因,应该避免。


Is creating a table dynamically at runtime based on a user's interactions a good or bad thing for a web-app? (I'm talking java, but question probably applies to more).

解决方案

Tables are generally crucial to a user's interaction with the database. Consequently the absence of tables is fatal.

From this it follows, that creating tables on the fly, at runtime, is a bad practice because it means there is no guarantee of the user's experience. If a CREATE TABLE statement fails, for whatever reason, the user is stuffed.

So, it is q good idea to avoid business processes which rely on the runtime creation of tables. There are usually workarounds, except in very specific circumstances.

To a certain extent this depends on the flavour of RDBMS underpinning the application. For instance, Oracle has the concept of Global Temporary Tables which removes the call for dynamic table creation in almost all circumstances. But even without such fancy features, there are usually ways around it: for instance, adding A USERNAME column to a table and building a view on top of it which includes a WHERE clause filtering on USERNAME=USER.

Basically, DDL is expensive to execute, in terms of elapsed time and system resource. It creates transactional complexity. And it is risky: if it fails then the user cannot proceed. So for all these reasons it should be avoided.

这篇关于在运行时动态创建表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆