Hello All, We are going to start new batch from next week. message/call or mail us for more details.

15 November 2016

Top 50 SQL Server Interview Questions & Answers

1. What are the two authentication modes in SQL Server?
There are two authentication modes –
  • Windows Mode
  • Mixed Mode
Modes can be changed by selecting the tools menu of SQL Server configuration properties and choose security page.
2.  What Is SQL Profiler?
SQL Profiler is a tool which allows system administrator to monitor events in the SQL server.  This is mainly used to capture and save data about each event of a file or a table for analysis.
3. What is recursive stored procedure?
SQL Server supports recursive stored procedure which calls by itself. Recursive stored procedure can be defined as a method of problem solving wherein the solution is arrived repetitively. It can nest up to 32 levels.
CREATE PROCEDURE [dbo].[Fact]
(
@Number Integer,
@RetVal Integer OUTPUT
)
AS
DECLARE @In Integer
DECLARE @Out Integer
IF @Number != 1
BEGIN
SELECT @In = @Number – 1
EXEC Fact @In, @Out OUTPUT - Same stored procedure has been called again(Recursively)
SELECT @RetVal = @Number * @Out
END
ELSE
BEGIN
SELECT @RetVal = 1
END
RETURN
GO

4. What are the differences between local and global temporary tables?
  • Local temporary tables  are visible when there is a connection, and are deleted when the connection is closed.
  • Global temporary tables  are visible to all users, and are deleted when the connection that created it is closed.

5. What is CHECK constraint?
A CHECK constraint can be applied to a column in a table to limit the values that can be placed in a column. Check constraint is to enforce integrity.
6. Can SQL servers linked to other servers?
SQL server can be connected to any database which has OLE-DB provider to give a link. Example: Oracle has OLE-DB provider which has link to connect with the SQL server group.
7.  What is sub query and its properties?
A sub-query is a query which can be nested inside a main query like Select, Update, Insert or Delete statements. This can be used when expression is allowed. Properties of sub query can be defined as
  • A sub query should not have order by clause
  • A sub query should be placed in the right hand side of the comparison operator of the main query
  • A sub query should be enclosed in parenthesis because it needs to be executed first before the main query
  • More than one sub query can be included
8. What are the types of sub query?
There are three types of sub query –
  • Single row sub query which returns only one row
  • Multiple row sub query which returns multiple rows
  • Multiple column sub query which returns multiple columns to the main query. With that sub query result, Main query will be executed.
9. What is SQL server agent?
The SQL Server agent plays  a vital role in day to day tasks of SQL server administrator(DBA). Server agent’s purpose is to implement the tasks easily with the scheduler engine which allows our jobs to run at scheduled date and time.
10. What are scheduled tasks in SQL Server?
Scheduled tasks or jobs are used to automate processes that can be run on a scheduled time at a regular interval. This scheduling of tasks helps to reduce human intervention during night time and feed can be done at a particular time. User can also order the tasks in which it has to be generated.
11. What is COALESCE in SQL Server?
COALESCE is used to return first non-null expression within the arguments. This function is used to return a non-null from more than one column in the arguments.
Example –

12.   How exceptions can be handled in SQL Server Programming?
Exceptions are handled using TRY—-CATCH constructs and it is handles by writing scripts inside the TRY block and error handling in the CATCH block.
13.   What is the purpose of FLOOR function?
FLOOR function is used to round up a non-integer value to the previous least integer. Example is given
Returns 6.
14.   Can we check locks in database? If so, how can we do this lock check?
Yes, we can check locks in the database. It can be achieved by using in-built stored procedure called sp_lock.
15.   What is the use of SIGN function?
SIGN function is used to determine whether the number specified is Positive, Negative and Zero. This will return +1,-1 or 0.
Example –

16.   What is a Trigger?
Triggers are used to execute a batch of SQL code when insert or update or delete commands are executed against a table. Triggers are automatically triggered or executed when the data is modified. It can be executed automatically on insert, delete and update operations.
17.   What are the types of Triggers?
There are four types of triggers and they are:
  • Insert
  • Delete
  • Update
  • Instead of
18.   What is an IDENTITY column in insert statements?
IDENTITY column is used in table columns to make that column as Auto incremental number or a surrogate key.
19.   What is Bulkcopy in SQL?
Bulkcopy is a tool used to copy large amount of data from Tables. This tool is used to load large amount of data in SQL Server.
20.   What will be query used to get the list of triggers in a database?
Query to get the list of triggers in database-

