Friday, August 23, 2013

About Interfaces-properties methods in OOPS Concept

INTERFACES OOPS Concept

All the classes will Inherit interfaces methods. Abstract classes serve some similar operation  of interfaces. Inside the interface methods does not implemented. Interface will be define methods, properties and events

Interface is not a class it will represent with the key word 'interface'
Interface name contain with I prefix in the interface name.
Interface contain public as its modifiers.
Interface methods will be implemented in the class file which inherited interfaces.

A class can be Inherit more interfaces. Interfaces will support multiple inheritance.

code: 

//Interface contain methods without implementation inside the interface
public interface Ivalue
{
    string Name();
}

//Interface method declare in the inherited classes of the intefaces
Public class Operation : Ivalue
{
   public string Name()
  {
     return "MANOJ KUMAR";
   }
}

SAMPLE PROJECT 

//Interface
    public interface Isample
    {
        string fname
        {
            get;
            set;
        }

        string lname
        {
            get;
            set;
        }

        string Name();
    }

//Class inherited with interfaces

    public class Operation : Isample
    {

       protected string _fname;
       protected string _lname;

        public string fname
        {
            get
            {
                return _fname;
            }
            set
            {
                _fname = value;
            }
        }

        public string lname
        {
            get
            {
                return _lname;
            }
            set
            {
                _lname = value;
            }
        }

        public string Name()
        {
            return "First Name is " + fname + " & Last Name is " + lname;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Isample sam = new Operation();
            sam.fname = "Manoj";
            sam.lname = "Kumar";
            Console.WriteLine(sam.Name());
            Console.ReadLine();
        }
    }
}

Result Set






Thursday, August 22, 2013

About Abstract class - properties, methods and implementation

Abstract OOPS Concept


              Abstract class contain both Abstract method and Non Abstract Method.Abstract class can not be instantiated. Abstract class identified using keyword "abstract" in the class prefix. Abstract class can  also be defined with non abstract methods without containing Abstract methods .

code:abstract class
abstract class Operation
{
 //Abstract Method    
    public abstract int add(int num1,int num2);

    //Non Abstract Method
    public int sub(int num1, int num2)
     {
        return  num1-num2;
     }
}

 Abstract method inside abstract class does not have implementation.
 Abstract method can be identified using Keyword "abstract" in the method inside the abstract class.
Derived class of the abstract class contain the implementation of abstract methods.

Non Abstract method have implementation inside the abstract class.


Sample Abstract class Code

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

namespace AbstractClass
{
    abstract class  Operation
    {
    //Abstract Method    
    public abstract int add(int num1,int num2);

    //Non Abstract Method
    public int sub(int num1, int num2)
     {
        return  num1-num2;
     }


    };
    class Program : Operation
    {
        //Abstract method Override Operation in Derived Class
        public override int add(int num1, int num2)
        {

            return num1 + num2;
        }
        static void Main(string[] args)
        {
           //Object of Derived class Instance created to access Methods
            Program prog = new Program();
            Console.WriteLine("addition:{0} Subtraction:{1}",prog.add(10, 5),prog.sub(50, 25));
            Console.ReadLine();
        }
    }
}

Result Screen








Properties of Abstract class & methods:
  • Abstract class can not be instantiated.
  • Abstract method can not be declared as 'Private'
  • Abstract class cant use sealed keyword.
  • Abstract  method cant use Virtual keyword.
  • If the abstract method declares as Protected inside the abstract class In the derived class also abstract method with protected modifier.


FRESHERS INTERVIEW QUESTIONS IN SQL SERVER JOINS CONCEPT


Most of the database Interview part  contains JOINS

TYPES OF JOINS IN SQL SERVER  & ITS Examples
  • LEFT OUTER JOIN  
  • RIGHT OUTER JOIN
  • FULL OUTER JOIN
  • CROSS JOIN
  • INNER JOIN



/*Create two tables*/
CREATE TABLE RightTable( ID [Int], Name Varchar(50));
GO
CREATE TABLE LeftTable(ID [INT], Amount[int]);
GO

/*Insert datas to the tables*/
INSERT INTO RightTable Values
(1,'man'),(2, 'sam'),(3,'jon'),(5,'joe'),(7,'kan')
GO
INSERT INTO LeftTable Values
(1,250),(2,550),(4,390),(6,874)
GO

/*LEFT JOIN*/
It returns all the rows in the Left side table and unmatched rows in the right side table will be "NULL"

SELECT *
FROM LeftTable
LEFT JOIN RightTable
ON LeftTable.ID=RightTable.ID

Result Set




/*RIGHT JOIN*/

It returns all the rows in the Right side table and unmatched rows in the Left side table will be "NULL"

SELECT *
FROM LeftTable
RIGHT JOIN RightTable
ON LeftTable.ID=RightTable.ID

Result Set




/*INNER JOIN*/
It returns only  common rows in the both the tables.
SELECT *
FROM  LeftTable
INNER JOIN RightTable
ON LeftTable.ID = RightTable.ID

Result Set



/*FULL JOIN*/
It returns all the rows from  both the tables.
SELECT *
FROM LeftTable
FULL OUTER JOIN RightTable
ON  LeftTable.ID = RightTable.ID

Result Set





/*CROSS JOIN*/

SELECT *
FROM LeftTable
CROSS JOIN RightTable

Result Set






Wednesday, August 21, 2013

SPARSE COLUMN IN SQL SERVER 2008

SPARSE COLUMN IN SQL SERVER 2008

     Optimized Storing of Null value can be done  using SPARSE COLUMN.
     Storing a null in a sparse column takes up no space at all. . In other words, a SPARSE column is better at managing NULL and ZERO values in SQL Server. It does not occupy any space in the database.

Sample for Identifying the size using Sparse column

/*CREATE BOTH SPARSED TABLE and UNPARSED TABLE*/

CREATE TABLE UNPARSEDmark1 (
testNAME VARCHAR(100),
TESTDate smallDateTime)
GO

CREATE TABLE mark1(
testNAME VARCHAR(100) SPARSE,
TESTDate smallDateTime SPARSE)
GO

/*INSERT 45000 NULL ROWS IN BOTH TABLES*/

DECLARE @IDx INT=1
WHILE @IDx<50000
BEGIN
INSERT INTO UNPARSEDmark1 VALUES(NULL,NULL)
INSERT INTO mark1 VALUES(NULL,NULL)
SET @idx+=1
END
GO
/*CHECK THE SPACE USED BY BOTH TABLES*/
sp_spaceUsed 'UNPARSEDmark1'
GO
sp_spaceUsed 'mark1'
GO
















Advantages of SPARSE Column
  • A SPARSE column saves database space when there is zero or null values in the database.
  • INSERT, UPDATE, and DELETE statements can reference the SPARSE columns by name.
  • We can get more benefit of Filtered indexes on a SPARSE column.
Limitation of SPARSE Column
  •  SPARSE column must be nullable and cannot have the ROWGUIDCOL or IDENTITY properties.
  • A SPARSE column cannot be data types like text, ntext, image, timestamp, user-defined data type, geometry, or geography.
  • Merge replication does not support SPARSE columns.
  • The SPARSE property of a column is not preserved when the table is copied.