Posts

Showing posts from January, 2015

Sibling number and get largest number in the family using C#

Image
Following code will illustrate to get largest number from given sibling numbers.

static void Main(string[] args)
        {
            int n2 = 3456789;
            var digits = new List<int>();
            int temp = 0;
            for (; n2 != 0; n2 /= 10)
            {
                digits.Add(n2 % 10);
            }
            var arr2 = digits;
            for (int num = 0; num < arr2.Count; num++)
            {
                for (int sort = 0; sort < arr2.Count - 1; sort++)
                {
                    if (arr2[sort] < arr2[sort + 1])
                    {
                        temp = arr2[sort + 1];
                        arr2[sort + 1] = arr2[sort];
                        arr2[sort] = temp;
                    }
                }
            }

            for (int i = 0; i < arr2.Count; i++)
                Console.Write(arr2[i] + "");
            Console.ReadKey();
        }

Temporarily avoid foreign key constraint in sql server

Image
We can avoid foreign key constraint temporarly by using following code

--ALTER TABLE Station NOCHECK CONSTRAINT MyConstraint

ALTER TABLE TABLE_NAME NOCHECK CONSTRAINT FK_CONSTRAINTNAME

select * from TABLE_NAME where COLUMN_NAME='UPDATEDVALUE'

update TABLE_NAME set COLUMN_NAME='UPDATEDVALUE' where COLUMN_NAME='WHERECONDITION_VALUE'

select * from TABLE_NAME where COLUMN_NAME='WHERECONDITION_VALUE'
-- Enable single constraint

ALTER TABLE TABLE_NAME CHECK CONSTRAINT FK_CONSTRAINTNAME