SQL Server Interview Questions and Answers – Part 6

Interview Questions and Answers are now updated with the latest questions and answers. New Location:  SQL Server Interview Questions and Answers.

Click here to get free chapters (PDF) in the mailbox

Interview Questions and Answers

What are the properties of the Relational tables?
Relational tables have six properties:

  • Values are atomic.
  • Column values are of the same kind.
  • Each row is unique.
  • The sequence of columns is insignificant.
  • The sequence of rows is insignificant.
  • Each column must have a unique name.

What is De-normalization?
De-normalization is the process of attempting to optimize the performance of a database by adding redundant data. It is sometimes necessary because current DBMSs implement the relational model poorly. A true relational DBMS would allow for a fully normalized database at the logical level, while providing physical storage of data that is tuned for high performance. De-normalization is a technique to move from higher to lower normal forms of database modeling in order to speed up database access.

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

What is Identity?
Identity (or AutoNumber) is a column that automatically generates numeric values. A start and increment value can be set, but most DBA leave these at 1. A GUID column also generates numbers, the value of this cannot be controled. Identity/GUID columns do not need to be indexed.

What is a Scheduled Jobs or What is a Scheduled Tasks?
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, Update Stats of Tables. Job steps give user control over flow of execution.  If one job fails, user can configure SQL Server Agent to continue to run the remaining tasks or to stop execution.

What is a table called, if it does not have 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 indexes from table and than do bulk of inserts and to restore those indexes after that.

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.

How do you load large data to the SQL server database?
BulkCopy is a tool used to copy huge amount of data from tables. BULK INSERT command helps to Imports a data file into a database table or view in a user-specified format.

Can we rewrite subqueries into simple select statements or with joins?
Subqueries can often be re-written to use a standard outer join, resulting in faster performance. As we may know, an outer join uses the plus sign (+) operator to tell the database to return all non-matching rows with NULL values. Hence we combine the outer join with a NULL test in the WHERE clause to reproduce the result set without using a sub-query.

Can SQL Servers linked to other servers like Oracle?
SQL Server can be lined to any server provided it has OLE-DB provider from Microsoft to allow a link. E.g. Oracle has a OLE-DB provider for oracle that Microsoft provides to add it as linked server to SQL Server group.

How to know which index a table is using?
SELECT table_name,index_name FROM user_constraints

How to copy the tables, schema and views from one SQL server to another?
Microsoft SQL Server 2000 Data Transformation Services (DTS) is a set of graphical tools and programmable objects that lets user extract, transform, and consolidate data from disparate sources into single or multiple destinations.

What is Self Join?
This is a particular case when one table joins to itself, with one or two aliases to avoid confusion. A self join can be of any type, as long as the joined tables are the same. A self join is rather unique in that it involves a relationship with only one table. The common example is when company have a hierarchal reporting structure whereby one member of staff reports to another.

What is Cross Join?
A cross join that does not have a WHERE clause produces the Cartesian product of the tables involved in the join. The size of a Cartesian product result set is the number of rows in the first table multiplied by the number of rows in the second table. The common example is when company wants to combine each product with a pricing table to analyze each product at each price.

Which virtual table does a trigger use?
Inserted and Deleted.

List few advantages of Stored Procedure.

  • Stored procedure can reduced network traffic and latency, boosting application performance.
  • Stored procedure execution plans can be reused, 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 DataWarehousing?

  • Subject-oriented, meaning that the data in the database is organized so that all the data elements relating to the same real-world event or object are linked together;
  • Time-variant, meaning that the changes to the data in the database are tracked and recorded so that reports can be produced showing changes over time;
  • Non-volatile, meaning that data in the database is never over-written or deleted, once committed, the data is static, read-only, but retained for future reporting;
  • Integrated, meaning that the database contains data from most or all of an organization’s operational applications, and that this data is made consistent.

What is OLTP(OnLine Transaction Processing)?
In OLTP – online transaction processing systems relational database design use the discipline of data modeling and generally follow the Codd rules of data normalization in order to ensure absolute data integrity. Using these rules complex information is broken down into its most simple structures (a table) where all of the individual atomic level elements relate to each other and satisfy the normalization rules.

How do SQL server 2000 and XML linked? Can XML be used to access data?
FOR XML (ROW, AUTO, EXPLICIT)
You can execute SQL queries against existing relational databases to return results as XML rather than standard rowsets. These queries can be executed directly or from within stored procedures. To retrieve XML results, use the FOR XML clause of the SELECT statement and specify an XML mode of RAW, AUTO, or EXPLICIT.

OPENXML
OPENXML is a Transact-SQL keyword that provides a relational/rowset view over an in-memory XML document. OPENXML is a rowset provider similar to a table or a view. OPENXML provides a way to access XML data within the Transact-SQL context by transferring data from an XML document into the relational tables. Thus, OPENXML allows you to manage an XML document and its interaction with the relational environment.

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.

