每年创建一个新的数据库表

时间:2021-08-31 13:59:03

I must create a new application based on an existing Excel application that uses a big database. For the new application I will use Microsoft Web Developer (VB.NET). The Excel application handles some orders and some data related to those orders.

我必须基于使用大型数据库的现有Excel应用程序创建新的应用程序。对于新的应用程序,我将使用Microsoft Web Developer(VB.NET)。 Excel应用程序处理一些订单和一些与这些订单相关的数据。

Because it is a big database, I need to create programmatically a table for every year. For example: orders from 2013 will be in Orders_2013, orders from 2014 will be in Orders_2014 and so on ... But my new application should be able to search in all the tables; if I search for an order that from 2012 and now is 2013 the application should be able to search in the specific database table.

因为它是一个大型数据库,所以我需要以编程方式为每年创建一个表。例如:2013年的订单将在Orders_2013中,2014年的订单将在Orders_2014中等等......但是我的新应用程序应该能够搜索所有表格;如果我搜索从2012年到现在是2013年的订单,应用程序应该能够在特定的数据库表中进行搜索。

I must use the old database structure, and that is kind of a setback. If I create a new database structure I must be able to import everything from the old database.

我必须使用旧的数据库结构,这是一种挫折。如果我创建一个新的数据库结构,我必须能够从旧数据库导入所有内容。

I need some guidance on how to build the application to create a new database, for every year.

每年我都需要一些关于如何构建应用程序以创建新数据库的指导。

I read something about SQL Management Studio, that I can use a task to create a script, for generating a new table every year, but I have not been able to create one so far. I will keep searching, but if someone knows what I'm looking for, please share that info.

我读了一些关于SQL Management Studio的内容,我可以使用任务来创建脚本,每年生成一个新表,但到目前为止我还没能创建一个。我会继续搜索,但如果有人知道我在找什么,请分享这些信息。

1 个解决方案

#1


2  

Let me start by saying that I would advocate a single table design, while employing views to maintain backward compatibility. I am going to assume that you have your hands tied and cannot modify your table structure at all and hence unable to use a singe table.

首先我要说的是,我会提倡单表设计,同时使用视图来保持向后兼容性。我将假设你的双手绑在一起,根本无法修改你的桌子结构,因此无法使用单个桌子。

In SQL Management Studio, you can create one of the yearly table in "Design View". Once done, you can right-click on the table and have it generate a CREATE TABLE script, which you can execute every year, with a different table name. I don't know if the SQL Management Studio can schedule it, but I would simple do it myself since its only once per year.

在SQL Management Studio中,您可以在“设计视图”中创建一个年度表。完成后,您可以右键单击该表并让它生成一个CREATE TABLE脚本,您可以使用不同的表名每年执行该脚本。我不知道SQL Management Studio是否可以安排它,但我自己每年只做一次就可以很简单。

As for the unified search, you can create a view which is a union of all the year specific tables and search over that. This way you will only have to modify only the search component to work with the new view. However, you will also have to update this view every year as well, which should be pretty simple.

对于统一搜索,您可以创建一个视图,该视图是所有特定年份表的联合并搜索该视图。这样,您只需要修改搜索组件即可使用新视图。但是,您还必须每年更新此视图,这应该非常简单。

#1


2  

Let me start by saying that I would advocate a single table design, while employing views to maintain backward compatibility. I am going to assume that you have your hands tied and cannot modify your table structure at all and hence unable to use a singe table.

首先我要说的是,我会提倡单表设计,同时使用视图来保持向后兼容性。我将假设你的双手绑在一起,根本无法修改你的桌子结构,因此无法使用单个桌子。

In SQL Management Studio, you can create one of the yearly table in "Design View". Once done, you can right-click on the table and have it generate a CREATE TABLE script, which you can execute every year, with a different table name. I don't know if the SQL Management Studio can schedule it, but I would simple do it myself since its only once per year.

在SQL Management Studio中,您可以在“设计视图”中创建一个年度表。完成后,您可以右键单击该表并让它生成一个CREATE TABLE脚本,您可以使用不同的表名每年执行该脚本。我不知道SQL Management Studio是否可以安排它,但我自己每年只做一次就可以很简单。

As for the unified search, you can create a view which is a union of all the year specific tables and search over that. This way you will only have to modify only the search component to work with the new view. However, you will also have to update this view every year as well, which should be pretty simple.

对于统一搜索,您可以创建一个视图,该视图是所有特定年份表的联合并搜索该视图。这样,您只需要修改搜索组件即可使用新视图。但是,您还必须每年更新此视图,这应该非常简单。