How to set a default value for an existing column
Syntax:ALTER TABLE [TableName] ADD CONSTRAINT [ContraintName] DEFAULT 'Value' FOR [ColumnName];Example:ALTER TABLE EmpMaster ADD CONSTRAINT Test DEFAULT 'Pune' FOR City;
OOPS Concepts, OOPS interview questions, C#.Net interview questions, .Net framework interview questions, Asp.Net interview questions, SQL server interview questions, WCF interview questions, WPF interview questions, Angular Js interview questions
Syntax:ALTER TABLE [TableName] ADD CONSTRAINT [ContraintName] DEFAULT 'Value' FOR [ColumnName];Example:ALTER TABLE EmpMaster ADD CONSTRAINT Test DEFAULT 'Pune' FOR City;
Syntax:
ALTER TABLE {TABLENAME}
ADD {COLUMNNAME} {TYPE} {NULL| NOT NULL}
CONSTRAINT {CONSTRAINT_NAME} DEFAULT {DEFAULT_VALUE}
[WITH VALUES]
Example:
ALTER TABLE EmployeeMaster
ADD City NOT NULL
CONSTRAINT EmpMaster_City DEFAULT 'Pune'
SELECT
[xmlColumn].value('(/Employee//EmployeeNumber/node())[1]','nvarchar(max)')as EmployeeNumber,
[xmlColumn].value('(/Employee//Department/node())[1]', 'nvarchar(max)')
as Department
FROM [TableName]
using System;
class Program
{
static void Main()
{
// 1 - string is Null
string sFirstName = null;
if (string.IsNullOrEmpty(sFirstName))
{
Console.WriteLine("First Name is Null or empty");
}
else
{
Console.WriteLine("First Name is having some value");
}
// 2. string is empty
string sFirstName = "";
if (string.IsNullOrEmpty(sFirstName))
{
Console.WriteLine("First Name is Null or empty");
}
else
{
Console.WriteLine("First Name is having some value");
}
// 3. string - having some value
string sFirstName = "Jatin Nahar";
if (string.IsNullOrEmpty(sFirstName))
{
Console.WriteLine("First Name is Null or empty");
}
else
{
Console.WriteLine("First Name is having some value");
}
}
}
Output as below:
1) First Name is Null or empty
2) First Name is Null or empty
3) First Name is having some value
![]() |
| Inheritance Hierarchy |
![]() |
| Diamond Problem |
interface ITest
{
void DoTask();
}
public class ClassA : ITest
{
public void DoTask()
{
int a;
}
}
public class ClassB : ITest
{
public void DoTask()
{
int a;
}
}
![]() |
| Advantage of abstract class over Interface |
//abstract class with abstract method, and its implementation in both derived classes.
abstract class AbsClass
{
void DoTask();
}
public class ClassA : AbsClass
{
public void DoTask()
{
int a;
}
}
public class ClassB : AbsClass
{
public void DoTask()
{
int a;
}
}
public abstract class AbsClass
{
// abstract method
public abstract void DoTask();
//Non- abstract method
void DoWork()
{
int a;
}
}
public class ClassA : AbsClass
{
public override void DoTask()
{
int a;
}
}
public class ClassB : AbsClass
{
public override void DoTask()
{
int a;
}
}
Abstract Class Vs Interface in C#.Net | ||
Memebers Allowed | Abstract as well as non abstact allowed. | Only abstract members are Allowed. |
Implementation of methods in derived classes | Not necessary to implement all the methods of base (abstract) class for derived classes. | The derived class must implement all the methods of interface. |
Fields | Can be defined. | Can not be defined. |
Access Modifier | Can contain access modifiers for the functions, properties. | Cannot have access modifiers for the functions, properties all members of interface is assumed as public. |
Advantage of Interface over Abstract class | A class may inherit only one abstract class. | A class may inherit several interfaces. |
Advantage of Abstract class over Interface | Abstract classes can add more functionality without destroying the child classes that were using the old version. | In an interface, creation of additional functions will have an effect on its child classes, due to the necessary implementation of interface methods to classes. |
![]() |
| Interface implementation in Derived classes |
![]() |
| Abstract Class implementation in derived classes |