SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 9 of 31

Please read the Introductory Post before continue reading interview question and answers.

List of all the Interview Questions and Answers Series blogs

What is CHECK Constraint?

A CHECK constraint is used to limit the values that can be placed in a column. The check constraints are used to enforce domain integrity. (Read more here)

What is NOT NULL Constraint?

A NOT NULL constraint enforces that the column will not accept null values. The not null constraints are used to enforce domain integrity, as the check constraints.

(Read more here)

What is the difference between UNION and UNION ALL?

UNION
The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.

UNION ALL
The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.

The difference between UNION and UNION ALL is that UNION ALL will not eliminate duplicate rows, instead it just pulls all rows from all the tables fitting your query specifics and combines them into a table. (Read more here)

What is B-Tree?

The database server uses a B-tree structure to organize index information. B-Tree generally has following types of index pages or nodes:

  • Root node: A root node contains node pointers to only one branch node.
  • Branch nodes: A branch node contains pointers to leaf nodes or other branch nodes, which can be two or more.
  • Leaf nodes: A leaf node contains index items and horizontal pointers to other leaf nodes, which can be many.

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, include both in same statement and store them in a local variable. SELECT @RC = @@ROWCOUNT, @ER = @@ERROR

What is a Scheduled Job or What is a Scheduled Task?

Scheduled tasks let user automate processes that run on regular or predictable cycles. User can schedule administrative tasks, such as cube processing, to run during times of slow business activity. User can also determine the order in which tasks run by creating job steps within a SQL Server Agent job, e.g. back up database and update statistics of the tables. Job steps give user control over flow of execution. If one job fails, then the user can configure SQL Server Agent to continue to run the remaining tasks or to stop execution.

What are the Advantages of Using Stored Procedures?

  • Stored procedure can reduced network traffic and latency, boosting application performance.
  • Stored procedure execution plans can be reused; they staying cached in SQL Server’s memory, reducing server overhead.
  • Stored procedures help promote code reuse.
  • Stored procedures can encapsulate logic. You can change stored procedure code without affecting clients.
  • Stored procedures provide better security to your data.

What is a Table Called, if it has neither Cluster nor Non-cluster Index? What is it Used for?

Unindexed table or Heap. Microsoft Press Books and Book on Line (BOL) refers it as Heap. A heap is a table that does not have a clustered index and therefore, the pages are not linked by pointers. The IAM pages are the only structures that link the pages in a table together. Unindexed tables are good for fast storing of data. Many times, it is better to drop all the indexes from table and then do bulk of INSERTs and restore those indexes after that.

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 that Microsoft provides to add it as a linked server to the SQL Server group

What is BCP? When is it Used?

BCP or BulkCopy is a tool used to copy huge amounts of data from tables and views. BCP does not copy the complete structures from source to destination. BULK INSERT command helps to import a data file into a database table or view in a user-specified format.

List of all the Interview Questions and Answers Series blogs

Reference: Pinal Dave (https://blog.sqlauthority.com)

Previous Post
SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 8 of 31
Next Post
SQL SERVER – Interview Questions and Answers – Frequently Asked Questions – Day 10 of 31

Related Posts

No results found.

3 Comments. Leave new

  • I’d dispute the description of UNION as “much like the JOIN command”. It’s pretty much orthogonal to it. JOIN bring together columns from two tables into one row. UNION brings together rows from two tables (actually from two selects)

    Reply
  • Appreciate it Pinal, have been very useful for my interviews so far

    Reply
  • Vijaya Laxmi Kumbaji
    April 3, 2012 6:29 pm

    I learn from your blog / website all the time for interviews in .NET and SQL server. It is really very helpful.

    Thanks for the post.

    Reply

Leave a ReplyCancel reply

Exit mobile version