我正在研究具有时间序列数据的表的水平分区。我发现2005年的分区比2000年要容易得多,但我似乎无法找到答案:我可以在SQL Server 2005中更改分区表吗?
我可以添加/删除分区表的列吗?
是否需要特殊步骤,因为它是分区?
我正在研究具有时间序列数据的表的水平分区。我发现2005年的分区比2000年要容易得多,但我似乎无法找到答案:我可以在SQL Server 2005中更改分区表吗?
我可以添加/删除分区表的列吗?
是否需要特殊步骤,因为它是分区?
我无法找到一个明确的答案(我发现DOC @ E.J布伦南参考有点密集和不明确的。)。所以我加入this example,并测试了,是的,你可以添加/删除列:
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;
*/
除了执行涉及分区表的SWITCH操作外,ALTER TABLE可用于更改分区表的列,约束和触发器的状态,就像它用于非分区表一样。但是,此语句不能用于更改表本身的分区方式。要重新分区分区表,请使用ALTER PARTITION SCHEME和ALTER PARTITION FUNCTION。此外,您不能更改分区表的列的数据类型。
在这里阅读更多: http://technet.microsoft.com/en-us/library/ms190273.aspx
2005年版本的文档的说同样的事情(http://technet.microsoft.com/en-我们/库/ ms190273(SQL.90)的.aspx)。我的意思不是迂腐,但这是否意味着我可以添加/删除列? – 2009-01-19 21:17:32