SQL Server 自动化管理分区设计方案
一、设计说明 设计这个自动化的目的是想要交替、重复地使用固定的几个分区(分区编号01~05)来保存数据,当最后一个分区就是快满的时候,我们会把最旧数据的分区的数据清空出分区,新数据就可以使用老分区空间了。 应用这个自动化管理分区的环境是有些限制的,
一、设计说明
设计这个自动化的目的是想要交替、重复地使用固定的几个分区(分区编号01~05)来保存数据,当最后一个分区就是快满的时候,我们会把最旧数据的分区的数据清空出分区,新数据就可以使用老分区空间了。
应用这个自动化管理分区的环境是有些限制的,其一:分区的数据是呈现递增的,比如分区字段是自增Id值,或者是以日期作为分区;其二:可以接受 历史数据被移除分区表带来的问题。其三:一天进库的数量不应大于分区管理表PartitionManage中Part_Value与 Change_Value的差,因为我们作业执行的频率是1天,不过你可以调整Change_Value或者作业的执行频率;
具体脚本可以参考:SQL Server 2005 自动化删除表分区设计方案
二、看图说话
(图1:整体概念图)
数据流经过分区方案,被分配到不同的分区中,从图中可以看出,分区是可以重复利用的,后台有一个所谓的自动化切换分区的作业在跑,目的就是如果 重复利用这些分区。这里的PRIMARY目的就是说明它与其它文件组的一个平级关系,而且我们在做交换分区时候也会用到PRIMARY,需要事先分配足够 的空间。
(图2:自动化设计图)
这是自动化切换分区作业的逻辑处理,其中分区管理表的设计是比较重要的,它的灵活度关系到整个自动化的效果; 这个逻辑有以下几个特点:
1. 分区的索引进行存储位置对齐;其它索引在创建时就使用了分区方案,索引数据跟随分区数据一起存储在分区中;
2. 分区管理表,包含了分区记录数预警设计,在Id达到这个值后就会进行交换分区;
3. 分区管理表,FileGroup_String字段的数据可以通过SQL脚本自动化生成,条件就是分区文件组名称需要有规律;
4. 临时表是创建在PRIMARY主分区上,跟原表使用相同的分区方案;需要事先给PRIMARY分配大于或者等于一个分区文件大小的空间,这样在交换分区的时候就不用增量为主分区分配数据空间;
5. 交换旧数据到临时表,使用下面的语句可以把数据交换到相同的分区中编号,这样可以应对临时表就是一个历史表,而好处就是历史表也同样使用了分区。
ALTER TABLE [tb] SWITCH PARTITION @PARTITION_num TO [Temp_tb] PARTITION@PARTITION_num
6. 这里需要先修改分区方案,才能修改分区函数,这个跟创建分区函数与分区方案的顺序是刚好相反的。
(图3:分区管理表PartitionManage)
字段说明:Change_Value(预警Id值)Part_Value(分区函数值)FileGroup_String(分区文件组名称)IsDone(状态)UpdateTime(更新时间);
这就是那个分区管理表(PartitionManage),它是经过了几个版本后才把字段确定下来的,现在它已经比较完善了,能应对比较多的情况:
1. 比如我们可以修改预警值(Change_Value),让数据提早进入交换分区;
2. 比如我们可以修改分区值(Part_Value),达到调整分区间隔的目的;
3. 比如我们可以修改分区文件组名称(FileGroup_String),达到跳级文件组的目的;通过修改分区管理表来设置分区值与分区文件组的对应关系;
4. 再比如,我们一次性修改了分区方案和分区函数,已经去到很后面的分区值了,那么我们只要设置这些分区值的状态(IsDone)为1(True)就可以解决了。
5. 记录了进行交换分区的时间(UpdateTime),方便查询;
(图4:分区为Id字段的记录分布图)
这是一个实战中的分区情况,这样的分区特点就是分区里面的记录数基本上是持平的,,在Partition_num=20的记录中明显多了很多记录,这就是因为我们没有及时进行交换分区造成的。
(图5:分区为ClassId(分类)字段的记录分布图)
这同样是另外一个生产环境中的真实数据,这个分区方式的特点就是分区的记录数不太均等,而我们前期需要做的就是通过划分每个分区中ClassId的值来尽量均衡分区中的记录数,所以可以看到最小与最大值跨度区别是比较大。
(来源:博客园 作者:听风吹雨)

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

According to news on April 17, HMD teamed up with the well-known beer brand Heineken and the creative company Bodega to launch a unique flip phone - The Boring Phone. This phone is not only full of innovation in design, but also returns to nature in terms of functionality, aiming to lead people back to real interpersonal interactions and enjoy the pure time of drinking with friends. Boring mobile phone adopts a unique transparent flip design, showing a simple yet elegant aesthetic. It is equipped with a 2.8-inch QVGA display inside and a 1.77-inch display outside, providing users with a basic visual interaction experience. In terms of photography, although it is only equipped with a 30-megapixel camera, it is enough to handle simple daily tasks.

