Wednesday, 12 March 2025

Find duplicates records IN sql table

 SQL duplicate records

select EMPID ,Forminfoid,FormName ,count(*) as dcount 

from  tbl_FilesMigrationLogs

group by EMPID,Forminfoid,FormName

HAving COUNT(*) >1


track by multiple columns.

Real time issues

 azure blob name spaces issue getting filename has different characters so getting error that 

path not found.
2.don't use increment id as save for the other table  
3.use country code instad of name may be name will changes

SQL Quryies

 1.string saparations. query 

select  STRING_AGG(EmpID,',')  From

(

SELECT EmpID FROM tbl_Employee  ORDER BY updatedOn DESC

OFFSET 70 ROWS FETCH NEXT 20 ROWS ONLY

) AS S;

2.in one table you need to get order by for 2 columns
ex:workflowid inorder after that sequence in desc order
for this user 

SELECT WorkFlow_ID, User_ID, MAX(Approver_Sequence) AS MaxApproverSequence

FROM tbl_WorkFlowMembers

WHERE Division_ID='RAIL'

GROUP BY WorkFlow_ID, User_ID

ORDER BY WorkFlow_ID, MaxApproverSequence DESC;

Monday, 10 March 2025

Duplicate records find and delete

 Check duplicate count based on 3 columns combo


select EMPID,FORMinfoID,FormName,Count(*) as counts from tbl_FilesMigrationLogs 

group by EmpID,FormInfoID,FormName

HAVING COUNT(*) >1; 

WITH CTE AS (
    SELECT EMPID,FORMinfoID,FormName,
           ROW_NUMBER() OVER (PARTITION BY EmpID, FormInfoID,FormName ORDER BY  EMPID) AS rn
    FROM tbl_FilesMigrationLogs
)
Select * FROM CTE WHERE rn > 1;

but for the both quries getting count different..

Friday, 7 March 2025

sql ch2

 Find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table. The STATION table is described as follows

To find the difference between the total number of CITY entries and the number of distinct CITY entries in the STATION table, you can use the following SQL query:


SELECT COUNT(CITY) AS TotalCityCount, COUNT(DISTINCT CITY) AS DistinctCityCount, (COUNT(CITY) - COUNT(DISTINCT CITY)) AS CityCountDifference FROM STATION;

SQL

 Query a list of CITY names from STATION for cities that have an even ID number. Print the results in any order, but exclude duplicates from the answer.

The STATION table is described as follows:

LTInterview

 

ChatGPT said:

In C#, memory is managed using different types of memory allocation and regions. Here are the primary memory types you will encounter:

1. Stack Memory

  • Purpose: Stores value types (primitive types like int, float, bool, structs, etc.) and local variables.
  • Managed by: The runtime, automatically handled (allocated when a method is called and deallocated when it exits).
  • Characteristics:
    • Fast: Allocations and deallocations are quick since they follow a Last-In-First-Out (LIFO) order.
    • Size Limit: The stack has a fixed size (typically around 1 MB to 8 MB).
    • Lifetime: Memory is automatically cleaned up when the method/variable goes out of scope.
    • Access: Direct access with no need for garbage collection.
    Example:
    csharp
    void Method() { int x = 10; // 'x' is stored in stack memory }

2. Heap Memory

  • Purpose: Stores reference types (objects, arrays, strings, etc.) and instances of classes.

  • Managed by: The garbage collector (GC) automatically cleans up unused objects.

  • Characteristics:

    • Slower than stack memory: Memory allocation and deallocation are slower since GC manages cleanup.
    • Dynamic Size: Memory size can grow as needed, as long as there is enough system memory.
    • Lifetime: Objects remain in heap memory until they are no longer referenced, and garbage collection frees them.
    • Access: References to heap objects are stored in the stack.

    Example:

    csharp
    class Person { public string Name; } void Method() { Person person = new Person(); // 'person' is allocated on the heap person.Name = "John"; }

3. Static Memory

  • Purpose: Stores static variables and global data (variables defined with the static keyword).

  • Managed by: The runtime and remains available throughout the application’s lifetime.

  • Characteristics:

    • Lifetime: Static variables live for the duration of the application.
    • Access: Static members can be accessed without creating an instance of the class.
    • Usage: Used for data or methods that should be shared across all instances of a class.

    Example:

    csharp
    class MyClass { public static int counter = 0; // Static variable } void Method() { MyClass.counter++; // Access static variable }

4. Code (Method) Memory

  • Purpose: Stores the compiled code (the executable instructions) for methods and functions.
  • Managed by: The runtime when the program is loaded into memory.
  • Characteristics:
    • Read-only: The code cannot be modified during execution.
    • Lifetime: The code remains in memory for the entire duration of the application.

5. Thread-Local Memory

  • Purpose: Stores data specific to the thread (like local variables for each thread).
  • Managed by: The runtime and is isolated to the thread that owns it.
  • Characteristics:
    • Thread-Specific: Each thread has its own thread-local memory for its local variables.
    • Used for Multi-threading: Essential when managing multiple threads in parallel operations.

Memory Management in C#

  1. Garbage Collection (GC): C# uses a garbage collector to manage memory on the heap, freeing memory of objects that are no longer in use (i.e., no references to them exist).

    • The GC periodically runs to reclaim memory from unused objects.
    • Generations: The GC uses a generational approach to optimize memory collection (Young Generation, Old Generation).
  2. Memory Allocation:

    • Stack: Automatically allocated and deallocated.
    • Heap: Objects are created dynamically via new and deallocated by the GC when no references exist.
  3. Memory Leaks:

    • While the garbage collector manages memory, improper management of references (e.g., keeping unnecessary references alive) can lead to memory leaks.

Conclusion

  • Stack: Fast, short-lived, and used for value types and local variables.
  • Heap: Slower, long-lived, and used for reference types (objects, arrays, etc.).
  • Static Memory: Used for static variables and shared data.
  • Code Memory: Stores method instructions.
  • Thread-Local Memory: Isolated to threads.

Let me know if you'd like a deeper dive into garbage collection or memory management strategies in C#! 🚀

junior devops engnr

  Position Overview: We are a growing start up seeking a Junior Azure DevOps Engineer with 2 to 3 years of experience to support our Azure...