Search This Blog

Friday, June 13, 2014

Difference between Abstract Class and Interface

SrNo Abstract Class Interface
1
Abstract class is a class that contain complete 
and abstract (incomplete) both types of members
Interface is a type which contains only the signatures of methods, delegates or events
2
Abstract class can be inherited by other classes 
but cannot be instantiated.
Interfaces are implemented by a class
3
A class can inherit only one abstract class A class can implement multiple interfaces
4
Abstract class can contain data members, constructors Interface doesn't contain data members, constructors
5
We can not achieve multiple inheritance  We can achieve multiple inheritance
6
Can contain access modifiers like public, private, protected, etc. for functions, snubs, properties. Doesn't contain access modifies. By default, everything is public.
7
Members of abstract class can be static. Members of interface cannot be static.

Thursday, June 12, 2014

Serialization and Deserialization in c#

Serialization is the process of converting an object into stream of bytes for storage and data transmission.
Deserialization is the reverse process of converting stream of bytes to their original form.

Advantages of Serialization:
  1. Facilitate the transportation of an object through a network
  2. Create a clone of an object
Disadvantage of Serialization:
  1. Resource overhead that is involved in serializing and deserializing the data.
  2. Latency issues that are involved for transmitting the data over the network.
  3. Serialization is a slow process.

Tuesday, June 3, 2014

Restore backup in SQL Server using SQL Scripts


1) Place the backup file <SampleBackupFile.bak> to an accessible location <E:\SampleFolder>.



2) Retrieve the mdf and ldf file names of the database from the backup file using the below query.


RESTORE FILELISTONLY

FROM DISK = 'E:\SampleFolder\SampleBackupFile.bak'


3) Now restore the database <SampleDB> using the below query.


RESTORE DATABASE <SampleDB>

FROM DISK = 'E:\SampleFolder\SampleBackupFile.bak'
WITH MOVE 'mdf_filename' 
        TO 'E:\SampleFolder\SampleMDFFile.mdf',
     MOVE 'ldf_filename' 
        TO 'E:\SampleFolder\SampleLDFFile.ldf'

Sunday, June 1, 2014

TRIM function in SQL Server

The TRIM function in SQL Server is used to remove white spaces.

There are 3 types of TRIM:
1)TRIM(<InputString>) - Removes white spaces from both left and right side of the input string.
2)LTRIM(<InputString>) - Remove white spaces from left side of the input string.
3)RTRIM(<InputString>) - Removes white spaces from right side of the input string.

Type Query Output
TRIM SELECT TRIM(' Hello ') Hello
LTRIM SELECT TRIM(' Hello') Hello
RTRIM SELECT TRIM('Hello ') Hello

Search any SP/Table/View/Function in SQL Server

SELECT DISTINCT so.name [Name], so.xtype [Type]
FROM sysobjects so INNER JOIN syscomments sc 
     on so.id = sc.id
WHERE sc.text like '%<SearchText>%'

Reverse a string without using string function in C#

------------------------------------------
Input String -> "Hello"
Expected Output -> "olleH"
------------------------------------------

string inputString = "Hello";
string outputString = "";
char[] array inputString.ToCharArray();
Array.Reverse(array);
outputString  = new string(array);
------------------------------------------

Saturday, December 1, 2012

Materialized Views in SQL Server


Materialized Views
  1. In SQL, a view is a virtual table based on the result-set of an SQL statement.
  2. A view contains rows and columns, just like a real table. The fields in a view are fields from one or more actual tables in the database.
  3. You can add SQL functions, WHERE and JOIN statements to a view and present the data as if the data were coming from one single table.
  4. But if a view performs an operation on millions of records, performance of the view will decrease dramatically and if this operation is performed frequently then the view will access millions of records repeatedly. 
  5. To resolve this issue, materialized view comes into picture. 
  6. A materialized view is defined same as a regular view but the output is stored in a physical table which is updated frequently whenever the actual tables change. 
  7. They are useful to aggregate data in business intelligence applications with complex queries.