Skip to content

Commit c3a5bd1

Browse files
committed
added new answers
1 parent e92e533 commit c3a5bd1

File tree

1 file changed

+116
-1
lines changed

1 file changed

+116
-1
lines changed

β€ŽREADME.mdβ€Ž

Lines changed: 116 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1741,15 +1741,130 @@ It is primarily of interest to developers. The storage engine is a β€œstub” th
17411741

17421742
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.
17431743

1744-
- Sample Query
1744+
### Sample Query
1745+
1746+
Suppose you have a table named students with a column name, and you want to find names that appear only once:
1747+
17451748
```sql
17461749
SELECT name
17471750
FROM students
17481751
GROUP BY name
17491752
HAVING COUNT(*) = 1;
17501753
```
1754+
1755+
<div align="right">
1756+
<b><a href="#table-of-contents">β†₯ back to top</a></b>
1757+
</div>
1758+
17511759
#### Q. How to test performance of database?
1760+
1761+
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:
1762+
1763+
**πŸ”Ή 1. Use Performance Testing Tools**
1764+
- Apache JMeter – For simulating multiple users and running SQL queries.
1765+
1766+
- Sysbench – For benchmarking MySQL/PostgreSQL.
1767+
1768+
- SQL Server Profiler – For SQL Server performance tracing.
1769+
1770+
- pgBadger / pgBench – For PostgreSQL performance analysis.
1771+
1772+
- MySQL Enterprise Monitor – For MySQL monitoring.
1773+
1774+
**πŸ”Ή 2. Run Benchmark Queries**
1775+
1776+
Use queries that represent your real-world workload and measure:
1777+
1778+
- Execution time
1779+
1780+
- CPU usage
1781+
1782+
- Disk I/O
1783+
1784+
- Memory usage
1785+
1786+
```sql
1787+
SET STATISTICS TIME ON;
1788+
SELECT * FROM orders WHERE amount > 1000;
1789+
SET STATISTICS TIME OFF;
1790+
```
1791+
**πŸ”Ή 3. Use EXPLAIN or EXPLAIN ANALYZE**
1792+
1793+
To understand query plans and optimize them:
1794+
1795+
```sql
1796+
EXPLAIN SELECT * FROM orders WHERE amount > 1000;
1797+
```
1798+
1799+
**πŸ”Ή 4. Monitor Key Metrics**
1800+
1801+
- Query response time
1802+
1803+
- Transactions per second (TPS)
1804+
1805+
- Throughput
1806+
1807+
- Deadlocks / Slow queries
1808+
1809+
- Cache hit ratio
1810+
1811+
**πŸ”Ή 5. Load Testing**
1812+
Simulate concurrent users performing operations to evaluate how the DB performs under stress.
1813+
1814+
**πŸ”Ή 6. Index and Query Optimization**
1815+
1816+
Check if indexes are used and queries are efficient.
1817+
1818+
<div align="right">
1819+
<b><a href="#table-of-contents">β†₯ back to top</a></b>
1820+
</div>
1821+
17521822
#### Q. What is SQL Profiler?
1823+
1824+
SQL Profiler is a graphical tool provided by Microsoft SQL Server that allows you to monitor, trace, and analyze database activities in real-time.
1825+
1826+
**πŸ”Ή Key Features of SQL Profiler:**
1827+
1828+
- Tracks T-SQL queries and stored procedures.
1829+
1830+
- Monitors login/logout activity.
1831+
1832+
- Identifies long-running or slow queries.
1833+
1834+
- Helps in performance tuning and debugging.
1835+
1836+
- Logs events like deadlocks, locks, and transactions.
1837+
1838+
**πŸ” Use Cases:**
1839+
1840+
- Performance tuning: Find queries that consume high CPU or run slowly.
1841+
1842+
- Troubleshooting: Detect problematic SQL commands or errors.
1843+
1844+
- Audit and security: Track user activities and access patterns.
1845+
1846+
- Optimization: Understand which indexes or queries need improvement.
1847+
1848+
**🧾 Example:**
1849+
1850+
You can use SQL Profiler to capture all queries being executed on the server during peak traffic and identify:
1851+
1852+
```
1853+
Event: SQL:BatchCompleted
1854+
Duration: 12000 ms
1855+
Text: SELECT * FROM orders WHERE amount > 1000;
1856+
```
1857+
1858+
**πŸ› οΈ Note:**
1859+
1860+
- SQL Profiler is deprecated in newer versions of SQL Server.
1861+
1862+
- Microsoft recommends using Extended Events for better performance and lower overhead.
1863+
1864+
<div align="right">
1865+
<b><a href="#table-of-contents">β†₯ back to top</a></b>
1866+
</div>
1867+
17531868
#### Q. How to get @@ERROR and @@ROWCOUNT at the same time?
17541869
#### Q. Explain about buffer cash and log Cache in SQL Server?
17551870

0 commit comments

Comments
Β (0)