Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the row count from an azure database?

Am working on a windows store javascript application. The application uses data from azure mobile services. Consider the below code:

var itemTable = mobileService.getTable('item');
//item is the table name stored in the azure database

The code fetches the entire table item and saves it to a variable itemTable.

What code will return the no of rows present in itemTable??

like image 868
Amar Zeno Avatar asked Mar 25 '13 13:03

Amar Zeno


People also ask

How do you count rows in a database?

To counts all of the rows in a table, whether they contain NULL values or not, use COUNT(*). That form of the COUNT() function basically returns the number of rows in a result set returned by a SELECT statement.

How do you get total row count?

Just click the column header. The status bar, in the lower-right corner of your Excel window, will tell you the row count. Do the same thing to count columns, but this time click the row selector at the left end of the row. If you select an entire row or column, Excel counts just the cells that contain data.

How do I count rows in Azure synapse?

Following is the example to get the number of rows updated by the update statement. UPDATE TEST SET COL1 = 1 WHERE COL1 = 2 OPTION (LABEL = 'QUERYID2'); DECLARE @row_count int; SELECT top 1 @row_count = row_count FROM sys.


1 Answers

What you're looking for is the includeTotalCount method on the table/query object (unfortunately it's missing from the documentation, I'll file a bug to the product team to have it fixed).

When you call read on the query object, it will return by default 50 (IIRC, the number may be different) elements from it, to prevent a naïve call from returning all elements in a very large table (thus either incurring the outbound bandwidth cost for reserved services, or hitting the quota for free ones). So getting all the elements in the table, and getting the length of the results may not be accurate.

If all you want is the number of elements in the table, you can use the code below: returning zero elements, and the total count.

    var table = client.getTable('tableName');
    table.take(0).includeTotalCount().read().then(function (results) {
        var count = results.totalCount;
        new Windows.UI.Popups.MessageDialog('Total count: ' + count).showAsync();
    });

If you want to query some elements, and also include the total count (i.e., for paging), just add the appropriate take() and skip() calls, and also the includeTotalCount as well.

like image 163
carlosfigueira Avatar answered Oct 22 '22 11:10

carlosfigueira