Home Database Mysql Tutorial 分区表的基本操作

分区表的基本操作

Jun 07, 2016 pm 03:55 PM
one time Partition Table Basic operations Example Simple Record

分区表的基本操作,简单记录一下~~~ 实例: SQL create table t_part (id int,col2 int,col3 int) 2 partition by range (id) 3 ( 4 partition p1 values less than (10000), 5 partition p2 values less than (20000), 6 partition p3 values less than (300

分区表的基本操作,简单记录一下~~~
实例:
SQL> create table t_part (id int,col2 int,col3 int)
2 partition by range (id)
3 (
4 partition p1 values less than (10000),
5 partition p2 values less than (20000),
6 partition p3 values less than (30000),
7 partition p4 values less than (40000),
8 partition p5 values less than (50000),
9 partition p6 values less than (60000),
10 partition p7 values less than (70000),
11 partition p8 values less than (80000),
12 partition p9 values less than (90000),
13 partition p10 values less than (100000),
14 partition p11 values less than (110000),
15 partition p12 values less than (maxvalue)
16 );

Table created.

SQL> insert into t_part select rownum,rownum+1,rownum+2 from dual connect by rownum
149999 rows created.

SQL> commit;

Commit complete.

1、分区清除,分区删除
alter table [partiontion_tablename] drop/truncate partition [partitionname];

SQL> alter table t_part drop partition p1;

Table altered.

SQL> alter table t_part truncate partition p2;

Table truncated.

2、增加分区
alter table [partiontion_tablename] add partition [partitionname] values less than (120000);
在分区有maxvalue时会报一下错误,需要先把maxvalue分区的数据分区交换到一个中间表,drop 掉该分区之后,新建分区,最后把改中间表的数据重新插入该分区表。
ERROR at line 1:
ORA-14074: partition bound must collate higher than that of the last partition

SQL> alter table t_part add partition p12 values less than (120000);

Table altered.

3、分区交换:
alter table [partiontion_tablename] exchange partition [partitionname] with table [tablename];

SQL> create table t_norm (id int,col2 int,col3 int);

Table created.

SQL> select count(*) from t_part partition(p12);

COUNT(*)
----------
40000

SQL> alter table t_part exchange partition p12 with table t_norm;

Table altered.

SQL> select count(*) from t_part partition(p12);

COUNT(*)
----------
0

SQL> select count(*) from t_norm;

COUNT(*)
----------
40000

同理,我们可以把t_norm表的数据交换到p12分区中。
SQL> alter table t_part exchange partition p12 with table t_norm;

Table altered.

SQL> select count(*) from t_part partition(p12);

COUNT(*)
----------
40000

SQL> select count(*) from t_norm;

COUNT(*)
----------
0

4、分区切割
alter table [partiontion_tablename] split partition [partitionname] at ([values]) into (partition [partitionname1],partition [partitionname2]); --partitionname1,2是一分为二后新的名字

SQL> alter table t_part rename partition p12 to pmax;

Table altered.

SQL> select count(*) from t_part partition (pmax);

COUNT(*)
----------
40000

SQL> alter table t_part split partition pmax at (120000) into (partition p12,partition pmax);

Table altered.

SQL> select count(*) from t_part partition(p12);

COUNT(*)
----------
10000

SQL> select count(*) from t_part partition (pmax);

COUNT(*)
----------
30000

5、分区合并
alter table [partiontion_tablename] merge partitions [partitionname1],[partitionname2] into partition [partitionname_new];

SQL> alter table t_part merge partitions p12,pmax into partition pmax;

Table altered.

SQL> select count(*) from t_part partition (pmax);

COUNT(*)
----------
40000
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 Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

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)

The easiest way to query the hard drive serial number The easiest way to query the hard drive serial number Feb 26, 2024 pm 02:24 PM

The hard disk serial number is an important identifier of the hard disk and is usually used to uniquely identify the hard disk and identify the hardware. In some cases, we may need to query the hard drive serial number, such as when installing an operating system, finding the correct device driver, or performing hard drive repairs. This article will introduce some simple methods to help you check the hard drive serial number. Method 1: Use Windows Command Prompt to open the command prompt. In Windows system, press Win+R keys, enter "cmd" and press Enter key to open the command

Where can I view the records of things I have purchased on Pinduoduo? How to view the records of purchased products? Where can I view the records of things I have purchased on Pinduoduo? How to view the records of purchased products? Mar 12, 2024 pm 07:20 PM

Pinduoduo software provides a lot of good products, you can buy them anytime and anywhere, and the quality of each product is strictly controlled, every product is genuine, and there are many preferential shopping discounts, allowing everyone to shop online Simply can not stop. Enter your mobile phone number to log in online, add multiple delivery addresses and contact information online, and check the latest logistics trends at any time. Product sections of different categories are open, search and swipe up and down to purchase and place orders, and experience convenience without leaving home. With the online shopping service, you can also view all purchase records, including the goods you have purchased, and receive dozens of shopping red envelopes and coupons for free. Now the editor has provided Pinduoduo users with a detailed online way to view purchased product records. method. 1. Open your phone and click on the Pinduoduo icon.

How to view and manage Linux command history How to view and manage Linux command history Aug 01, 2023 pm 09:17 PM

How to View Command History in Linux In Linux, we use the history command to view the list of all previously executed commands. It has a very simple syntax: history Some options for pairing with the history command include: Option description -c clears the command history for the current session -w writes the command history to a file -r reloads the command history from the history file -n Limit the number of output of recent commands Simply run the history command to see a list of all previously executed commands in a Linux terminal: In addition to viewing command history, you can also manage command history and perform modifications to previously executed commands , reverse search command history or even delete history completely

How to write a simple online reservation system through PHP How to write a simple online reservation system through PHP Sep 26, 2023 pm 09:55 PM

How to write a simple online reservation system through PHP. With the popularity of the Internet and users' pursuit of convenience, online reservation systems are becoming more and more popular. Whether it is a restaurant, hospital, beauty salon or other service industry, a simple online reservation system can improve efficiency and provide users with a better service experience. This article will introduce how to use PHP to write a simple online reservation system and provide specific code examples. Create database and tables First, we need to create a database to store reservation information. In MyS

How to write a simple student performance report generator using Java? How to write a simple student performance report generator using Java? Nov 03, 2023 pm 02:57 PM

How to write a simple student performance report generator using Java? Student Performance Report Generator is a tool that helps teachers or educators quickly generate student performance reports. This article will introduce how to use Java to write a simple student performance report generator. First, we need to define the student object and student grade object. The student object contains basic information such as the student's name and student number, while the student score object contains information such as the student's subject scores and average grade. The following is the definition of a simple student object: public

Quick Start: Use Go language functions to implement a simple library management system Quick Start: Use Go language functions to implement a simple library management system Jul 30, 2023 am 09:18 AM

Quick Start: Implementing a Simple Library Management System Using Go Language Functions Introduction: With the continuous development of the field of computer science, the needs of software applications are becoming more and more diverse. As a common management tool, the library management system has also become one of the necessary systems for many libraries, schools and enterprises. In this article, we will use Go language functions to implement a simple library management system. Through this example, readers can learn the basic usage of functions in Go language and how to build a practical program. 1. Design ideas: Let’s first

How to check call history in iPhone and export it? How to check call history in iPhone and export it? Jul 05, 2023 pm 12:54 PM

Call recording in iPhone is often underestimated and is one of the most critical features of iPhone. With its simplicity, this feature is of vital importance and can provide important insights about the calls made or received on the device. Whether for work purposes or legal proceedings, the ability to access call records can prove invaluable. In simple terms, call history refers to the entries created on your iPhone whenever you make or receive a call. These logs contain key information, including the contact's name (or number if not saved as a contact), timestamp, duration, and call status (dialed, missed, or not answered). They are a concise record of your communication history. Call history includes call history strips stored on your iPhone

C# Development Advice: Logging and Monitoring Systems C# Development Advice: Logging and Monitoring Systems Nov 22, 2023 pm 08:30 PM

C# Development Suggestions: Logging and Monitoring System Summary: In the software development process, logging and monitoring systems are crucial tools. This article will introduce the role and implementation suggestions of logging and monitoring systems in C# development. Introduction: Logging and monitoring are essential tools in large-scale software development projects. They can help us understand the running status of the program in real time and quickly discover and solve problems. This article will discuss how to use logging and monitoring systems in C# development to improve software quality and development efficiency. The role of logging system

See all articles