Sql Server Interview Questions and Answers (1758) - Page 52

How to Add a column,with a default value as 'ÁA' in a Status column and current date in created_date column to an employee_master table?

Alter Table Employee_Master

Add
Status Varchar(2) Null Default AA
,Created_Date DateTime Null Default GetDate();

How to remove an existing column in existing table?

With the help of Drop column we can remove any column from any table.

For Example:-
Alter Table table_name

Drop Column column_name.

How to change Data-Type of a column in Sql-Server?

With the help of Alter Column,we can change data-type of a column.

Syntax:-
Alter Table table_name

Alter Column column_name datatype.


For Example:-
Alter Table employee_master

Alter Column employee_code varchar(30);

How to change Data-Type of a column in My-Sql Database?

With the help of Modify Column,we can change data-type of a column in MySql database?

Syntax:-
Alter Table table_name

Modify Column column_name datatype.


For Example:-
Alter Table employee_master

Modify Column employee_code varchar(30);

How to create an Index on Table?

With the help of Create Index statement,we can create any index on any column in a table.

Syntax:-
Create Index index_name

On table_name(column_name);


For Example:-
Create Index idx_employee_id

On Employee_Master(employee_id);

How to create an Index on Table on multiple columns?

With the help of Create Index statement,we can create any index on any column(s) in a table.

Syntax:-
Create Index index_name

On table_name(column_name1,column_name2,---,column_n);


For Example:-
Create Index idx_employee_id

On Employee_Master(employee_id,employee_code);

What is the output of below query? declare @value varchar(20) = 'vish'; select coalesce(@value,'') as a

NOTE: This is objective type question, Please click question title for correct answer.
What is the output of value in below query? declare @value varchar(20); select coalesce(@value,'vishal') as value;

NOTE: This is objective type question, Please click question title for correct answer.
How to set all letters or text in lower-case?

We can use Lower in-built Sql-Server function to set all letters or text in lower-case.

For Example:-

Select Lower('VISHAL') as Name;


Output:
vishal
What is the output of below query? select isnull('rajesh','sathua');

Answer is rajesh.
Actually IsNull checks for 1st expression value,if 1st expression value is null then it return 2nd expression value.

Here,1st expression value is Rajesh and also 1st expression is not null.Then IsNull will return Rajesh.
What output below query will return? Select NUllIf(1,1) As a;

NULLIF returns Null if the 2 expressions are equal otherwise it returns first argument value.

Here both expressions have same value that is 1.
So NullIf will return Null.So the output will be null.
How to avoid duplicate values in SQL-Server?

With the help of Distinct clause,we can avoid duplicate records:-

Syntax:-
Select Distinct column_name from tbl_name;


For Example:-

select distinct project_name from project_master where project_name is not null;

How to create a View in Sql Server?

With Create View statement,we can create view inside databases.

For Example:-

create view vw_requisition

as
select requisition_id,requisition_raised_by,requisition_closed_by
from requisiton_master;

How to access View?

Views can be accessed by Select statement as we can access any table with select statement:

Select * from vw_requisition;


Where vw_requisition is my View Name.
How to check whether record is present or not in a table?

With the help of Exists in-built sql server function,we can check where record is present in a Table or Not.It returns true if record is present otherwise returns false.

For Example:-
if exists(select project_name from project_master where upper(project_name) = upper('Hospital Management'))

begin
print 'True - Present';
end
else
print 'False - Not Present';

Is there any difference between Primary Key and Unique key with not null?

Yes, ofcource the Primary key and unique key with not null are different as below:
1.Primary key will not allow null values whereas the unique key will allow.
2.in a table, there can be only one Primary Key column where as Unique key can be contained with any number of columns.
3.primary key is non-clustered index whereas unique key is a clustered index.
What is the use of nullif function?

Nullif function contains two parameters.
It returns null values when two expressions are equal, returns the first parameter if not equal.
Eg:
If the first parameter is dotnet and second also dotnet, then the result will be null.
If the first parameter is dotnet and second is funda, then the result will be dotnet.
How to check whether record exists in table or not?

Use count function to check whether record is present in a table or not.

For Example:-
Select count(code_id) from code_details where code_value = 'apt0';


It will return number of record count related to code_value 'apt0'
What is the use of DQS?

DQS is a new feature introduced in sql2012.
It is used to check the quality of the data and also clean the data as required.
It used for many data quality tasks like enrichment, monitoring, data correction and de-duplication.
Data cleansing and quality tasks can be done with cloud based reference data services provided by numerous data providers.
Integrity of the data can also be analysed.
What does Count function return?

Count function returns integer value meaning it returns no of records if present otherwise return 0.
In other words,we can say,Count function is the simplest function and very useful in counting the number of records,which are expected to be returned by a SELECT statement.
It always returns an int data type value.
Found this useful, bookmark this page to the blog or social networking websites. Page copy protected against web site content infringement by Copyscape

 Interview Questions and Answers Categories