Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 116 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
```

<div align="right">
<b><a href="#table-of-contents">โ†ฅ back to top</a></b>
</div>

#### 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.

<div align="right">
<b><a href="#table-of-contents">โ†ฅ back to top</a></b>
</div>

#### 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.

<div align="right">
<b><a href="#table-of-contents">โ†ฅ back to top</a></b>
</div>

#### Q. How to get @@ERROR and @@ROWCOUNT at the same time?
#### Q. Explain about buffer cash and log Cache in SQL Server?

Expand Down