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

How to get @@ERROR and @@ROWCOUNT at the same time?

If @@Rowcount is checked after Error checking statement then it will have 0 as the value of @@Recordcount as it would have been reset. And if @@Recordcount is checked before the error-checking statement then @@Error would get reset. To get @@error and @@rowcount at the same time do both in same statement and store them in local variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR
Can SQL Servers linked to other servers like Oracle?

SQL Server can be linked to any server provided it has OLE-DB provider from Microsoft to allow a link. E.g. Oracle has an OLE-DB provider for oracle that Microsoft provides to add it as linked server to SQL Server group
What is BCP? When does it used?

BulkCopy is a tool used to copy huge amount of data from tables and views. BCP does not copy the structures same as source to destination. BULK INSERT command helps to import a data file into a database table or view in a user-specified format.
What are sp_configure commands and set commands?

Use sp_configure to display or change server-level settings. To change database-level settings, use ALTER DATABASE. To change settings that affect only the current user session, use the SET statement.
How to implement one-to-one, one-to-many and many-to-many relationships while designing tables?

One-to-One relationship can be implemented as a single table and rarely as two tables with primary and foreign key relationships. One-to-Many relationships are implemented by splitting the data into two tables with primary key and foreign key relationships.
Many-to-Many relationships are implemented using a junction table with the keys from both the tables forming the composite primary key of the junction table.
What is an execution plan? When would you use it? How would you view the execution plan?

An execution plan is basically a road map that graphically or textually shows the data retrieval methods chosen by the SQL Server query optimizer for a stored procedure or ad-hoc query and is a very useful tool for a developer to understand the performance characteristics of a query or stored procedure since the plan is the one that SQL Server will place in its cache and use to execute the stored procedure or query. From within Query Analyzer is an option called "Show Execution Plan" (located on the Query drop-down menu). If this option is turned on it will display query execution plan in separate window when query is ran again.
What is ACID ??

A transaction in SQL or in any DB must be ACID i.e.

atomicity, consistency, isolation, durability

Check on Google for details
How can u pick random records from SQL table ?

SELECT colName FROM tblSource
ORDER BY NEWID()
Efficiency comparison of EXISTS and IN

EXISTS is efficient as if any row returned, Search stops.
IN is looking for a specific match which takes longer.

However they may not always replace each other but wherever they can, above is their efficiency comparison !!
Can you compare two SQL fields with datatype "text" by using equal "=" operator

NOTE: This is objective type question, Please click question title for correct answer.
What are the three levels of data abstraction?

The are three levels of abstraction are as follows:

Physical level: The lowest level of abstraction describes how data are stored.

Logical level: The next higher level of abstraction, describes what data are stored in database and what relationship among those data.

View level: The highest level of abstraction describes only part of entire database.
What is the error in the following command? DROP TABLE &TABLE_NAME;

Variable names should start with an alphabet. Here the table name starts with an '&' symbol. So it will give a compilation error.
What is the use of DATEDIFF function in SQL?

It will extract the difference between two given dates as per the parameter passed.

datediff(parameter,date1,date2)
What is the use of DATEPART function in SQL?

datepart(parameter,date) will extract the date part according to the parameter passed. The parameters can be yy for year, mm for month or dd for date.
Which function is used to find the largest integer less than or equal to a specific value?

FLOOR

Floor is used to round a number down to the last whole number. Any number with even the highest decimal is rounded down.

Examples:
  SELECT FLOOR(-5.12); 

This will be round down to -6
  SELECT FLOOR(5.14); 

This will be round down to 5
What is the use of DESC in SQL?

DESC is used to describe a schema as well as to retrieve rows from table in descending order.

The query SELECT * FROM Student ORDER BY SNAME DESC will display the output sorted on SNAME in descending order.
Which option is used to drop constraints specified on the table?

DROP option in the ALTER TABLE command is used to drop constraints specified on the table.
MONTHS_BETWEEN date function is used for what purpose?

MONTHS_BETWEEN is used to find the difference between two dates.
Which command is used to create a table by copying the structure of another table?

CREATE TABLE .. AS SELECT command
Example:-
CREATE TABLE AS SELECT*FROM WHERE 1=2;

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