Home Database Mysql Tutorial 为sql server进行表分区

为sql server进行表分区

Jun 07, 2016 pm 05:38 PM
server Partition conduct

为sql server进行表分区 最近项目中数据量超过的千万级别,一个普通单表查询也慢的要命,对客户来说长时间的等待是不能容忍的。于是想尽各种办法对数据库进行优化,包括索引,单表查询等等。但结果都不近人意。最终选择对单表进行分区。经过测试,效率确实提

为sql server进行表分区

    最近项目中数据量超过的千万级别,一个普通单表查询也慢的要命,,对客户来说长时间的等待是不能容忍的。于是想尽各种办法对数据库进行优化,包括索引,单表查询等等。但结果都不近人意。最终选择对单表进行分区。经过测试,效率确实提高了不少。

     创建分区表一般包括四个步骤。

    1:为分区创建文件组和文件

    2:设计分区函数

    3:设计分区架构

    4:创建分区表

  (1) 创建文件组和文件可以用sql创建,也可以通过管理工具创建具体方法如下:

    1:管理工具:

      打开Management Studio,选择要操作的数据库右键-属性-文件/文件组。根据相应的提示创建即可

    2:通过sql创建

     创建文件组:ALTER DATABASE Mytest ADD FILEGROUP MytestFileGroup  ,其中Mytest是当前操作的数据库,MytestFileGroup是文件组名称

     创建文集并将文件添加到文件组:

     ALTER DATABASE Mytest ADD FILE

      (
          FILEGROWTH=1MB,
          NAME='Mytest0' ,
          FILENAME='C:\data\Mytest0.NDF',
          SIZE=3MB
      )TO FILEGROUP MytestFileGroup

     通过一上操作,我们已经创建了一个名为MytestFileGroup的文件组以及文件组下面的文件Mytest0.NDF,文件的存放位置在c盘的data文件夹下。可以将不同文件存放   在不同的磁盘下面,这样可以提高IO效率,增加查询速度。

  (2) 创建完成文件组和文件之后我们便可以设计分区函数了。直接上sql:

      CREATE PARTITION FUNCTION MytestPartFunction (INT)
      AS RANGE RIGHT
      FOR VALUES
      (2000000,4000000,6000000,8000000,10000000,12000000,14000000,16000000,18000000,20000000)

      其中MytestPartFunction是函数名称。RANGE RIGHT表示分区的边界处理方式,这里RIGHT表示以右边界为准,既边界值分到右边的分区中。

    分区依据是根据INT类型的值。

  

  (3)创建完分区函数后,就要进行分区架构设计了。分区架构根据分区函数将不同的分区对应到不同的文件组。以达到不同分区数据存放到不同文件。分区架构代码如下:

      CREATE PARTITION SCHEME MytestPartFunction
      AS PARTITION MytestPartFunction
      TO

(MytestFileGroup0,MytestFileGroup1,MytestFileGroup2,MytestFileGroup3,MytestFileGroup4,MMytestFileGroup5,MytestFileGroup6,MytestFileGroup7,MytestFileGroup8,MytestFileGroup9,MytestFileGroup10)

     MytestPartFunction 是分区架构名称。MytestPartFunction是刚刚创建的分区函数名称,这里表示分区架构是以该函数进行分区。后面的MytestFileGroup0-MytestFileGroup10分别代表将不同的区域内的数据存放到不同的文件组。

  (4)   创建完成分区函数和分区架构之后,就可以创建分区表了。创建分区表跟创建普通的表差不多。这里用代码实现如下:
    create table UserInfo (
       ID                   int                  identity,
       UserCode             nvarchar(50)         not null,

     UserName  nvarchar(50)         not null
    ) ON MytestPartFunction(ID)

    后面的MytestPartFunction就是分区架构。其中括号中的ID表示以ID作为分区依据。

  

  这样一个完整的分区表就完成了。其中有些细节没有说明。以后慢慢完善吧。本人对数据库了解的不太多,大部分东西都是从网上现找的,可能其中有些不足。恳请大家指正。

 

posted on

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solve the problem that the reserved partition of win11 system cannot be updated Solve the problem that the reserved partition of win11 system cannot be updated Dec 26, 2023 pm 12:41 PM

After updating win11, some users encountered the problem that the partition reserved by the system cannot be updated, resulting in the inability to download more new software. So today I brought you the solution to the partition reserved by the system cannot be updated by win11. Come and download it together. Try it. What to do if win11 cannot update the partition reserved by the system: 1. First, right-click the start menu button below. 2. Then right-click the menu and click Run. 3. During operation, enter: diskmgmt.msc and press Enter. 4. You can then enter the system disk and check the EFI system partition to see if the space is less than 300M. 5. If it is too small, you can download a tool to change the system reserved partition to larger than 300MB. 450M is recommended.

