码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2015-12-11 22:16:43      阅读:161      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!