Thursday, 28 December 2017

Alter table command

Alter table command
Alter table command is used to modify the defination of table by modifying the table column .
Alter table statement can be used to delete, add and modify the existing table.

alter table emp add  test111  int

alter table emp drop column test111

Friday, 22 December 2017

Inheritance in C#

Inheritance in C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InheritanceDetails
{
    //http://www.onlinebuff.com/article_oops-principle-inheritance-in-c-with-an-example_16.html

    /// <summary>
    /// Inheritance:
    /// 1. Inheritance is the process of creating new classes from existing classes.
    /// 2. Newly created class is called as derived class and existing class (Main class)
    ///    is called as Base class.
    /// 3. Reusability is main feature of inheritance
    /// 4. In C# we have single heritance and multiple inheritance. multiple inheritance in C# is
    ///    achieved through interfaces.
    /// 5. If we create Base class object which points to Base class then this object have access
    ///    only to base class methods
    /// 6. If we create Base class object which points to Derived class then this
    ///    object have access only to base class methods and not to child class methods and data members
    /// 7. If Child class object is created which points to base class then
    ///    this object have access of base as well as child class methods and member types.
    ///
    /// </summary>
    class Program
    {
        static void Main(string[] args)
        {
            //access to base class methods and members
            BaseClass baseClassObject = new BaseClass();
            baseClassObject.PrintBaseClassName();
            baseClassObject.BaseClass1 = 10;

            //access to base class methods and members
            BaseClass objectBaseClass = new ChildClass();
            objectBaseClass.PrintBaseClassName();
            objectBaseClass.BaseClass1 = 11;

            //access to base class methods and members
            BaseClass objectBaseClass1 = new ChildofChildClass();
            objectBaseClass1.PrintBaseClassName();
            objectBaseClass1.BaseClass1 = 12;

            //access to base class as well as child class methods and data types
            ChildClass objectChildClass = new ChildClass();
            objectChildClass.PrintBaseClassName();
            objectChildClass.PrintChildClassName();
            objectChildClass.BaseClass1 = 13;
            objectChildClass.ChildClass1 = 14;


            // Execute ChildofChildClass methods only
            ChildClass ChildClassObject = new ChildofChildClass();
            ChildClassObject.PrintBaseClassName();
            ChildClassObject.PrintChildClassName();
            ChildClassObject.BaseClass1 = 15;
            ChildClassObject.ChildClass1 = 16;

            ChildofChildClass objectChildofChildClass = new ChildofChildClass();
            objectChildofChildClass.BaseClass1 = 17;
            objectChildofChildClass.ChildClass1 = 18;
            objectChildofChildClass.ChildofChildClass1 = 19;
            objectChildofChildClass.PrintBaseClassName();
            objectChildofChildClass.PrintChildClassName();
            objectChildofChildClass.PrintChildToChildClassName();
            Console.Clear();

            Car car = new Car();
            car.Company = "Maruti";
            car.ModelName = "Swift";
            car.PrintCar(car.Company, car.ModelName);

            Car carSwift = new Swift();
            carSwift.Company = car.Company;
            carSwift.ModelName = car.ModelName;
            carSwift.PrintCar(carSwift.Company, carSwift.ModelName);

            Car carSwiftDzire = new SwiftDzire();
            carSwiftDzire.Company = car.Company;
            carSwiftDzire.ModelName = car.ModelName;
            carSwiftDzire.PrintCar(carSwiftDzire.Company, carSwiftDzire.ModelName);

            Swift swift = new Swift();
            swift.Company = car.Company;
            swift.ModelName = car.ModelName;
            swift.isSedan = false;
            swift.Varient = "ZXI";
            swift.PrintCar(swift.Varient, swift.isSedan);

            SwiftDzire swiftDzire = new SwiftDzire();
            swiftDzire.bootSpace = "300 Lit.";
            swiftDzire.Company = car.Company;
            swiftDzire.ModelName = "Swift Dzire";
            swiftDzire.isSedan = true;
            swiftDzire.Varient = "VXI";
            swiftDzire.fuelType = "Petrol";
            swiftDzire.PrintCar(swiftDzire.bootSpace, swiftDzire.fuelType);


            Console.ReadLine();
        }
    }

    public class BaseClass
    {
        public int BaseClass1 { get; set; }

        public void PrintBaseClassName()
        {
            Console.WriteLine("Class name is Base Class");
        }
    }

    public class ChildClass : BaseClass
    {
        public int ChildClass1 { get; set; }

        public void PrintChildClassName()
        {
            Console.WriteLine("Class name is Child Class");
        }
    }

    public class ChildofChildClass : ChildClass
    {
        public int ChildofChildClass1 { get; set; }

        public void PrintChildToChildClassName()
        {
            Console.WriteLine("Class name is Child of Child Class");
        }
    }
}

