Skip to content

Bits of .NET

Daily micro-tips for C#, SQL, performance, and scalable backend engineering.

  • Asp.Net Core
  • C#
  • SQL
  • JavaScript
  • CSS
  • About
  • ErcanOPAK.com
  • No Access
  • Privacy Policy

Category: SQL

SQL

SQL: Use GROUP BY for Data Aggregation

- 12.07.26 - ErcanOPAK comment on SQL: Use GROUP BY for Data Aggregation

๐Ÿ“Š GROUP BY = Data Aggregation Raw data is too detailed. GROUP BY summarizes data. Counts, sums, averages โ€” powerful analysis. ๐Ÿ“ GROUP BY Basics — Count by category SELECT category, COUNT(*) as product_count FROM products GROUP BY category; — Sum by customer SELECT customer_id, SUM(total) as total_spent, COUNT(*) as order_count FROM orders GROUP BY […]

Read More
SQL

SQL: Use Views to Simplify Complex Queries

- 12.07.26 - ErcanOPAK comment on SQL: Use Views to Simplify Complex Queries

๐Ÿ“Š Views = Virtual Tables Complex queries repeated everywhere. Views simplify them. Create once, query like a table. ๐Ÿ“ Create View CREATE VIEW active_users AS SELECT id, name, email, created_at FROM users WHERE status = ‘active’ AND last_login > ‘2024-01-01’; — Query the view SELECT * FROM active_users; — View with JOIN CREATE VIEW order_summary […]

Read More
SQL

SQL: Use Indexing for Query Performance

- 12.07.26 - ErcanOPAK comment on SQL: Use Indexing for Query Performance

โšก Indexing = Query Performance Slow queries kill performance. Indexing speeds up data access. Find data fast, optimize queries. ๐Ÿ“ Index Types # B-Tree Index (default) CREATE INDEX idx_users_email ON users(email); # Unique Index CREATE UNIQUE INDEX idx_users_email ON users(email); # Composite Index CREATE INDEX idx_users_name_email ON users(name, email); # Full-Text Index CREATE FULLTEXT INDEX […]

Read More
SQL

SQL: Master Joins for Data Relationships

- 11.07.26 - ErcanOPAK comment on SQL: Master Joins for Data Relationships

๐Ÿ”— Joins = Data Relationships Data is in multiple tables. Joins combine them. INNER, LEFT, RIGHT, FULL โ€” choose right. ๐Ÿ“ Join Types — INNER JOIN (Only matching) SELECT u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id; — LEFT JOIN (All from left) SELECT u.name, o.total FROM users u LEFT […]

Read More
SQL

SQL: Use Subqueries for Complex Data

- 11.07.26 - ErcanOPAK comment on SQL: Use Subqueries for Complex Data

๐Ÿ“Š Subqueries = Complex Data Single queries are limited. Subqueries nest queries. Complex conditions, derived data. ๐Ÿ“ Subquery Examples — Users with orders over $100 SELECT name, email FROM users WHERE id IN ( SELECT user_id FROM orders WHERE total > 100 ); — Users with no orders SELECT name, email FROM users WHERE id […]

Read More
SQL

SQL: Use Foreign Keys for Data Integrity

- 11.07.26 - ErcanOPAK comment on SQL: Use Foreign Keys for Data Integrity

