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

How to rename employee_contact column to employee_contact_number column in employee_master table.

Exec sp_rename 'employee_master.employee_contact', 'employee_contact_number', 'Column';

What is the use of @@Rowcount in Sql Server?

@@Rowcount is an in-built Sql Server function which returns number of rows affected by last executed statement.

Example:
Insert into table1(id,name) values(1,'abc');

Select @@Rowcount;

What is the return type of @@Rowcount function?

@@Rowcount function always returns numeric value.

@@Rowcount is an in-built Sql Server function which returns number of rows affected by last executed statement.
What is the use of Reverse function in Sql Server?

The Reverse function is a string function which is used to return the reverse of a string value.

Syntax:
Reverse(expression_value)


For Example:-
Select Reverse('DotnetFunda') as Reversed_value;


Output:
adnuFtentoD

Give an example of a Reverse function?

Select Reverse('VishalNeeraJ') as output1;

Select Reverse(123) as output1;


Output:
JareeNlahsiV
321

What is the use of Stuff function in Sql Server?

Stuff function is also a String function which works exactly same as Replace function except for searching any value from specified string.It replaces portion of the string in a specified string.

Syntax:
Stuff(expression_value1,start_position,string_length,expression_value2);


Where:
expression_value1: Is our any string a string from which portion of characters will be replaced.It can be a constant,variable,or column of either character or binary data.

string_length: Is a Numeric value that specifies starting index to replace characters from expression_value1.If we specify negative value or greater than the expression_value1 string then Stuff function returns null value.

string_length: Is also a Numeric Value which specifies number of characters to be replaced from expression_value1.If negative value is specified as length,then stuff function returns null value.

expression_value2: Is a new string to be changed from expression_value1.
What is the use of Space function and explain example?

Space is an in-built Sql Server function which returns a string of the specified number of spaces.
Whatever the number we provide in space function,will generate space characters.In short we can say that,it is used for giving the spaces between characters.

For Example:
Select Space(5);

It will generate 5 space characters.

SELECT 'Vishal' + SPACE(1) + 'Neeraj';


Output:
Vishal Neeraj
The keyword SET is used in which of the following statements?

NOTE: This is objective type question, Please click question title for correct answer.
Which statements can be used to process the rows in a cursor?

NOTE: This is objective type question, Please click question title for correct answer.
What is the ouput of the following query, SELECT COUNT(managerId) FROM Employee empId Name managerId 789 select 45 356 update NULL 698 delete 78

The output will be 2.
Because even though we have three rows but a single row does not contain managerId which means it contains NULL value.
Since the COUNT statement does not allow NULLS, the output is 2.
Is the following statement correct, Sometimes select count(*) gives fewer rows than select count(val)

NOTE: This is objective type question, Please click question title for correct answer.
Should we necessarily supply the direction next or prior while using Fetch statement?

NOTE: This is objective type question, Please click question title for correct answer.
What kind of query can be used to restrict the rows returned by a query?

NOTE: This is objective type question, Please click question title for correct answer.
How to Rename a column in a Table which is already exists?

Use sp_rename Sql Server system stored procedure to rename any column exists in a Table.

Syntax Is:
sp_rename 'Table_Name.[Old_Column_Name]','New_Column_Name', 'Column'

How to rename existing Table in Sql Server?

We can rename the Table Name with the sp_rename Sql Server command .

Syntax Is:
sp_rename 'Old_Table_Name','New_Table_Name';

How to get Date part from given date or current date?

Select Convert(Varchar(10),Getdate(),101) as date_only;


101 is a format provided by dot net for extracting date part from given date in sql server.

Output:02/18/2014 i.e. MM/dd/yyyy
How to get Time from given date?

Select Convert(Varchar(8),Getdate(),108) as time_only;


108 is a format provided by dot net for extracting time part from given date in sql server.
What is an index and types of indexes. How many number of indexes can be used per table

Indexs are used for the faster retrivel of data.

Two types of indexes
1)Cluster index,2)Non-clustered index

clustered index is physically stored a table can have 1 clustered index
non clustered index is logically stored a table can have 249 non clustred index

CLUSTERED INDEX:
Clustered index will be created by default when u create primary key on a column. So we can create one clustered index per table. clustered index is stored in serial passion.

NON CLUSTERED INDEX:
Non clustered index will be created automatically when u create unique key on a column. A table can have no.of unique keys, so we can create no.of non clustered indexes per table.
Can we have multiple primary key on the table?

No,we do not have.Because primary key enforces the uniqueness.
So if we are creating any table using create table statement and assigning primary key to more than one column.Then it will not allow.It can be only one in any table.
How to assign primary key to any column in the table?

Suppose,i want to create table called project_master and to assign a primary key to ID column,just give primary key after datatype as

create table Project_Master

(
project_id int primary key,
project_name varchar(50)
)

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