//****************////****************////****************////****************////****************////****************//
// Inheritance denotes "Is a" relationship
//  1. Ineritance means parent -child relationship. by using inheritance methodology we can create
//     new class from existing class.
//  2. new class is called as child class or derived class or sub class or specialized class.
//     and existing class is called as base class or parent class
//     or super class or generalized class
//  3. Reusability of code is main feature of inheritance.
//     it means we can use the existing code again and again.
//  4. Inheritance types : Single, Multiple, Multilevel, Hierarchical and Hubrid.
//     Single => Base class has derived class ==> Class A is base class of Class B
//     Multiple => due to complexity it is not possible in C#. but it can be achieved through interfaces in C#.
//     Multilevel => base class have derived class and this derived class again have another derived class => Class A is base class
//     of Class B and Class C is derived class of class B
//     Hierarchical => two different classes derives same base class  => Class  A is base class which derives Class Two different classes Class B and Class C.
//     Hubrid => This is a special type of inheritance and can be achieved from any combination of single,
//     hierarchical and multi level inheritance known as hybrid inheritance.
//  5. Inheritance uses IS a relationship. meaning Swift dzire is a Car, Wagaon R is a Car. so Car is base class which has Swift and WagonR as child classes.

//****************////****************////****************////****************////****************////****************//

public class Car
{
    public string ModelName { get; set; }
    public string Company { get; set; }
    public void PrintCar(string Company, string ModelName)
    {
        Console.WriteLine("Company: " + Company + " Model: " + ModelName);
    }
}

public class Swift : Car
{
    public string Varient { get; set; }
    public bool isSedan { get; set; }
    public void PrintCar(string Varient, bool isSedan)
    {
        Console.WriteLine("=============**********================");
        base.PrintCar("Maruti", "Swift");
        Console.WriteLine("Varient: " + Varient + " Sedan: " + isSedan);
        Console.WriteLine("=============**********================");
    }
}

public class SwiftDzire : Swift
{
    public string bootSpace { get; set; }
    public string fuelType { get; set; }

    public void PrintCar(string bootSpace, string fuelType)
    {
        Console.WriteLine("=============**********================");
        base.PrintCar("Maruti", "SwiftDzire");
        base.isSedan = true;
        Console.WriteLine("bootSpace:" + bootSpace + " Sedan: " + base.isSedan + " Fuel Type: " + fuelType);
        Console.WriteLine("=============**********================");
    }

}

Tuesday, 5 December 2017

Temporary Table

Temporary Table
Temporary table is same as the table, it creates the dummy table on the database
Ttemp table is available whem the connection is live or the session is live.
Once the session is expired the temporary table is deleted.
Temporary table are created at runtime
There are two types of temp table
1)      local temporary table
2)      global temporary table

Local temp tables are only available to the current connection for the user; and they are automatically deleted when the user disconnects from instances. Local temporary table name is stared with hash ("#") sign.


Global Temporary tables name starts with a double hash ("##"). Once this table has been created by a connection, like a permanent table it is then available to any user by any connection. It can only be deleted once all connections have been closed.

Temporary tables are stored at Temp DB database



select * into #EmployeesTempTable from Employees
--or
create table #EmpTemp
(id int,
name varchar(20))

--or
create table ##EmpTemp
(id int,
name varchar(20))

drop table ##EmpTemp