Complete Series of SQL Server Interview Questions and Answers
SQL Server Interview Questions and Answers – Introduction
SQL Server Interview Questions and Answers – Part 1
SQL Server Interview Questions and Answers – Part 2
SQL Server Interview Questions and Answers – Part 3
SQL Server Interview Questions and Answers – Part 4
SQL Server Interview Questions and Answers – Part 5
SQL Server Interview Questions and Answers – Part 6
SQL Server Interview Questions and Answers Complete List Download

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

Database, SQL Backup and Restore, SQL Constraint and Keys, SQL Cursor, SQL Download, SQL Function, SQL Joins, SQL Scripts, SQL Server, SQL Server Security, SQL Stored Procedure, SQL Trigger
Previous Post
SQL Server Interview Questions and Answers – Part 5
Next Post
SQL Server Interview Questions and Answers Complete List Download

Related Posts

81 Comments.

  • I was given task to tranform the crystal report to sql server report format. There i have one problem. In crystal report, you can use the formula running total to evalulate and display the sequential row number of each items in a group result and also sequential row number for sub group as well. But in sql server report, I try to use the formula row_number but it only can display the number line 1 (start of the report file) and number xx (where xx is the end of the line in my report file) but that is totally wrong for my report requirement. I need a way that could help me only count the row number start from the group items (in table) instead of first line of the report file. Please help.. i have try so many times but still can’t work.

  • I found these Questions and answers very useful. Thanks a lot…

  • As Per my opinion These Questions and answers are very helpful those who are in serious job Hunting.

    Many Many Thanks

  • This stuff is excellent …..thx a lot !!

  • Hi ,
    I m Rupesh….
    I am facing a problem…
    I have a view which is related to many functions and tables
    and view is having over 6 lacs records and now I want to copy all these records to a table….

    I have tried all the options such as import /export and insert command also but it is taking so much time……..

    plz help its very urgent…

    Thanx inn advance

  • hi,
    Is it possible to turn off headers in sql sever Agent.

  • Hi ,
    Just need a simple store procedure which deletes a record from 2 tables. The second delete is comparing file_name field. What is the correct syntax for the second delete statement. Any help will be much appreciated. Also is this possible?

    CREATE procedure up_test_delete(
    @test_id int
    )
    as
    delete from tests where test_id=@test_id
    delete from (another table) where file_name =’filename.aspx?test_id=’+@test_id

  • Thank you Pinal.

    Regards
    Abi

  • Hi Pinal ,
    Thank you for your help! I really appreciate for it. Indeed you are helping me for my carreer. I am sure that you will help me in the problems and doubts that i will have in my job as i said i am a new SQL Server DBA and i do not know much but i am trying hard to learn new stuff . I need the docs for query optomization, query execution plan and query tunining. If you have steps for these please let me know.

    Thank you in advance.
    Abi

  • hi!!!,
    this question answer is very good material for me and also it helps to anyone who want to get details info about sql server database.

  • HI PINAL,
    I AM AMAR.

    I’VE A QUERY I WANT CREATE INSERT TRIGGER IN A TABLE IN SQL2005. AND ANOTHER QUERY IS I’VE TO DISPLAY
    THE TOTAL AMOUNT OF ALL THE SALES ORDERS ROUNDED OFF TO A WHOLE NUMBER. IN ADDITION , I’VE TO DISPLAY THE SALES ORDER ID AND THE TYPE OF CREDIT CARD THROUGH WHICH THE PAMENT WAS MODE.

    I’VE TO DISPLAY THE TOTAL AMOUNT DUE OF ALL THE ORDERS IN THE FOLLOWING TABULAR FORMAT :-

    ORDER VALUE
    THE TOTAL AMOUNT DUE FOR THE SALES ORDER ID:43659 I S $27231.55
    THE TOTAL AMOUNT DUE FOR THE SALES ORDER ID:43650 I S $1716.18

    PLEASE, HELP ME.

  • Thanks Alot.

  • Hi Pinal,
    What a beautiful question and answer. I am a interviewer I have been asking lot of question from your list.
    any way this very useful to new software eng.

    Thanks for your article.

    Regards
    Mahesh

  • Ajinkya Suryvanshi
    June 12, 2007 4:34 am

    Hi Pinal,
    Great way to answering such a complex question.

    Thanks

  • Hi Pinal,

    Hope u r good…
    I have some doubts on sql server
    How many maxium number of rows we can store in one table
    what is the minimum space occupied by a stored procedure

    Its urgent!!

    Thanx in advance…..

    bye

    Rupesh

  • thank you very much

  • great work!!! It helped me a lot…

  • ajish babu j (m2)
    July 2, 2007 2:23 am

    Hi Pinal,thank u for ur work

  • Hi Pinal,

    post some questions regarding architecture …

    Thanks

  • Sonali kedar
    July 5, 2007 4:57 am

    I found these are Useful questions & answers

Comments are closed.