From c3a5bd13044e69658a1b0ec8fe246722dc0626ea Mon Sep 17 00:00:00 2001 From: rahull0328 Date: Fri, 2 May 2025 18:20:31 +0530 Subject: [PATCH] added new answers --- README.md | 117 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 116 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1111220..9a9471e 100644 --- a/README.md +++ b/README.md @@ -1741,15 +1741,130 @@ It is primarily of interest to developers. The storage engine is a β€œstub” th To find unique (non-repeated) values in a column (i.e., values that appear only once), you can use the GROUP BY clause with HAVING COUNT(*) = 1. -- Sample Query +### Sample Query + +Suppose you have a table named students with a column name, and you want to find names that appear only once: + ```sql SELECT name FROM students GROUP BY name HAVING COUNT(*) = 1; ``` + +
+ β†₯ back to top +
+ #### Q. How to test performance of database? + +Testing the performance of a database involves assessing how efficiently it handles operations like queries, inserts, updates, and deletes under various loads. Here's how you can do it: + +**πŸ”Ή 1. Use Performance Testing Tools** +- Apache JMeter – For simulating multiple users and running SQL queries. + +- Sysbench – For benchmarking MySQL/PostgreSQL. + +- SQL Server Profiler – For SQL Server performance tracing. + +- pgBadger / pgBench – For PostgreSQL performance analysis. + +- MySQL Enterprise Monitor – For MySQL monitoring. + +**πŸ”Ή 2. Run Benchmark Queries** + +Use queries that represent your real-world workload and measure: + +- Execution time + +- CPU usage + +- Disk I/O + +- Memory usage + +```sql +SET STATISTICS TIME ON; +SELECT * FROM orders WHERE amount > 1000; +SET STATISTICS TIME OFF; +``` +**πŸ”Ή 3. Use EXPLAIN or EXPLAIN ANALYZE** + +To understand query plans and optimize them: + +```sql +EXPLAIN SELECT * FROM orders WHERE amount > 1000; +``` + +**πŸ”Ή 4. Monitor Key Metrics** + +- Query response time + +- Transactions per second (TPS) + +- Throughput + +- Deadlocks / Slow queries + +- Cache hit ratio + +**πŸ”Ή 5. Load Testing** +Simulate concurrent users performing operations to evaluate how the DB performs under stress. + +**πŸ”Ή 6. Index and Query Optimization** + +Check if indexes are used and queries are efficient. + +
+ β†₯ back to top +
+ #### Q. What is SQL Profiler? + +SQL Profiler is a graphical tool provided by Microsoft SQL Server that allows you to monitor, trace, and analyze database activities in real-time. + +**πŸ”Ή Key Features of SQL Profiler:** + +- Tracks T-SQL queries and stored procedures. + +- Monitors login/logout activity. + +- Identifies long-running or slow queries. + +- Helps in performance tuning and debugging. + +- Logs events like deadlocks, locks, and transactions. + +**πŸ” Use Cases:** + +- Performance tuning: Find queries that consume high CPU or run slowly. + +- Troubleshooting: Detect problematic SQL commands or errors. + +- Audit and security: Track user activities and access patterns. + +- Optimization: Understand which indexes or queries need improvement. + +**🧾 Example:** + +You can use SQL Profiler to capture all queries being executed on the server during peak traffic and identify: + +``` +Event: SQL:BatchCompleted +Duration: 12000 ms +Text: SELECT * FROM orders WHERE amount > 1000; +``` + +**πŸ› οΈ Note:** + +- SQL Profiler is deprecated in newer versions of SQL Server. + +- Microsoft recommends using Extended Events for better performance and lower overhead. + +
+ β†₯ back to top +
+ #### Q. How to get @@ERROR and @@ROWCOUNT at the same time? #### Q. Explain about buffer cash and log Cache in SQL Server?