You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+116-1Lines changed: 116 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1741,15 +1741,130 @@ It is primarily of interest to developers. The storage engine is a βstubβ th
1741
1741
1742
1742
To find unique (non-repeated) valuesin a column (i.e., values that appear only once), you can use the GROUP BY clause with HAVINGCOUNT(*) =1.
1743
1743
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
+
1745
1748
```sql
1746
1749
SELECT name
1747
1750
FROM students
1748
1751
GROUP BY name
1749
1752
HAVING COUNT(*) = 1;
1750
1753
```
1754
+
1755
+
<div align="right">
1756
+
<b><a href="#table-of-contents">β₯ back to top</a></b>
1757
+
</div>
1758
+
1751
1759
#### 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
+
1752
1822
#### 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
+
1753
1868
#### Q. How to get @@ERROR and @@ROWCOUNT at the same time?
1754
1869
#### Q. Explain about buffer cash and log Cache in SQL Server?
0 commit comments