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 ;

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

SQL Server 2012: How to get up to 5 hierarchy levels of data from original to derived product table

分類Dev

Get DISTINCT COUNT in one pass in SQL Server

分類Dev

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

分類Dev

Delete duplicate records from SQL Server 2012 table with identity

分類Dev

SQL Server 2012 Pivot Table

分類Dev

Merge data into one column - sql server 2012

分類Dev

How to get the count/records from the table which is not there in same table?

分類Dev

SQL Server How to output one table result from multiple results with a WHILE query

分類Dev

Move database from SQL Server 2012 to 2008

分類Dev

SQL Server 2008でのCount(Distinct([value))OVER(Partition by)

分類Dev

Count from a Count based on a condition in SQL server

分類Dev

using Case get values from different table in sql server

分類Dev

How to check history in SQL Server 2012?

分類Dev

How can I get the link of SQL Server Express 2012 SP4 for CLI download?

分類Dev

Select data from one table & then rename the columns based on another table in SQL server

分類Dev

T-SQL stored procedure to get data from any table on the server for CSV export (SQL Server 2016)

分類Dev

How to get output from SQL Server Insert Command with more than one row using C# ADO.Net?

分類Dev

How to create JSON from an EAV table in SQL Server

分類Dev

sql select and Count from 2 Table

分類Dev

Get row count of successful bulk insert using jdbc from sql server

分類Dev

SQL to get top 3 from a table with at least one from opposite gender

分類Dev

Subtract hours from SQL Server 2012 query result

分類Dev

Display two columns but one of them is in union with another column from another table in SQL Server

分類Dev

How to get unique values from specific column in SQL Server?

分類Dev

How to rename a table in SQL Server?

分類Dev

SQL count occurrence of every record (integer) in one table with multiple columns

分類Dev

SQL join including all rows from one table irrespective of how many are represented in the other table

分類Dev

SQL Server- Merge rows into one column and take maximum count

分類Dev

How to retrieve only particular part of string in SQL Server 2012

Related 関連記事

  1. 1

    SQL Server 2012: How to get up to 5 hierarchy levels of data from original to derived product table

  2. 2

    Get DISTINCT COUNT in one pass in SQL Server

  3. 3

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

  4. 4

    Delete duplicate records from SQL Server 2012 table with identity

  5. 5

    SQL Server 2012 Pivot Table

  6. 6

    Merge data into one column - sql server 2012

  7. 7

    How to get the count/records from the table which is not there in same table?

  8. 8

    SQL Server How to output one table result from multiple results with a WHILE query

  9. 9

    Move database from SQL Server 2012 to 2008

  10. 10

    SQL Server 2008でのCount(Distinct([value))OVER(Partition by)

  11. 11

    Count from a Count based on a condition in SQL server

  12. 12

    using Case get values from different table in sql server

  13. 13

    How to check history in SQL Server 2012?

  14. 14

    How can I get the link of SQL Server Express 2012 SP4 for CLI download?

  15. 15

    Select data from one table & then rename the columns based on another table in SQL server

  16. 16

    T-SQL stored procedure to get data from any table on the server for CSV export (SQL Server 2016)

  17. 17

    How to get output from SQL Server Insert Command with more than one row using C# ADO.Net?

  18. 18

    How to create JSON from an EAV table in SQL Server

  19. 19

    sql select and Count from 2 Table

  20. 20

    Get row count of successful bulk insert using jdbc from sql server

  21. 21

    SQL to get top 3 from a table with at least one from opposite gender

  22. 22

    Subtract hours from SQL Server 2012 query result

  23. 23

    Display two columns but one of them is in union with another column from another table in SQL Server

  24. 24

    How to get unique values from specific column in SQL Server?

  25. 25

    How to rename a table in SQL Server?

  26. 26

    SQL count occurrence of every record (integer) in one table with multiple columns

  27. 27

    SQL join including all rows from one table irrespective of how many are represented in the other table

  28. 28

    SQL Server- Merge rows into one column and take maximum count

  29. 29

    How to retrieve only particular part of string in SQL Server 2012

ホットタグ

アーカイブ