0% found this document useful (0 votes)
5 views1 page

Range Right and Left

The document outlines the steps to create a test database and set up filegroups for partitioning. It includes commands to create partition functions, partition schemes, and tables, as well as to insert data into these tables. Additionally, it provides SQL queries to retrieve partition information for the created tables.

Uploaded by

www.greeny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Range Right and Left

The document outlines the steps to create a test database and set up filegroups for partitioning. It includes commands to create partition functions, partition schemes, and tables, as well as to insert data into these tables. Additionally, it provides SQL queries to retrieve partition information for the created tables.

Uploaded by

www.greeny
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

Create database test

go
use test
Go

-- Step 2: Create the filegroups


ALTER DATABASE test ADD FILEGROUP MyFileGroup1;
Go
ALTER DATABASE test ADD FILEGROUP MyFileGroup2;

-- Step 3: Create the files in the filegroups


ALTER DATABASE test ADD FILE (NAME = MyFile1, FILENAME = 'C:\test\MyFile1.ndf',SIZE
= 100MB,MAXSIZE = UNLIMITED,FILEGROWTH = 100MB
)TO FILEGROUP MyFileGroup1;
Go
ALTER DATABASE test ADD FILE ( NAME = MyFile2,FILENAME = 'C:\test\MyFile2.ndf',SIZE
= 100MB,MAXSIZE = UNLIMITED,FILEGROWTH = 100MB
)TO FILEGROUP MyFileGroup2;

-- Step 1: Create the partition function


CREATE PARTITION FUNCTION MyPartitionFunction (INT) AS RANGE left FOR VALUES (5);
CREATE PARTITION FUNCTION MyPartitionFunction1 (INT) AS RANGE right FOR VALUES (5);

-- Step 4: Create the partition scheme


CREATE PARTITION SCHEME MyPartitionScheme AS PARTITION MyPartitionFunction TO
(MyFileGroup1, MyFileGroup2);
CREATE PARTITION SCHEME MyPartitionScheme1 AS PARTITION MyPartitionFunction1 TO
(MyFileGroup1, MyFileGroup2);

-- Step 5: Create the table with partitioning


CREATE TABLE MyTable(ID INT NOT NULL) ON MyPartitionScheme(ID);
CREATE TABLE MyTable2(ID INT NOT NULL) ON MyPartitionScheme1(ID);
-- Step 6: Insert data into the table
INSERT INTO MyTable (ID) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);
INSERT INTO MyTable2 (ID) VALUES (1), (2), (3), (4), (5), (6), (7), (8), (9), (10);

SELECT partition_id ,
OBJECT_NAME(object_id) AS Tablename ,
partition_number ,
row_count
FROM sys.dm_db_partition_stats
WHERE object_id = OBJECT_ID('mytable');

---
SELECT partition_id ,
OBJECT_NAME(object_id) AS Tablename ,
partition_number ,
row_count
FROM sys.dm_db_partition_stats
WHERE object_id = OBJECT_ID('MyTable2');

You might also like