Skip to main content

Posts

Showing posts from 2011

How to Insert Data into Two Tables Using a Single SQL Query

Use SQL Server 2022 / modern T-SQL terminology. Prefer SET XACT_ABORT ON with TRY...CATCH for reliable transaction handling. Prefer OUTPUT INSERTED.Id over SCOPE_IDENTITY() when practical. Use explicit JOIN syntax instead of comma joins. Avoid table variables when a temporary table or direct INSERT...SELECT is more appropriate. Demonstrate identity retrieval and multi-row inserts cleanly. Include the application/API layer approach commonly used with .NET / EF Core / Dapper . Explain when to use a stored procedure versus application-managed transactions. Here is a much more current version you could use in your documentation. Inserting Data into Multiple SQL Server Tables When an application needs to insert data into multiple tables, the approach depends on whether the tables are independent or have a relationship such as a primary key / foreign key relationship. For SQL Server applications, especially modern .NET / ASP.NET Core applications, the preferred ap...

Abstract Class vs Interface in C#: What’s the Difference and When Should You Use Each?

Feature Abstract Class Interface Can be instantiated? No No Can contain implementation? Yes Yes, modern C# supports default implementations Can contain fields? Yes No instance fields Can have constructors? Yes No instance constructors Multiple inheritance No A class can implement multiple interfaces Shared state Yes No instance state Best for Closely related types Contracts/capabilities Dependency Injection Possible Very common Common implementation Strong support Limited/default implementations Versioning considerations Base-class changes can affect derived types Interface evolution requires care 10. Choosing Between an Abstract Class and an Interface Here are some practical guidelines. Use an abstract class when: The types have a strong "is-a" relationship . You need to share common implementation. You need common state or fields. You need constructors. You want to provide a common workflow. Derived classes are expected to follow a common architecture. Ex...