简体   繁体   中英

Sql Server 2008 partition table based on insert date

My question is about table partitioning in SQL Server 2008.

I have a program that loads data into a table every 10 mins or so. Approx 40 million rows per day.

The data is bcp'ed into the table and needs to be able to be loaded very quickly.

I would like to partition this table based on the date the data is inserted into the table. Each partition would contain the data loaded in one particular day.

The table should hold the last 50 days of data, so every night I need to drop any partitions older than 50 days.

I would like to have a process that aggregates data loaded into the current partition every hour into some aggregation tables. The summary will only ever run on the latest partition (since all other partitions will already be summarised) so it is important it is partitioned on insert_date.

Generally when querying the data, the insert date is specified (or multiple insert dates). The detailed data is queried by drilling down from the summarised data and as this is summarised based on insert date, the insert date is always specified when querying the detailed data in the partitioned table.

Can I create a default column in the table "Insert_date" that gets a value of Getdate() and then partition on this somehow?

OR

I can create a column in the table "insert_date" and put a hard coded value of today's date.

What would the partition function look like?

Would seperate tables and a partitioned view be better suited?

I have tried both, and even though I think partition tables are cooler. But after trying to teach how to maintain the code afterwards it just wasten't justified. In that scenario we used a hard coded field date field that was in the insert statement.

Now I use different tables ( 31 days / 31 tables ) + aggrigation table and there is an ugly union all query that joins togeather the monthly data. Advantage. Super timple sql, and simple c# code for bcp and nobody has complained about complexity.

But if you have the infrastructure and a gaggle of .net / sql gurus I would choose the partitioning strategy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM