首页 > 其他 > 详细

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

时间:2015-12-11 22:15:05      阅读:366      评论:0      收藏:0      [点我收藏+]

 

 

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)

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

创建 staging table,用于接收partition 2的数据


2,测试 nullability

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

switch data

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

Msg 4985, Level 16, State 1, Line 2
ALTER TABLE SWITCH statement failed because column ‘ID‘ does not have the same nullability attribute in tables ‘DB_Study.dbo.dt_partition‘ and ‘DB_Study.dbo.dt_SwitchStaging‘.

3,测试数据类型的兼容性

alter table  dbo.dt_SwitchStaging
alter column ID bigint null

switch data

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

Msg 4944, Level 16, State 1, Line 2
ALTER TABLE SWITCH statement failed because column ‘ID‘ has data type int in source table ‘DB_Study.dbo.dt_partition‘ which is different from its type bigint in target table ‘DB_Study.dbo.dt_SwitchStaging‘.

 

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

原文:http://www.cnblogs.com/ljhdo/p/5040150.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!