CTE vs Temp Table
Wednesday, December 31, 2025
DELETE vs TRUNCATE vs DROP
DELETE vs TRUNCATE vs DROP
| Feature | DELETE | TRUNCATE | DROP |
|---|---|---|---|
| Rollback | ✅ Yes | ❌ No | ❌ No |
| Where clause | ✅ Yes | ❌ No | ❌ No |
| Identity reset | ❌ No | ✅ Yes | — |
| Logging | Fully logged | Minimally logged | Removes metadata |
Friday, December 22, 2023
List 50% Rows of a table
Query Show 50% Rows of a table
WITH employee_ranking AS ( SELECT employee_id, last_name, first_name, salary, NTILE(2) OVER (ORDER BY salary ) as ntile FROM employee)SELECT employee_id, last_name, first_name, salaryFROM employee_rankingWHERE ntile = 1ORDER BY salarySQL Server 2022 Enhancements/Features
SQL Server 2022 Enhancements/Features
1) Built-In Query Intelligence:
2) Query Store:
With Query store, we have following benefits.
- Discover slow queries
- Intervene manually to identify slow SQL queries.
- Optimize slow SQL queries
- Go live, observe performance, and repeat optimization if the expected result is not received.
3) Cardinality Estimation Feedback:

4) Memory Grant Feedback:
Memory grants for latest query is estimated by previous query executions
5) Parameter-Sensitive Plan (PSP) optimization:
In SQL Server 2022, the introduced PSP (Plan Stability Priority) helps solve this problem. With the ability of the Query Store to cache multiple execution plans for a single SQL statement, it becomes possible to select a more suitable plan based on parameters. The general principle is as follows: adding a dispatcher between the Query Hash and plan cache hash to determine which cached execution plan to use based on the dispatcher. This feature is indeed a great help for slightly larger databases with complex queries. Although I haven't had the opportunity to witness specific cases yet, based on my experience, this feature will significantly reduce the O&M threshold.
6) Degree of Parallelism (DOP) Feedback
ALTER DATABASE SCOPED CONFIGURATION SET DOP_FEEDBACK = ONSaturday, December 31, 2022
Tuesday, December 28, 2021
New Features in MS SQL Server 2019
New Features in MS SQL Server 2019
Ø Intelligent Query Processing Enhancements
Ø Accelerated Database Recovery (ADR)
Ø AlwaysEncrypted with secure enclaves
Ø Query Store custom capture policies
Ø Verbose truncation warnings
Ø Resumable index build
Ø Data virtualization with Polybase
Ø Last actual execution plan DMF
Ø Multiple internal performance improvements
Thursday, December 24, 2020
Running Total using windows functions in SQL Server
Query to find running total using windows analytical functions
/* Create global temporary table */
CREATE TABLE ##Employee_Temp(EmpId INT,EMPName VARCHAR(100), Salary MONEY,DEPTID INT,LOC VARCHAR(200))
/* Insert Sample Data in global temporary table */
INSERT INTO ##Employee_Temp VALUES
(1,'RAM',10000,1,'CHARLOTTE'),
(2,'GEORGE',11000,1,'CHARLOTTE'),
(3,'BENJAMIN',9000,2,'CHARLOTTE'),
(4,'MARK',12000,2,'NEW YORK'),
(5,'ALLEN',13000,3,'NEW YORK'),
(6,'NILOLA',14000,3,'NEW YORK'),
(7,'REDIFF',20000,4,'DELHI'),
(8,'SHAYAM',16000,4,'DELHI'),
(9,'ALLARD',17000,4,'LONDON'),
(10,'KEVIN',18000,5,'TOKIO')
/* Below is the select Query to get running total from top to bottom and bottom to top */
select *,
SUM(Salary ) OVER( ORDER BY EMPID ROWS BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW) AS RunningTotalUsingROWS_TOPTOBOTTOM,
SUM(Salary ) OVER( ORDER BY EMPID RANGE BETWEEN UNBOUNDED PRECEDING
AND CURRENT ROW) AS RunningTotalUsingRANGE_TOPTOBOTTOM,
SUM(Salary ) OVER( ORDER BY EMPID ASC ROWS BETWEEN CURRENT ROW
AND UNBOUNDED FOLLOWING ) AS RunningTotalUsingROWS_BOTTOMTOTOP,
SUM(Salary ) OVER( ORDER BY EMPID ASC RANGE BETWEEN CURRENT ROW
AND UNBOUNDED FOLLOWING ) AS RunningTotalUsingRANGE_BOTTOMTOTOP
FROM ##Employee_Temp ORDER BY EMPID ASC
Result:
Running total with selected (3) PRECEDING & FOLLOWING:
Result:
Saturday, December 28, 2019
Tuesday, December 18, 2018
Friday, March 24, 2017
Contained Database in SQL Server
in this way contained database becomes fully portable without having the issue of orphaned users.




%20Feedback.png)





