How to get COUNT(*) from one partition of a table in SQL Server 2012?

Masoomian

My table have 7 million records and I do split table in 14 part according to ID, each partition include 5 million record and size of partition is 40G. I want to run a query to get count in one partition but it scan all partitions and time of Query become very large.

SELECT COUNT(*) 
FROM Item 
WHERE IsComplated = 0 
  AND ID Between 1 AND 5000000

How can I run my query on one partition only without scan other partition?

HaveNoDisplayName

Refer http://msdn.microsoft.com/en-us/library/ms188071.aspx

B. Getting the number of rows in each nonempty partition of a partitioned table or index The following example returns the number of rows in each partition of table TransactionHistory that contains data. The TransactionHistory table uses partition function TransactionRangePF1 and is partitioned on the TransactionDate column. To execute this example, you must first run the PartitionAW.sql script against the AdventureWorks2012 sample database. For more information, see PartitioningScript.

USE AdventureWorks2012;
GO
SELECT $PARTITION.TransactionRangePF1(TransactionDate) AS Partition, 
COUNT(*) AS [COUNT] FROM Production.TransactionHistory 
GROUP BY $PARTITION.TransactionRangePF1(TransactionDate)
ORDER BY Partition ;
GO

C. Returning all rows from one partition of a partitioned table or index The following example returns all rows that are in partition 5 of the table TransactionHistory. Note Note To execute this example, you must first run the PartitionAW.sql script against the AdventureWorks2012 sample database. For more information, see PartitioningScript.

SELECT * FROM Production.TransactionHistory
WHERE $PARTITION.TransactionRangePF1(TransactionDate) = 5 ;

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

SQL Server 2012 : how to get count group by from multiple table joins

From Dev

Is there a way to drop a range value from a partition table (sql server 2012)

From Dev

How to get partition column name from partition table in oracle server

From Dev

Get count of children from each parent.SQL Server 2012

From Dev

How to get the count of a join table in sql server?

From Dev

How distribute many columns in one table in SQL Server 2012 database

From Dev

How to get all columns from first table when there is no matching column in SQL Server 2012

From Dev

How to get all columns from first table when there is no matching column in SQL Server 2012

From Dev

How to copy table from MS SQL Server 2012 to MonetDB

From Dev

How to delete a filegroup from a partitioned table (SQL Server 2012)

From Dev

SQL Server 2012: Copy table structure with data from one DB server to other using Linked Server

From Dev

SQL get count from one table and split to two columns

From Dev

SQL - get count from one table based on result of query

From Dev

get a count of each value from every column in a table SQL Server

From Dev

Get records count from sql server table in the most optimized way

From Dev

SQL Server 2012: Multiple select count(column1) in a single query from different table causing errors

From Dev

How to count records faster querying linked DB2 server from SQL SERVER 2012

From Dev

Dynamic PIVOT table SQL Server 2012 with COUNT() and SUM() and a TOTAL column

From Dev

Get values from multiple sql server table by one query

From Dev

SQL Server Table Partition

From Dev

How can I do a switched outer join with more than one table in SQL Server 2012?

From Dev

Get Count of Missing records between two tables (SQL Server 2012)

From Dev

How to create a new table from existing table with both keys and data in SQL Server 2012 (Management Studio)?

From Dev

How to Get Sum of One Column Based On Other Table in Sql Server

From Dev

How to get the table names from "SQL script" in SQL Server database

From Dev

How to copy data from one table into another in Microsoft SQL Server

From Dev

How to sum a specific row from one table to another in SQL Server

From Dev

How does one retrieve records 1 year prioir from specific date in sql server 2012

From Dev

How to count row in SQL SERVER 2012 using sys.partitions

Related Related

  1. 1

    SQL Server 2012 : how to get count group by from multiple table joins

  2. 2

    Is there a way to drop a range value from a partition table (sql server 2012)

  3. 3

    How to get partition column name from partition table in oracle server

  4. 4

    Get count of children from each parent.SQL Server 2012

  5. 5

    How to get the count of a join table in sql server?

  6. 6

    How distribute many columns in one table in SQL Server 2012 database

  7. 7

    How to get all columns from first table when there is no matching column in SQL Server 2012

  8. 8

    How to get all columns from first table when there is no matching column in SQL Server 2012

  9. 9

    How to copy table from MS SQL Server 2012 to MonetDB

  10. 10

    How to delete a filegroup from a partitioned table (SQL Server 2012)

  11. 11

    SQL Server 2012: Copy table structure with data from one DB server to other using Linked Server

  12. 12

    SQL get count from one table and split to two columns

  13. 13

    SQL - get count from one table based on result of query

  14. 14

    get a count of each value from every column in a table SQL Server

  15. 15

    Get records count from sql server table in the most optimized way

  16. 16

    SQL Server 2012: Multiple select count(column1) in a single query from different table causing errors

  17. 17

    How to count records faster querying linked DB2 server from SQL SERVER 2012

  18. 18

    Dynamic PIVOT table SQL Server 2012 with COUNT() and SUM() and a TOTAL column

  19. 19

    Get values from multiple sql server table by one query

  20. 20

    SQL Server Table Partition

  21. 21

    How can I do a switched outer join with more than one table in SQL Server 2012?

  22. 22

    Get Count of Missing records between two tables (SQL Server 2012)

  23. 23

    How to create a new table from existing table with both keys and data in SQL Server 2012 (Management Studio)?

  24. 24

    How to Get Sum of One Column Based On Other Table in Sql Server

  25. 25

    How to get the table names from "SQL script" in SQL Server database

  26. 26

    How to copy data from one table into another in Microsoft SQL Server

  27. 27

    How to sum a specific row from one table to another in SQL Server

  28. 28

    How does one retrieve records 1 year prioir from specific date in sql server 2012

  29. 29

    How to count row in SQL SERVER 2012 using sys.partitions

HotTag

Archive