我正在研究其中包含时间序列数据的表的水平分区。我发现 2005 年的分区比 2000 年要容易得多,但我似乎找不到这个答案:
我可以添加/删除分区表的列吗?
是否需要特殊步骤,因为它是分区的?
我正在研究其中包含时间序列数据的表的水平分区。我发现 2005 年的分区比 2000 年要容易得多,但我似乎找不到这个答案:
我可以添加/删除分区表的列吗?
是否需要特殊步骤,因为它是分区的?
除了执行涉及分区表的 SWITCH 操作外,ALTER TABLE 还可用于更改分区表的列、约束和触发器的状态,就像它用于非分区表一样。但是,此语句不能用于更改表本身的分区方式。要对分区表进行重新分区,请使用 ALTER PARTITION SCHEME 和 ALTER PARTITION FUNCTION。此外,您不能更改分区表的列的数据类型。
在此处阅读更多信息: http ://technet.microsoft.com/en-us/library/ms190273.aspx
我找不到明确的答案(我发现@EJ Brennan 引用的文档有点密集和不清楚)。所以我添加到这个例子中并测试了,是的,你可以添加/删除列:
USE adventureworks
go
create partition function YearPF(datetime) as range right for values ('20050101');
-- Now we need to add filegroups that will contains partitioned values
alter database adventureworks add filegroup YearFG1;
alter database adventureworks add filegroup YearFG2;
-- Now we need to add file to filegroups
alter database adventureworks add file (name = 'YearF1', filename = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdvWorksF1.ndf') to filegroup YearFG1;
alter database adventureworks add file (name = 'YearF2', filename = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdvWorksF2.ndf') to filegroup YearFG2;
-- Here we associate the partition function to
-- the created filegroup via a Partitioning Scheme
create partition scheme YearPS as partition YearPF to (YearFG1, YearFG2)
-- Now just create a table that uses the particion scheme
create table PartitionedOrders
(
Id int not null identity(1,1),
DueDate DateTime not null,
) on YearPS(DueDate)
-- And now we just have to use the table!
insert into PartitionedOrders values('20020101')
insert into PartitionedOrders values('20030101')
insert into PartitionedOrders values('20040101')
insert into PartitionedOrders values('20050101')
insert into PartitionedOrders values('20060101')
-- Now we want to see where our values has falled
select *, $partition.YearPF(DueDate) from PartitionedOrders
-- see if we can add a column
ALTER TABLE PartitionedOrders ADD NewColumn INT NULL
-- add some more records, populating the new column
insert into PartitionedOrders values('20010101', 1)
insert into PartitionedOrders values('20070101', 2)
-- see that they were inserted properly
select *, $partition.YearPF(DueDate) from PartitionedOrders
ALTER TABLE PartitionedOrders DROP COLUMN NewColumn
-- see that the column dropped
select *, $partition.YearPF(DueDate) from PartitionedOrders
/* clean up
drop table PartitionedOrders
drop partition scheme YearPS;
drop partition function YearPF;
alter database adventureworks remove file YearF1;
alter database adventureworks remove file YearF2;
alter database adventureworks remove filegroup YearFG1;
alter database adventureworks remove filegroup YearFG2;
*/