Posts

Showing posts from July, 2021

Resetting Identity column in SQL

 Identity is one of the useful property in column. It will help us to create auto incrementing column in sql. Before the arrival of this property this requirement was done manually by adding 1 with the maximum value of the specific column. We can see this property vividly in this article.I hope this will be helpful. CREATE TABLE tblEmployee (  EmployeeId INT  IDENTITY(1,1) NOT NULL,  EmployeeName VARCHAR(50) ) Assume that we have inserted lots of records.Now we have to reset the identity value. DECLARE @maxValue INT SELECT  @maxValue=ISNULL(MAX(EmployeeId),0) FROM tblEmployee DBCC CHECKIDENT ('[tblEmployee ]',RESEED,@maxValue) Now we have reset the identity column with the maximum record count of the table. Usually we will have situation to reset IDENTITY when " Primary key violation.cannot insert duplicate value.current identity value is()" this error comes.

Break statement in C#

Image
  Break is one of the useful statement in C#. This will help us to exit the current loop. I give a example below to understand it vividly. public void BreakStatementTest() { #region Break statement test...             Console.WriteLine("Please provide Number of iteration");             int totalCount = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("Please provide breakpoint number");             int breakPoint = Convert.ToInt32(Console.ReadLine());             Console.WriteLine("Total count:"+totalCount);             for (int i=0;i<totalCount;i++ )             {                 Console.WriteLine("Inside loop i=" + i);                 if (i == breakPoint) break;   ...