According to news on April 26, ZTE’s 5G portable Wi-Fi U50S is now officially on sale, starting at 899 yuan. In terms of appearance design, ZTE U50S Portable Wi-Fi is simple and stylish, easy to hold and pack. Its size is 159/73/18mm and is easy to carry, allowing you to enjoy 5G high-speed network anytime and anywhere, achieving an unimpeded mobile office and entertainment experience. ZTE 5G portable Wi-Fi U50S supports the advanced Wi-Fi 6 protocol with a peak rate of up to 1800Mbps. It relies on the Snapdragon X55 high-performance 5G platform to provide users with an extremely fast network experience. Not only does it support the 5G dual-mode SA+NSA network environment and Sub-6GHz frequency band, the measured network speed can even reach an astonishing 500Mbps, which is easily satisfactory.

According to news on April 3, Taipower’s upcoming M50 Mini tablet computer is a device with rich functions and powerful performance. This new 8-inch small tablet is equipped with an 8.7-inch IPS screen, providing users with an excellent visual experience. Its metal body design is not only beautiful but also enhances the durability of the device. In terms of performance, the M50Mini is equipped with the Unisoc T606 eight-core processor, which has two A75 cores and six A55 cores, ensuring a smooth and efficient running experience. At the same time, the tablet is also equipped with a 6GB+128GB storage solution and supports 8GB memory expansion, which meets users’ needs for storage and multi-tasking. In terms of battery life, M50Mini is equipped with a 5000mAh battery and supports Ty

According to news on July 12, the Honor Magic V3 series was officially released today, equipped with the new Honor Vision Soothing Oasis eye protection screen. While the screen itself has high specifications and high quality, it also pioneered the introduction of AI active eye protection technology. It is reported that the traditional way to alleviate myopia is "myopia glasses". The power of myopia glasses is evenly distributed to ensure that the central area of sight is imaged on the retina, but the peripheral area is imaged behind the retina. The retina senses that the image is behind, promoting the eye axis direction. grow later, thereby deepening the degree. At present, one of the main ways to alleviate the development of myopia is the "defocus lens". The central area has a normal power, and the peripheral area is adjusted through optical design partitions, so that the image in the peripheral area falls in front of the retina.

At work, ppt is an office software often used by professionals. A complete ppt must have a good ending page. Different professional requirements give different ppt production characteristics. Regarding the production of the end page, how can we design it more attractively? Let’s take a look at how to design the end page of ppt! The design of the ppt end page can be adjusted in terms of text and animation, and you can choose a simple or dazzling style according to your needs. Next, we will focus on how to use innovative expression methods to create a ppt end page that meets the requirements. So let’s start today’s tutorial. 1. For the production of the end page, any text in the picture can be used. The important thing about the end page is that it means that my presentation is over. 2. In addition to these words,

How to set up the Linux Opt partition and code examples In Linux systems, the Opt partition is usually used to store optional software packages and application data. Properly setting the Opt partition can effectively manage system resources and avoid problems such as insufficient disk space. This article will detail how to set up a LinuxOpt partition and provide specific code examples. 1. Determine the partition space size. First, we need to determine the space size required for the Opt partition. It is generally recommended to set the size of the Opt partition to 5%-1 of the total system space.

According to news on July 19, Xiaomi MIX Fold 4, the first flagship folding new phone, was officially released tonight and is equipped with a "three-dimensional special-shaped battery" for the first time. According to reports, Xiaomi MIX Fold4 has achieved a major breakthrough in battery technology and designed an innovative "three-dimensional special-shaped battery" specifically for folding screens. Traditional folding screen devices mostly use conventional square batteries, which have low space utilization efficiency. In order to solve this problem, Xiaomi did not use the common winding battery cells, but developed a new lamination process to create a new form of battery, which greatly improved the space utilization. Battery Technology Innovation In order to accurately alternately stack positive and negative electrode sheets and ensure the safe embedding of lithium ions, Xiaomi has developed a new ultrasonic welding machine and lamination machine to improve welding and cutting accuracy.

According to news on March 22, Coolpad launched two new phones, Coolpad Grand View 3 and 3Plus, all of which support 5G networks. According to reports, the new machine adopts "grating mold lamination technology" and can provide a "multi-dimensional interactive experience" through AI image processing algorithms. This model also has a "SmartTouch naked-eye 3D module" that can increase the screen light transmittance to more than 97%. Paired with an algorithm engine, it can achieve "real-time smart pupil tracking", "automatically adjust and optimize calibration parameters, automatically compensate for optical accuracy, and reduce the cost of naked-eye 3D production." In terms of hardware, both Coolpad Grand View 3 and 3Plus are equipped with
