SELECT SCHEMA_NAME(A.schema_id) + '.' +
A.Name, SUM(B.rows) AS 'RowCount'
FROM sys.objects A
INNER JOIN sys.partitions B ON A.object_id = B.object_id
WHERE A.type = 'U'
GROUP BY A.schema_id, A.Name
GO
Thursday, 16 February 2017
Total row counts for all table in YOUR_DATABASE:
Select an OrderID always before the current passing OrderID:
select an OrderID before the OrderID you are passing. check the below scenario for more clarification.
;WITH CTE AS
(
SELECT
rownum = ROW_NUMBER() OVER (ORDER BY orderID),orderID FROM Orders
)
SELECT
cur.orderID as CurrentID , prev.orderID as PrevID
FROM CTE cur
INNER JOIN CTE prev on prev.rownum = cur.rownum - 1
where cur.orderID=27 or cur.orderID=29
OUTPUT:
Friday, 10 February 2017
Monday, 6 February 2017
Check database total size in use :-
SELECT DB_NAME(database_id) AS DatabaseName,
Name AS Logical_Name,
Physical_Name,
(size * 8) / 1024 SizeMB
FROM sys.master_files
WHERE DB_NAME(database_id) = 'YOUR_DB'
Name AS Logical_Name,
Physical_Name,
(size * 8) / 1024 SizeMB
FROM sys.master_files
WHERE DB_NAME(database_id) = 'YOUR_DB'
Thursday, 2 February 2017
Check two table where columns are not matching :-
select column_name from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='Table_name1'
except
select column_name from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='Table_name2'
where TABLE_NAME='Table_name1'
except
select column_name from INFORMATION_SCHEMA.COLUMNS
where TABLE_NAME='Table_name2'
Subscribe to:
Posts (Atom)