21.   What is the difference between UNION and UNION ALL?
• UNION: To select related information from two tables UNION command is used. It is similar to JOIN command.
• UNION All: The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values. It will not remove duplicate rows, instead it will retrieve all rows from all tables.
22.   How Global temporary tables are represented and its scope?
Global temporary tables are represented with ## before the table name. Scope will be the outside the session whereas local temporary tables are inside the session. Session ID can be found using @@SPID.
23.  What are the differences between Stored Procedure and the dynamic SQL?
Stored Procedure is a set of statements which is stored in a compiled form. Dynamic SQL is a set of statements that dynamically constructed at runtime and it will not be stored in a Database and it simply execute during run time.
24. What is Collation?
Collation is defined to specify the sort order in a table. There are three types of sort order –
  1. Case sensitive
  2. Case Insensitive
  3. Binary
25.  How can we get count of the number of records in a table?
Following are the queries can be used to get the count of records in a table –
26. What is the command used to get the version of SQL Server?

is used to get the version of SQL Server.
27.   What is UPDATE_STATISTICS command?
UPDATE_STATISTICS command is used to update the indexes on the tables when there is a large amount of deletions or modifications or bulk copy occurred in indexes.
28.   What is the use of SET NOCOUNT ON/OFF statement?
By default, NOCOUNT is set to OFF and it returns number of records got affected whenever the command is getting executed. If the user doesn’t want to display the number of records affected, it can be explicitly set to ON- (SET NOCOUNT ON).
29.   Which SQL server table is used to hold the stored procedure scripts?
Sys.SQL_Modules is a SQL Server table used to store the script of stored procedure. Name of the stored procedure is saved in the table called Sys.Procedure.
30.   What are Magic Tables in SQL Server?
Insert and Delete tables are created when the trigger is fired for any DML command. Those tables are called Magic Tables in SQL Server. These magic tables are used inside the triggers for data transaction.
31.   What is the difference between SUBSTR and INSTR in the SQL Server?
The SUBSTR function is used to return specific portion of string in a given string. But, INSTR function gives character position in a given specified string.

Gives result as Smi

Gives 3 as result as I appears in 3rd position of the string
32.   What is the use of =,==,=== operators?
= is used to assign one value or variable to another variable. == is used for comparing two strings or numbers. === is used to compare only string with the string and number with numbers.
33.   What is ISNULL() operator?
ISNULL function is used to check whether value given is NULL or not NULL in sql server. This function also provides to replace a value with the NULL.
34.   What is the use of FOR Clause?
FOR clause is mainly used for XML and browser options. This clause is mainly used to display the query results in XML format or in browser.
35.   What will be the maximum number of index per table?
For SQL Server 2008 100 Index can be used as maximum number per table. 1 Clustered Index and 999 Non-clustered indexes per table can be used in SQL Server.
1000 Index can be used as maximum number per table. 1 Clustered Index and 999 Non-clustered indexes per table can be used in SQL Server.
1 Clustered Index and 999 Non-clustered indexes per table can be used in SQL Server.
36.   What is the difference between COMMIT and ROLLBACK?
Every statement between BEGIN and COMMIT becomes persistent to database when the COMMIT is executed. Every statement between BEGIN and ROOLBACK are reverted to the state when the ROLLBACK was executed.
37.   What is the difference between varchar and nvarchar types?
Varchar and nvarchar are same but the only difference is that nvarhcar can be used to store Unicode characters for multiple languages and it also takes more space when compared with varchar.
38.   What is the use of @@SPID?
A @@SPID returns the session ID of the current user process.
39.   What is the command used to Recompile the stored procedure at run time?
Stored Procedure can be executed with the help of keyword called RECOMPILE.
Example

