Showing posts with label Record Count. Show all posts
Showing posts with label Record Count. Show all posts

Wednesday, February 26, 2020

ต้องการรู้จำนวน Records ในแต่ละตาราง , MS Sql Server

USE YourDBname
SELECT
      QUOTENAME(sOBJ.name) AS [TableName]
      , SUM(sPTN.Rows) AS [RowCount]
FROM
      sys.objects AS sOBJ
      INNER JOIN sys.partitions AS sPTN
            ON sOBJ.object_id = sPTN.object_id
WHERE
      sOBJ.type = 'U'
      AND sOBJ.is_ms_shipped = 0x0
      AND index_id < 2 -- 0:Heap, 1:Clustered
GROUP BY
      sOBJ.schema_id
      , sOBJ.name
ORDER BY [RowCount] DESC

Thursday, September 26, 2013

ต้องการใช้ Select Command เลือก Record Number และ Record Count มาด้วย

Use the following code in SQL Server

ตัวอย่าง Select Record Number มาด้วย

   select rank() OVER (ORDER BY a.au_lname, a.au_fname) as rank, a.au_lname, a.au_fname
   from authors a
   order by rank 


ตัวอย่าง Select Record Count มาด้วย

SELECT my_table.my_col, count(*) OVER() AS 'Count'
  FROM my_table
 WHERE my_table.foo = 'bar'