How to install, uninstall, and reset Windows server backup How to install, uninstall, and reset Windows server backup Mar 06, 2024 am 10:37 AM

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

[Linux system] fdisk related partition commands. [Linux system] fdisk related partition commands. Feb 19, 2024 pm 06:00 PM

fdisk is a commonly used Linux command line tool used to create, manage and modify disk partitions. The following are some commonly used fdisk commands: Display disk partition information: fdisk-l This command will display the partition information of all disks in the system. Select the disk you want to operate: fdisk/dev/sdX Replace /dev/sdX with the actual disk device name you want to operate, such as /dev/sda. Create new partition:nThis will guide you to create a new partition. Follow the prompts to enter the partition type, starting sector, size and other information. Delete Partition:d This will guide you to select the partition you want to delete. Follow the prompts to select the partition number to be deleted. Modify Partition Type: This will guide you to select the partition you want to modify the type of. According to mention

Solution to the problem of unable to partition after win10 installation Solution to the problem of unable to partition after win10 installation Jan 02, 2024 am 09:17 AM

When we reinstalled the win10 operating system, when it came to the disk partitioning step, we found that the system prompted that a new partition could not be created and the existing partition could not be found. In this case, I think you can try to reformat the entire hard disk and reinstall the system to partition, or reinstall the system through software, etc. Let’s see how the editor did it for the specific content~ I hope it can help you. What to do if you cannot create a new partition after installing win10. Method 1: Format the entire hard disk and repartition it or try plugging and unplugging the USB flash drive several times and refreshing it. If there is no important data on your hard disk, when it comes to the partitioning step, delete all the data on the hard disk. Partitions are deleted. Reformat the entire hard drive, then repartition it, and then install it normally. Method 2: P

Detailed explanation of how to set up Linux Opt partition Detailed explanation of how to set up Linux Opt partition Mar 20, 2024 am 11:30 AM

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.

How to increase WinRE partition size in Windows 11 How to increase WinRE partition size in Windows 11 Feb 19, 2024 pm 06:06 PM

In this article, we will show you how to change or increase WinRE partition size in Windows 11/10. Microsoft will now update Windows Recovery Environment (WinRE) alongside monthly cumulative updates, starting with Windows 11 version 22H2. However, not all computers have a recovery partition large enough to accommodate the new updates, which can cause error messages to appear. Windows Recovery Environment Service Failed How to Increase WinRE Partition Size in Windows 11 To increase WinRE partition size manually on your computer, follow the steps mentioned below. Check and disable WinRE Shrink OS partition Create new recovery partition Confirm partition and enable WinRE

Integer calculation solution for win10 partition defragmentation Integer calculation solution for win10 partition defragmentation Dec 30, 2023 pm 07:41 PM

When partitioning Windows, if you simply enter the calculated value as 1GB=1024MB, you will always get a result like 259.5GB/59.99GB/60.01GB instead of an integer. So how is the integer calculated for the win10 partition? Woolen cloth? Let’s take a look with the editor below. The formula for calculating the integer of win10 partition: 1. The formula is: (X-1)×4+1024×X=Y. 2. If you want to get the integer partition of Windows, you must know a formula. The value calculated through this formula can be recognized by Windows as an integer GB value. 3. Among them, X is the value of the integer partition you want to get, the unit is GB, and Y is the number that should be entered when partitioning.

Deepin Linux hard disk partitioning and installation tutorial: step by step to achieve efficient system deployment Deepin Linux hard disk partitioning and installation tutorial: step by step to achieve efficient system deployment Feb 10, 2024 pm 07:06 PM

Before installing Deepin Linux, we need to partition the hard disk. Hard disk partitioning is the process of dividing a physical hard disk into multiple logical areas. Each area can be used and managed independently. The correct partitioning method can improve the performance and performance of the system. Stability, so this step is very important. This article will provide you with detailed and in-depth Linux hard disk partitioning and installation tutorials. Preparation 1. Make sure you have backed up important data, as the partitioning process will erase all data on the hard drive. 2. Prepare a Deepin Linux installation media, such as a USB flash drive or CD. Hard disk partition 1. Boot into the BIOS settings and set the boot media as the preferred boot device. 2. Restart the computer and boot from the boot media to enter the system installation interface. 3.Select

See all articles