Or we can include WITHRECOMPILE in the stored procedure itself.
40.   How to delete duplicate rows in SQL Server?
Duplicate rows can be deleted using CTE and ROW NUMER feature of SQL Server.
41.   Where are SQL Server user names and passwords stored in SQL Server?
User Names and Passwords are stored in sys.server_principals and sys.sql_logins. But passwords are not stored in normal text.
42.   What is the difference between GETDATE and SYSDATETIME?
Both are same but GETDATE can give time till milliseconds and SYSDATETIME can give precision till nanoseconds. SYSDATE TIME is more accurate than GETDATE.
43.   How data can be copied from one table to another table?
INSERT INTO SELECT
This command is used to insert data into a table which is already created.
SELECT INTO
This command is used to create a new table and its structure and data can be copied from existing table.
44.   What is TABLESAMPLE?
TABLESAMPLE is used to extract sample of rows randomly that are all necessary for the application. The sample rows taken are based on the percentage of rows.
45.   Which command is used for user defined error messages?
RAISEERROR is the command used to generate and initiates error processing for a given session. Those user defined messages are stored in sys.messages table.
46.   What do mean by XML Datatype?
XML data type is used to store XML documents in the SQL Server database. Columns and variables are created and store XML instances in the database.
47.   What is CDC?
CDC is abbreviated as Change Data Capture which is used to capture the data that has been changed recently. This feature is present in SQL Server 2008.
48.   What is SQL injection?
SQL injection is an attack by malicious users in which malicious code can be inserted into strings that can be passed to an instance of SQL server for parsing and execution. All statements have to checked for vulnerabilities as it executes all syntactically valid queries that it receives.
Even parameters can be manipulated by the skilled and experienced attackers.
49.   What are the methods used to protect against SQL injection attack?
Following are the methods used to protect against SQL injection attack:
  • Use Parameters for Stored Procedures
  • Filtering input parameters
  • Use Parameter collection with Dynamic SQL
  • In like clause, user escape characters
50.   What is Filtered Index?               
Filtered Index is used to filter some portion of rows in a table to improve query performance, index maintenance and reduces index storage costs. When the index is created with WHERE clause, then it is called Filtered Index

