Frage

Ich bin auf der Suche in die horizontale Partitionierung für eine Tabelle, die Zeitreihendaten enthält. Ich habe entdeckt, dass Partitionierung im Jahr 2005 viel einfacher ist, als es im Jahr 2000 war, aber ich kann nicht scheinen, diese Antwort zu finden:

Kann ich Add / Drop-Spalten einer partitionierten Tabelle?

Sind spezielle Schritte erforderlich, da es partitioniert?

War es hilfreich?

Lösung 2

ich keine endgültige Antwort finden konnte (ich fand die doc @ E. J. Brennan ein wenig dichter und unklar sein verwiesen). So habe ich href="http://weblogs.sqlteam.com/dmauri/archive/2005/07/18/7147.aspx" rel="nofollow noreferrer"> diesem Beispiel ja, können Sie Add / Drop-Spalten :

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;
*/
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top