learn about sqlserver partitition and partition table --- add or remove table partitions addition mo...

Yes . In the previous. chapter , we see how to generate  "partition function" "parttiton schema" and "parttiton table"

 

what can we do if we need to add or drop an table partition ?

 

Here is exist status:

 

/*  add partition (oracle)== split partition (oracle,mssql) */

/*  drop parttiton (oracle) == merge partition (mssql) */

 

learn about sqlserver partitition and partition table --- add or remove table partitions addition mo...

 

and

 

learn about sqlserver partitition and partition table --- add or remove table partitions addition mo...

 

 

Here we go

 

/* add partitions */

 

alter database test add filegroup TESTFG_201602;

alter database test add file (name = TESTFG_201602,filename = "C:\var\opt\mssql\data\TESTFG_201602.ndf",size = 1MB,maxsize = unlimited,filegrowth = 1MB) to filegroup TESTFG_201602;

go

alter partition scheme PS_DATETIME_M_TEST NEXT USED TESTFG_201601;

alter partition function PF_DATETIME_M_TEST() split range ( N'2016-01-02T00:00:00.000');

go

 

That script has an error. you would  see if I execute it

 

learn about sqlserver partitition and partition table --- add or remove table partitions addition mo...

However,  It is right about "less than", because we use range right    --- it will be talk about it in detail

 

learn about sqlserver partitition and partition table --- add or remove table partitions addition mo....

 

Let get into bussiness, hot to fix that ?

 

Yes, we merge it

 

/* drop partitions */

alter partition function PF_DATETIME_M_TEST() merge range (N'2016-01-02T00:00:00.000');

--alter database test remove file TESTFG_201602;        

--alter database test remove filegroup TESTFG_201602;

 

then we can see that return

 

learn about sqlserver partitition and partition table --- add or remove table partitions addition mo...

 

and we can make it right

 

alter partition scheme PS_DATETIME_M_TEST NEXT USED TESTFG_201602;

alter partition function PF_DATETIME_M_TEST() split range ( N'2016-02-01T00:00:00.000');

go

 

Yes. we did it

 

learn about sqlserver partitition and partition table --- add or remove table partitions addition mo...

 

 

OK.  Becareful , only empty partition can be merge .  What about if the partition contains data ?  We will see in the next chapter.