70 comments:

  1. Enroll for Java Training in Bangalore with DataBytes; best Java Coaching Institutes in Bangalore.

    ReplyDelete
  2. hi welcome to this blog. really you have post an informative blog. it will be really helpful to many peoples. thank you for sharing this blog.
    dotnet training in chennai

    ReplyDelete
  3. Hello Pankaj,
    I like to thank you for providing these top 50 interview questions, as a beginner this helps me to learn many things in the subject and also during interview times. Check this page for dot net training and placement in chennai

    ReplyDelete
  4. Great information we can have more info in AWS

    ReplyDelete
  5. wow really nice. It will be helpful for the people those who are ready to crack the interview and please also for remind what they have learned throughout concept.

    Back to Original Services Private Limited

    ReplyDelete
  6. Your thinking toward the respective issue is awesome also the idea behind the blog is very interesting which would bring a new evolution in respective field. Thanks for sharing.

    Digital Marketing Company in Chennai

    ReplyDelete
  7. Great site for these post and i am seeing the most of contents have useful for my Carrier.Thanks to such a useful information.Any information are commands like to share him.

    Digital Marketing Course in Chennai

    ReplyDelete
  8. Marvellous post....very beneficial for all newcomers
    thanks for providing such an amazing blog.
    you can visit here too
    Best C C++ training institute in Delhi

    ReplyDelete
  9. A very nice guide. I will definitely follow these tips. Thank you for sharing such detailed article. I am learning a lot from you.

    Painless Dental Treatment In Chennai

    ReplyDelete
  10. I just see the post i am so happy to the communication science post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be replay for your great thinks and I hope you post again soon...
    Isoft Innovations Facebook
    Isoft Innovations Reviews

    ReplyDelete
  11. Webtrackker technology is the best IT training institute in NCR. Webtrackker provide training on all latest technology such as dot net training. Webtrackker is not only training institute but also it also provide best IT solution to his client. Webtrackker provide training by experienced and working in the industry on same technology.Webtrackker Technology C-67 Sector-63 Noida 8802820025

    dot net training institute in indirapuram


    dot net Training institute in Noida


    Dot net Training institute in Ghaziabad


    dot net training institute in Vaishali


    dot net Training institute in Vasundhara


    dot net Training institute in Delhi South Ex

    ReplyDelete
  12. A nice article here with some useful tips for those who are not used-to comment that frequently. Thanks for this helpful information I agree with all points you have given to us. I will follow all of them.


    Invisalign Treatment In Chennai

    Best Dental Clinic In Annanagar

    ReplyDelete
  13. Learn Dot Net Training in Chennai at Credo Systemz. Training offered by MNC Experts. Rated as Best .Net Training Institute in Chennai. Learn C# & ASP.Net Course with 100% Placement.

    Dot Net Training in Chennai
    Microsoft Dot Net Training in Chennai

    ReplyDelete
  14. .NET(.NET Framework) a perfect programming language which was developed by Microsoft Corporation by February 2002. .NET framework has various set of libraries. These libraries will support various languages such as VB.NET, C#.NET, ASP.NET etc.

    Best Dot Net Training Institute in Chennai
    Microsoft Dot Net Training in Chennai

    ReplyDelete
  15. I may be crazy but, the idea has been nagging me for some time that perhaps the biggest favor we could do for the African poor would be to kill off all that dangerous wild life.
    Best ASP.NET Training in Gurgaon

    ReplyDelete
  16. niceinformation you are posted. great article. thanks for sharng dotnet faqs
    Keep sharing................
    Thank you

    ReplyDelete
  17. This comment has been removed by the author.

    ReplyDelete
  18. I just see the post i am so happy the post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be subscribing to your feed and I hope you post again soon.
    Manpower Services in Chennai

    ReplyDelete
  19. I am not sure the place you are getting your information, however good topic.I needs to spend some time studying more or understanding more.Thank you for wonderful information I was in search of this info for my mission.

    Manpower Consultancy in Bangalore
    HR Consultancy in Bangalore
    Recruitment Consultancy in Bangalore
    HR Franchise in Bangalore

    ReplyDelete
  20. Maney people search for Sql server interview questions and answers. Thank you pankaj for this post. I am sharing mvc interview questions and .net training in Noida link

    ReplyDelete
  21. It's interesting that many of the bloggers to helped clarify a few things for me as well as giving.Most of ideas can be nice content.The people to give them a good shake to get your point and across the command.

    Digital Marketing Company in Chennai

    ReplyDelete
  22. This comment has been removed by the author.

    ReplyDelete

  23. Nice Sharing..! I have been following you for a couple of months now but this is my first time commenting on a blog post. Thank you for sharing your knowledge and experience with us. Keep up the good work. Already bookmarked for future reference.

    Installment loans in Mississippi
    Payday loans in Mississippi
    Title loans in Mississippi

    ReplyDelete
  24. This comment has been removed by the author.

    ReplyDelete
  25. I’m sincerely suggesting your blog to all my friends… I’ve changed myself in many thing after reading your blog… Thanks and keep going.
    Best Interior Designers in Chennai
    Interior Designers in Chennai

    ReplyDelete
  26. Really a good technical site,keep on writing good stuffs
    dot net training in chennai

    ReplyDelete
  27. If you looking for .net training institute in noida then join us, we provide best learning environment for more detail click on dot net training in noida

    ReplyDelete

  28. very useful info, and please keep updating........

    ReplyDelete

  29. Very Useful information that i have found. don't stop sharing and Please keep updating us..... Thanks

    ReplyDelete
  30. Pretty section of content. I simply stumbled upon your site and in accession capital to say that I get actually loved to account your blog posts.
    SQL Server Training in Chennai

    ReplyDelete
  31. This comment has been removed by the author.

    ReplyDelete
  32. I really appreciate your Post. the post has excellent tips which are useful. this post is good in regards of both knowledge as well as information Jobs in ASP.Net

    ReplyDelete
  33. Thanks for sharing information about .NET Training, I read your entire post and realize that your post is really informative. Such type of post is really helpful for those people who want to learn .NET. Apart from this I read another informative post for same kind of information. For your further information I am sharing that informative post about .NET Training.

    ReplyDelete

  34. Its very useful to me. Wonderful blog.. Thanks for sharing informative Post.

    Installment loans
    Payday loans
    Title loans

    ReplyDelete
  35. Excellent Blog very imperative good content, this article is useful to beginners and real time employees.Thank u for sharing...
    prince2 foundation Training

    ReplyDelete
  36. Very Nice blog. Really helpful information about ASP …. Please keep update some more…………

    ReplyDelete
  37. you are posting a good information for people and keep maintain and give more update too.
    seo company in india

    ReplyDelete
  38. Nice post! I thank you for sharing this nice blog with us. Likewise, I would like to say something that Happy Heap Marketing is also one of the Jobs in Asp.net

    ReplyDelete
  39. Valuable for information if there is any other regarding this kindly revert me back on this C++ Jobs

    ReplyDelete
  40. I just see the post i am so happy to the communication science post of information's.So I have really enjoyed and reading your blogs for these posts.Any way I’ll be replay for your great thinks and I hope you post again soon.
    .Net Development Services
    Hire .Net Developers India

    ReplyDelete
  41. Thanks for posting, you are sharing lot of information with us. Nice blog keep sharing


    Biztalk Online Training Hyderabad

    ReplyDelete
  42. Your blog is very much informative, people should surely read this. I will definitely share this within my circle, so that maximum number can read this. Like you, we IWT Digital Marketing Training Institute want to help maximum number of students in this field.
    digitalmarketingtraininginstituteingurgaon

    ReplyDelete
  43. superb.....blog is much interesting which engaged me more.Spend a worthful time.keep updating more.
    SEO Company in India

    ReplyDelete
  44. Nice post . Thanks for the shearing valuable information. I really fiend this type blog. Special thanks to writer.
    Asp.net developers

    ReplyDelete
  45. You wrote an excellent article thank you for sharing

    Biztalk Online Training Hyderabad

    ReplyDelete

  46. This information is impressive; I am inspired with your post writing style & how continuously you describe this topic.


    Pawn Shop

    Pawn Loans

    Pawn Shops

    Pawn Loan

    Pawn Shop near me

    ReplyDelete
  47. Hai Author Good Information that i found here,do not stop sharing and Please keep updating us..... Thanks.............hire dot net developer
    .net development services

    ReplyDelete
  48. Thanks for spending your valuable time in delivering the most valuable content here.I loved the way you write and suggest my friends too for getting aware of your blogs.
    Pawn Shops in Montgomery
    Pawn Shops in Birmingham
    Pawn Shops in Mobile

    ReplyDelete

  49. Its a wonderful post and very helpful, thanks for all this information. You are including better information regarding this topic in an effective way.Thank you so much

    Installment Loans Near Me
    Title loans Near Me
    Cash Advances Near Me

    ReplyDelete
  50. Dotnet is a technology in drift nowadays, .NET training programs for you,specially designed to make you job ready. I appreciate you spending some time and effort to put this information together on .net training in gurgaon as it will help cloud solution and the business need . it was still worthwhile!

    ReplyDelete
  51. Hi,
    Thanks for sharing the info about .NET Plz keep sharing on...
    Thank you...

    ReplyDelete
  52. This blog is about SQL server.These Question and Answers are useful for Interview Cracking purpose....
    Interior Designers in Chennai
    Interior Decorators in Chennai
    Interior Design in Chennai

    ReplyDelete
  53. Really it was an awesome article...very interesting to read..You have provided an nice article....Thanks for sharing..
    Android Training in Chennai
    Ios Training in Chennai

    ReplyDelete
  54. My partner and I stumbled over here different website and thought I might as well check things out. I like what I see so now I’m following you. Look forward to checking out your web page repeatedly.
    <a href="http://www.traininginmarathahalli.in/dot-net-training-in-bangalore/”> Dotnet Training in Marathahalli </a>|

    ReplyDelete
  55. Well Said, you have furnished the right information that will be useful to anyone at all time. Thanks for sharing your Ideas.
    selenium training in bangalore|
    selenium training in chennai|

    ReplyDelete
  56. Nice post. Thanks for sharing and providing information about your services.
    Industrial Training in Lucknow | Software Training in Lucknow

    ReplyDelete
  57. Hi pankaj

    Recently I got job as a dotnet developer, this post is very helpful for dotnet beginners to get a job....good work

    Thank you
    priya

    ReplyDelete
  58. The presentation was very clear and the examples were relevant.. well presented. The training instills confidence. Thank You Venkat
    gexton education

    ReplyDelete
  59. What a fantabulous post this has been. Never seen this kind of useful post. I am grateful to you and expect more number of posts like these. Thank you very much.

    ghayoor abbas official

    ReplyDelete
  60. Looking very interesting article with wonderful information
    Now I am able to learn ASP.NET on my own.
    Thank you for giving such a nice info
    plz do keep sharing on...

    ReplyDelete