Partition table的switch条件2:Partition 的隐式Check约束 和Nullability

Partition column允许为Null,Null是最小值,存在于Partition Number=1的partition中。

Any data with a NULL in the partition column will reside in the leftmost partition. NULL is considered smaller than the minimum value of the data type’s values.

Partition Function 定义了Partition column在每一个分区的value range,这种value range就像每一个Partition的数据都有一个check 约束,用于限定Partition column的取值范围。

Partition Number=1,Partition column允许存在null;

其他Partition,Partition column不允许存在null。

在check 约束中,如果出现Unknown,Check约束视为True。例如 constraint CK__TableName_ID check(ID>1 and ID<10), 如果ID=Null,那么表达式ID>1 and ID<10 返回Unknown(或null),Check约束逻辑运算的结果是True,即不违反check约束。

1,创建实例数据

-- create parition function
CREATE PARTITION FUNCTION pf_int_Left (int)
AS
RANGE LEFT
FOR VALUES (10,20);

--create partition scheme
CREATE PARTITION SCHEME PS_int_Left
AS
PARTITION pf_int_Left
TO ([primary], [primary], [primary]);

--create partitioned table
create table dbo.dt_partition
(
ID int,
Code int
)
on PS_int_Left (ID)

--Create staging table
create table dbo.dt_SwitchStaging
(
ID int,
Code int
)
on [primary]

--insert data into dbo.dt_partition
insert into dbo.dt_partition
(
ID,
Code
)
values(15,2),(1,1)

2,将partition 2的数据switch 到 dbo.dt_SwitchStaging

--swith partition 2 to staging table
alter table dbo.dt_partition
switch partition 2
to dbo.dt_SwitchStaging

将staging table中的数据swith into partition 2

--switch staging table to partition 2
alter table dbo.dt_SwitchStaging
switch
to dbo.dt_partition partition 2

Msg 4982, Level 16, State 1, Line 2
ALTER TABLE SWITCH statement failed. Check constraints of source table ‘DB_Study.dbo.dt_SwitchStaging‘ allow values that are not allowed by range defined by partition 2 on target table ‘DB_Study.dbo.dt_partition‘.

为staging table增加check 约束,partition 2的value range是 ID>10 and ID<=20。

--add check constraint
alter table dbo.dt_SwitchStaging
with check
add constraint CK__dt_SwitchStaging_ID check(ID >10 and ID<=20)

执行swith 代码,依然出错,错误消息和上面相同,错误原因是忽略了Partition 2的partition column 不能为空的约束。

--add check constraint
alter table dbo.dt_SwitchStaging
with check
add constraint CK__dt_SwitchStaging_ID check(ID >10 and ID<=20 and ID is not null)

3,Partition Number=1 允许parition column 为null

--empty staging table
truncate table dbo.dt_SwitchStaging
go

--drop constraint
alter table dbo.dt_SwitchStaging
drop constraint CK__dt_SwitchStaging_ID
go

alter table dbo.dt_partition
switch partition 1
to dbo.dt_SwitchStaging
go

--add check constraint
alter table dbo.dt_SwitchStaging
with check
add constraint CK__dt_SwitchStaging_ID check(ID <=10 )
go

--insert null
insert into dbo.dt_SwitchStaging
(ID,Code)
values(null,1)
go

--switch staging table to partition 1
alter table dbo.dt_SwitchStaging
switch
to dbo.dt_partition partition 1
go

执行成功,创建的Check 约束允许 ID为null,并且 partition column也允许为Null。

时间: 2024-08-19 12:10:11

Partition table的switch条件2:Partition 的隐式Check约束 和Nullability的相关文章

Partition table的switch条件1:结构相同(类型,nullability)

1,创建实例数据 -- create parition function CREATE PARTITION FUNCTION pf_int_Left (int) AS RANGE LEFT FOR VALUES (10,20); --create partition scheme CREATE PARTITION SCHEME PS_int_Left AS PARTITION pf_int_Left TO ([primary], [primary], [primary]); --create p

Java 条件表达式结果的隐式转换

public class IN0102 { public static void main(String[] args) { int a = 'a'; System.out.println(a);//97 float f = (float) 3.2; float sum =1.5f; int num=2; System.out.println((sum<2?1:num/sum));//1.0 System.out.println("-----------------------------

Partition Table 查询性能

分区表的高效的查询性能是基于Partition Elimination 和 Partition Parallelism实现的.Partition Elimination 是指在执行TSql查询的时候,不是seek表的所有分区,而是根据Partition column排除部分分区,在符合 filtering the partition column 条件的 partition 上进行查询.Partition Parallelism是指分区之间可以并发执行查询.分区表查询使用更小的查询范围,更高的并

Oracle partition table 分区表详解

分区表就是通过使用分区技术,将一张大表,拆分成多个表分区(独立的segment),从而提升数据访问的性能,以及日常的可维护性.分区表中,每个分区的逻辑结构必须相同.如:列名.数据类型.分区表中,每个分区的物理存储参数可以不同.如:各个分区所在的表空间.对于应用而言完全透明,分区前后没有变化,不需要进行修改. 分区表相关试图显示表分区信息 显示数据库所有分区表的详细分区信息﹕DBA_TAB_PARTITIONS 显示子分区信息 显示数据库所有组合分区表的子分区信息﹕DBA_TAB_SUBPARTI

doesn&#39;t contain a valid partition table 解决方法

输入 fdisk -l 可以看到 输入 fdisk /dev/xvdb 跟着向导一步步做下去(如果不知道该输入什么,就输入“m”并回车,可以打印出菜单): Command (m for help): m Command action a   toggle a bootable flag b   edit bsd disklabel c   toggle the dos compatibility flag d   delete a partition l   list known partiti

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.

在 mkfs.ext4 /dev/sda2 格式化硬盘空间时,可能出现这样的错误. had this situation at office where I was told to re-partition an already existing partition. The situation was to get the below schema /dev/sdb1 1 3040 24418768+ 83 Linux /dev/sdb2 3041 6080 24418800 83 Linux

Mycat+Mysql 插入数据报错 i[Err] 1064 - partition table, insert must provide ColumnList

使用Navicat连接Mycat 8066 成功插入了分库表和全局表 1.全局表 sql如下: INSERT INTO `t_rank` VALUES ('259bfdc3-7922-4839-96c7-61c89e877dc5', '法国', '7', '11', '11', '12', null, '34'); INSERT INTO `t_rank` VALUES ('41eece5d-9d86-4cfe-b0ce-e6d4e4021cac', '中国', '2', '38', '27',

小米2s线刷出现remote: partition table doesn&#39;t exist

=================问题============ 小米2s线刷出现remote: partition table doesn't exist =================解决方案========== 在线刷的包中的flash_all.bat内容最前面加入这一句“fastboot %* flash partition "%~dp0images\gpt_both0.bin" || @echo "Flash partition" &&

GUID Partition Table (GPT)

https://en.wikipedia.org/wiki/GUID_Partition_Table https://zh.wikipedia.org/wiki/全局唯一标识分区表 GUID Partition Table (GPT) is a standard for the layout of the partition table on a physical storage device, such as a hard disk drive or solid-state drive, us