sql server 上的alter table switch 如何工作? [英] How does alter table switch works on sql server?

查看:57
本文介绍了sql server 上的alter table switch 如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有时在 SQL Server 2008 上使用 switch 表在 2 个表之间快速传输数据,但我不知道它是如何工作的,这与只是一个 insert into T2 select * from T1<有什么区别/代码>.

I am using switch table sometime on SQL Server 2008 to transfer quickly data between 2 tables, but I do not know how it works, and what's the difference between this an just a insert into T2 select * from T1.

谁能详细解释一下它的工作原理和区别?

Someone can explain in detail how it works and the difference?

此外,我注意到如果两个表都不是克隆的,则此语句不起作用.例如,如果我在一张表中有一个索引,而在另一张表中没有,它就会失败.

Furthermore I notice that if both tables are not clones this statement does not work. For example if I have one index in one table and not in the other one it fails.

推荐答案

使用语句插入数据

insert into T2 select * from T1

通过将数据从 T1 插入到 T2 来加载数据.当一个分区被传输(切换)时,数据并没有被物理移动;只有关于数据位置的元数据发生变化.

Loads data by inserting data from T1 into T2. When a partition is transferred (switched), the data is not physically moved; only the metadata about the location of the data changes.

在切换分区之前,必须满足几个一般要求:

Before you can switch partitions, several general requirements must be met:

切换分区的一般要求:

当一个分区被转移时,数据并没有被物理移动;只有有关数据位置的元数据发生变化.在您可以切换分区之前,必须满足几个一般要求:

When a partition is transferred, the data is not physically moved; only the metadata about the location of the data changes. Before you can switch partitions, several general requirements must be met:

  1. 在 SWITCH 操作之前,两个表都必须存在.在执行切换操作之前,要从中移动分区的表(源表)和接收分区的表(目标表)必须存在于数据库中.
  2. 接收分区必须存在且必须为空.无论您是将表作为分区添加到已存在的分区表,还是将分区从一个分区表移动到另一个分区,接收新分区的分区必须存在并且必须是空分区.
  3. 接收非分区表必须存在且必须为空.如果您要重新分配一个分区以形成一个非分区表,则接收新分区的表必须存在并且它必须是一个空的非分区表.
  4. 分区必须在同一列上.如果您要将一个分区从一个分区表切换到另一个分区,则两个表必须在同一列上进行分区.
  5. 源表和目标表必须共享同一个文件组.ALTER TABLE...SWITCH 语句的源表和目标表必须位于同一个文件组中,并且它们的大值列必须存储在同一个文件组中.任何相应的索引、索引分区或索引视图分区也必须驻留在同一文件组中.但是,文件组可以与相应表或其他相应索引的文件组不同.

此信息及更多信息位于此处:

This info and more is located here:

https://technet.microsoft.com/en-us/library/ms191160(v=sql.105).aspx

这篇关于sql server 上的alter table switch 如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