๐Ÿ”— Foreign Keys = Data Integrity Orphaned data is bad. Foreign keys maintain relationships. Referential integrity, cascading actions. ๐Ÿ“ Foreign Key Basics — Create with foreign key CREATE TABLE orders ( id INT PRIMARY KEY, user_id INT, total DECIMAL(10,2), FOREIGN KEY (user_id) REFERENCES users(id) ); — With ON DELETE CASCADE CREATE TABLE order_items ( id […]

Read More
SQL

SQL: Use Triggers for Automated Actions

- 10.07.26 - ErcanOPAK comment on SQL: Use Triggers for Automated Actions

๐Ÿ”” Triggers = Automated Actions Need to automate database actions? Triggers run automatically. Audit logs, data validation, synchronization. ๐Ÿ“ Trigger Basics — Audit trigger (INSERT) CREATE TRIGGER user_audit_insert ON users AFTER INSERT AS BEGIN INSERT INTO audit_log (action, table_name, record_id, changed_by, changed_at) SELECT ‘INSERT’, ‘users’, id, SYSTEM_USER, GETDATE() FROM inserted; END; — Audit trigger (UPDATE) […]

Read More
SQL

SQL: Use Views to Simplify Complex Queries

- 10.07.26 - ErcanOPAK comment on SQL: Use Views to Simplify Complex Queries

๐Ÿ“Š Views = Virtual Tables Complex queries repeated everywhere. Views simplify them. Create once, use like a table. ๐Ÿ“ Create View CREATE VIEW active_users AS SELECT id, name, email, created_at FROM users WHERE status = ‘active’ AND last_login > ‘2024-01-01’; — Query the view SELECT * FROM active_users; — View with JOIN CREATE VIEW order_summary […]

Read More
SQL

SQL: Use Stored Procedures for Database Logic

- 10.07.26 - ErcanOPAK comment on SQL: Use Stored Procedures for Database Logic

๐Ÿ“ฆ Stored Procedures = Database Logic Business logic in code is fine. Stored procedures move logic to database. Performance, security, consistency. ๐Ÿ“ Creating Procedures — Basic procedure CREATE PROCEDURE GetUserById @UserId INT AS BEGIN SELECT * FROM Users WHERE Id = @UserId; END; — Execute EXEC GetUserById 1; — With OUTPUT parameter CREATE PROCEDURE GetUserCount […]

Read More
SQL

SQL: Use JSON Functions for Modern Data

- 09.07.26 - ErcanOPAK comment on SQL: Use JSON Functions for Modern Data

๐Ÿ“‹ JSON in SQL = Modern Data JSON is everywhere. SQL JSON functions work with JSON data. Store, query, modify โ€” flexible data. ๐Ÿ“ JSON Functions # Store JSON CREATE TABLE users ( id INT PRIMARY KEY, name VARCHAR(100), metadata JSON ); INSERT INTO users (id, name, metadata) VALUES ( 1, ‘Alice’, ‘{“age”: 30, “city”: […]

Read More
SQL

SQL: Master Query Optimization for Performance

- 09.07.26 - ErcanOPAK comment on SQL: Master Query Optimization for Performance

โšก Query Optimization = Database Performance Slow queries kill performance. Query optimization speeds up database. Faster responses, better UX. ๐Ÿ“ Optimization Techniques # 1. Avoid SELECT * — Bad SELECT * FROM users; — Good SELECT id, name, email FROM users; # 2. Use WHERE conditions — Bad SELECT * FROM users; — Good SELECT […]

Read More
SQL

SQL: Master Transactions for ACID Compliance

- 09.07.26 - ErcanOPAK comment on SQL: Master Transactions for ACID Compliance

๐Ÿ”„ Transactions = ACID Compliance Data integrity matters. Transactions ensure ACID. Atomic, Consistent, Isolated, Durable โ€” reliable data operations. ๐Ÿ“ Transaction Basics # Basic transaction BEGIN TRANSACTION; UPDATE accounts SET balance = balance – 100 WHERE id = 1; UPDATE accounts SET balance = balance + 100 WHERE id = 2; COMMIT; # With error […]

Read More
SQL

SQL: Use Stored Procedures for Database Logic

- 07.07.26 - ErcanOPAK comment on SQL: Use Stored Procedures for Database Logic

๐Ÿ“ฆ Stored Procedures = Database Logic Business logic in code is fine. Stored procedures move logic to database. Performance, security, consistency. ๐Ÿ“ Creating Procedures — Basic procedure CREATE PROCEDURE GetUserById @UserId INT AS BEGIN SELECT * FROM Users WHERE Id = @UserId; END; — Execute EXEC GetUserById 1; — With OUTPUT parameter CREATE PROCEDURE GetUserCount […]

Read More
SQL

SQL: Use Indexes to Boost Query Performance

- 07.07.26 - ErcanOPAK comment on SQL: Use Indexes to Boost Query Performance

โšก Indexes = Query Performance Slow queries kill performance. Indexes speed up queries. Find data fast, optimize SELECTs. Essential for database performance. ๐Ÿ“ Index Types # B-Tree Index (default) CREATE INDEX idx_users_email ON users(email); # Unique Index (enforces uniqueness) CREATE UNIQUE INDEX idx_users_email ON users(email); # Composite Index (multiple columns) CREATE INDEX idx_users_name_email ON users(name, […]

Read More
SQL

SQL: Use CTEs for Readable Complex Queries

- 07.07.26 - ErcanOPAK comment on SQL: Use CTEs for Readable Complex Queries

๐Ÿ“Š CTE = Readable Complex Queries Nested subqueries are messy. CTEs make queries readable. Break complex queries into steps. Essential for maintainable SQL. ๐Ÿ“ CTE Syntax WITH cte_name AS ( SELECT column1, column2 FROM table WHERE condition ) SELECT * FROM cte_name WHERE another_condition; — Multiple CTEs WITH cte1 AS ( SELECT … ), cte2 […]

Read More
SQL

SQL: Use Window Functions for Advanced Analytics

- 05.07.26 - ErcanOPAK comment on SQL: Use Window Functions for Advanced Analytics

๐Ÿ“Š Window Functions = Advanced Analytics Aggregates are limited. Window functions analyze data without grouping. Rankings, running totals, moving averages. ๐Ÿ“ Window Function Syntax SELECT name, salary, department_id, — Window function AVG(salary) OVER (PARTITION BY department_id) as dept_avg, RANK() OVER (ORDER BY salary DESC) as salary_rank, LAG(salary, 1) OVER (ORDER BY salary) as prev_salary FROM […]

Read More
SQL

SQL: Use Subqueries for Complex Data Retrieval

- 05.07.26 - ErcanOPAK comment on SQL: Use Subqueries for Complex Data Retrieval

๐Ÿ“Š Subqueries = Nested Power Single queries are limited. Subqueries nest queries inside queries. Complex conditions, derived data, advanced filtering. ๐Ÿ“ Subquery Examples — Users with orders over $100 SELECT name, email FROM users WHERE id IN ( SELECT user_id FROM orders WHERE total > 100 ); — Users with no orders SELECT name, email […]

Read More
SQL

SQL: Use Aggregate Functions for Data Analysis

- 05.07.26 - ErcanOPAK comment on SQL: Use Aggregate Functions for Data Analysis

๐Ÿ“Š Aggregate Functions = Data Insights Need totals, averages, counts? Aggregate functions summarize data. Essential for reporting and analytics. ๐Ÿ“ Basic Aggregates SELECT COUNT(*) AS total_rows, COUNT(DISTINCT column) AS distinct_values, SUM(amount) AS total_sum, AVG(amount) AS average, MIN(amount) AS min_value, MAX(amount) AS max_value, STDDEV(amount) AS std_dev FROM orders; — With GROUP BY SELECT customer_id, COUNT(*) AS […]

Read More
SQL

SQL: Use Views to Simplify Complex Queries

- 04.07.26 - ErcanOPAK comment on SQL: Use Views to Simplify Complex Queries

๐Ÿ“Š Views = Virtual Tables Complex queries repeated everywhere. Views simplify them. Create a view once, query it like a table. ๐Ÿ“ Create View CREATE VIEW active_users AS SELECT id, name, email, created_at FROM users WHERE status = ‘active’ AND last_login > ‘2024-01-01’; — Query the view SELECT * FROM active_users; — View with JOIN […]

Read More
SQL

SQL: Understand JOIN Types โ€” INNER, LEFT, RIGHT, FULL

- 04.07.26 - ErcanOPAK comment on SQL: Understand JOIN Types โ€” INNER, LEFT, RIGHT, FULL

๐Ÿ”— JOIN Types = Which Rows to Include INNER, LEFT, RIGHT, FULL โ€” which to use? Know the difference for correct results. ๐Ÿ“ JOIN Types — INNER JOIN (only matching rows) SELECT u.name, o.total FROM users u INNER JOIN orders o ON u.id = o.user_id; — Users without orders are excluded — LEFT JOIN (all […]

Read More
SQL

SQL: Prevent SQL Injection with Parameterized Queries

- 04.07.26 - ErcanOPAK comment on SQL: Prevent SQL Injection with Parameterized Queries

๐Ÿ”’ Never Concatenate User Input into SQL SQL injection is #1 web vulnerability. Parameterized queries prevent it. Always use parameters for user input. โŒ Vulnerable (SQL Injection) string query = “SELECT * FROM users WHERE email = ‘” + email + “‘”; var cmd = new SqlCommand(query, connection); // User input: admin’ OR ‘1’=’1 // […]

Read More
SQL

SQL: Understand Database Normalization (1NF, 2NF, 3NF)

- 24.06.26 - ErcanOPAK comment on SQL: Understand Database Normalization (1NF, 2NF, 3NF)

๐Ÿ“Š Normalization = Organized Data Bad design = duplicate data, anomalies. Normalization organizes data. 1NF, 2NF, 3NF โ€” reduce redundancy, improve integrity. ๐Ÿ“ First Normal Form (1NF) โŒ Not 1NF (repeating groups) Order: 1, Customer: Alice, Products: Laptop, Phone, Tablet โœ… 1NF (atomic values, separate rows) OrderID Customer Product 1 Alice Laptop 1 Alice Phone […]

Read More
SQL

SQL: DELETE vs TRUNCATE โ€” Know the Difference

- 24.06.26 - ErcanOPAK comment on SQL: DELETE vs TRUNCATE โ€” Know the Difference

๐Ÿ—‘๏ธ DELETE removes rows. TRUNCATE removes all rows. Both remove data. DELETE can use WHERE, fires triggers. TRUNCATE is faster, resets identity, cannot use WHERE. ๐Ÿ“ DELETE DELETE FROM users WHERE id = 123; DELETE FROM users WHERE status = ‘inactive’; – Can use WHERE (selective) – Fires triggers – Slower (logs each row) – […]

Read More
SQL

SQL: Use SELECT to Query Data from Tables

- 24.06.26 - ErcanOPAK comment on SQL: Use SELECT to Query Data from Tables

๐Ÿ“Š SELECT = Read Data from Database Data is useless if you can’t read it. SELECT queries data. The most used SQL command. ๐Ÿ“ Basic SELECT — All columns SELECT * FROM users; — Specific columns SELECT name, email FROM users; — Distinct values SELECT DISTINCT country FROM users; — With alias SELECT name AS […]

Read More
SQL

SQL: Use DELETE to Remove Data from Tables

- 21.06.26 - ErcanOPAK comment on SQL: Use DELETE to Remove Data from Tables

๐Ÿ—‘๏ธ DELETE = Remove Rows Data needs removal. DELETE removes rows. Be careful โ€” without WHERE, deletes all rows. Use transactions. ๐Ÿ“ Basic DELETE — Delete specific row DELETE FROM users WHERE id = 123; — Delete multiple rows DELETE FROM users WHERE status = ‘inactive’; — Delete all rows (careful!) DELETE FROM users; — […]

Read More
SQL

SQL: Use UPDATE to Modify Existing Data

- 21.06.26 - ErcanOPAK comment on SQL: Use UPDATE to Modify Existing Data

โœ๏ธ UPDATE = Change Existing Data Data changes over time. UPDATE modifies existing rows. Be careful โ€” without WHERE, updates all rows. ๐Ÿ“ Basic UPDATE — Update single column UPDATE users SET email = ‘newemail@example.com’ WHERE id = 123; — Update multiple columns UPDATE users SET name = ‘Alice Updated’, age = 31 WHERE id […]

Read More
SQL

SQL: Use INSERT to Add Data to Tables

- 21.06.26 - ErcanOPAK comment on SQL: Use INSERT to Add Data to Tables

๐Ÿ“ INSERT = Add Rows to Table Tables are empty at first. INSERT adds rows. Single rows, multiple rows, from other tables. ๐Ÿ“ Basic INSERT — Insert single row INSERT INTO users (name, email, age) VALUES (‘Alice’, ‘alice@example.com’, 30); — Insert with all columns INSERT INTO users VALUES (1, ‘Bob’, ‘bob@example.com’, 25); — Insert multiple […]

Read More
SQL

SQL: Use GROUP BY to Aggregate Data

- 20.06.26 - ErcanOPAK comment on SQL: Use GROUP BY to Aggregate Data

๐Ÿ“Š GROUP BY = Summarize Your Data Need totals, averages, counts? GROUP BY aggregates data. Sales by category, users by country, orders by month. ๐Ÿ“ Basic GROUP BY — Count per category SELECT category, COUNT(*) as product_count FROM products GROUP BY category; — Average price per category SELECT category, AVG(price) as avg_price FROM products GROUP […]

Read More
SQL

SQL: Use ORDER BY to Sort Query Results

- 20.06.26 - ErcanOPAK comment on SQL: Use ORDER BY to Sort Query Results

๐Ÿ“Š ORDER BY = Sort Your Results SELECT returns unsorted. ORDER BY sorts results. Ascending, descending, multiple columns. Essential for reporting. ๐Ÿ“ Basic ORDER BY — Ascending (default) SELECT * FROM users ORDER BY name; SELECT * FROM users ORDER BY name ASC; — Descending SELECT * FROM users ORDER BY age DESC; SELECT * […]

Read More
SQL

SQL: Use WHERE Clause to Filter Query Results

- 20.06.26 - ErcanOPAK comment on SQL: Use WHERE Clause to Filter Query Results

๐Ÿ” WHERE is the Most Important SQL Keyword SELECT * FROM users returns everything. WHERE filters results. Get only what you need. Faster queries, less data. ๐Ÿ“ WHERE Examples — Equality SELECT * FROM users WHERE id = 123; SELECT * FROM users WHERE email = ‘alice@example.com’; — Comparison SELECT * FROM users WHERE age […]

Read More
Page 1 of 10
1 2 3 4 5 6 … 10 Next ยป

Posts pagination

1 2 3 … 10 Next »
July 2026
M T W T F S S
 12345
6789101112
13141516171819
20212223242526
2728293031  
« Jun    

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (899)
  • How to make theater mode the default for Youtube (859)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (815)
  • How to enable, disable and check if Service Broker is enabled on a database in SQL Server (600)
  • Add Constraint to SQL Table to ensure email contains @ (583)
  • Average of all values in a column that are not zero in SQL (545)
  • How to use Map Mode for Vertical Scroll Mode in Visual Studio (512)
  • Find numbers with more than two decimal places in SQL (460)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes
  • Ajax: Use Axios for HTTP Requests
  • JavaScript: Understand Hoisting
  • HTML: Use Web Storage for Client-Side Data
  • CSS: Use Filter Effects for Visual Magic
  • Windows 11: Unlock God Mode for All Settings

Most Viewed Posts

  • Get the User Name and Domain Name from an Email Address in SQL (960)
  • How to add default value for Entity Framework migrations for DateTime and Bool (899)
  • How to make theater mode the default for Youtube (859)
  • Get the First and Last Word from a String or Sentence in SQL (840)
  • How to select distinct rows in a datatable in C# (815)

Recent Posts

  • C#: Use Using Statements for Resource Management
  • C#: Use Lambda Expressions for Concise Code
  • SQL: Use GROUP BY for Data Aggregation
  • .NET Core: Master Routing for Clean URLs
  • Git: Use Reset to Undo Local Changes

Social

  • ErcanOPAK.com
  • GoodReads
  • LetterBoxD
  • Linkedin
  • The Blog
  • Twitter
© 2026 Bits of .NET | Built with Xblog Plus free WordPress theme by wpthemespace.com