SQL Server Interview Questions



Basic SQL Server Interview Questions
SQL Server Interview Questions on Temporary Tables
SQL Server Interview Questions on Indexes - Part 1
SQL Server Interview Questions on Indexes - Part 2
What is the difference between a Temporary Table and a Table Variable
What is the use of COALESCE in SQL Server
SQL Server Interview Questions on triggers



Difference between User Defined Function and Stored Procedure
SQL Server Interview Questions on Views - Part 1
SQL Server Interview Questions on Views - Part 2
Basic SQL Server Interview Questions on Joins
Explain Inner Join with an example
Explain Left Outer Join with an example
Explain Right Outer Join with an example
Explain Full Outer Join with an example
Explain Self Join with an example
What is the difference between Index Scan and Index Seek
What are the advantages of using stored procedures?
What are the different ways to replace NULL values in SQL Server?
SQL Server interview questions on string manipulation functions
Write a Stored Procedure that takes column name as a parameter and returns the result sorted by the column that is passed
What is deferred name resolution in SQL Server?

21 comments:

  1. Dear Mr.Venkat,
    Thank u very much for such an organized collection. I cleared my interview after reading this blog for 2 times.

    - Anup

    ReplyDelete
  2. Really nice collection of SQL Questions. Thanks for the nice post.

    Priya Sharma
    Senior Software Engineer, Accenture

    ReplyDelete
  3. Hi there, awesome site. I thought the topics you posted on were very interesting. I tried to add your RSS to my feed reader and it a few. take a look at it, hopefully I can add you and follow.

    ReplyDelete
  4. Hi Venkat,

    This is awesome zone, where i clear my fundamental concept to remember easily and getting confident to clear interview.

    ReplyDelete
  5. Thank you for your wonderful work!!

    ReplyDelete
  6. Hi Mr Venkat,
    This is to thanks from bottom of heart for such a nice collection in one place , C#, ASP.NET, SQL SERVER tutorials and Interview questions all of them helping lot in my preparation . Keep doing hard wark . god bless you

    ReplyDelete
  7. Hi Mr Venkat
    thank you for your hard work second
    i would like to ask quatsion i have problem in part 27 in sql server i have this code


    DECLARE @DOB Datetime, @tempdate Datetime, @years int, @months int, @days int
    SET @DOB='10/08/1982'

    SELECT @tempdate = @DOB

    SELECT @years = DATEDIFF(YEAR, @tempdate, GETDATE()) -
    CASE
    WHEN (MONTH(@DOB) > MONTH(GETDATE()) OR
    (MONTH(@DOB) = MONTH(GETDATE()) AND DAY(@DOB) > DAY(GETDATE()))
    THEN 1 ELSE 0
    END
    SELECT @tempdate = DATEADD(YEAR, @Years, @tempdate)

    SELECT @months = DATEDIFF(MONTH, @tempdate, GETDATE())
    CASE
    WHEN DAY(@DOB) > DAY(GETDATE())
    THEN 1 ELSE 0
    END
    SELECT @tempdate = DATEADD(MONTH, @months, @tempdate)
    SELECT @days =DATEDIFF(day, @tempdate ,GETDATE())
    SELECT @Years as Years, @months as Months ,@days as [Days]

    Error messege is

    Msg 156, Level 15, State 1, Line 10
    Incorrect syntax near the keyword 'THEN'.
    Msg 156, Level 15, State 1, Line 15
    Incorrect syntax near the keyword 'CASE'.

    Then will not exept in OR and AND
    please teacher send me correct code in
    my email f.bilaal0007@gmail.com

    ReplyDelete
    Replies
    1. DECLARE @DOB Datetime, @tempdate Datetime, @years int, @months int, @days int
      SET @DOB='10/08/1982'

      SELECT @tempdate = @DOB

      SELECT @years = DATEDIFF(YEAR, @tempdate, GETDATE()) -
      CASE
      WHEN (MONTH(@DOB) > MONTH(GETDATE()) OR
      (MONTH(@DOB) = MONTH(GETDATE()) AND DAY(@DOB) > DAY(GETDATE())))
      THEN 1 ELSE 0
      END
      SELECT @tempdate = DATEADD(YEAR, @Years, @tempdate)

      SELECT @months = DATEDIFF(MONTH, @tempdate, GETDATE())-
      CASE
      WHEN DAY(@DOB) > DAY(GETDATE())
      THEN 1 ELSE 0
      END
      SELECT @tempdate = DATEADD(MONTH, @months, @tempdate)
      SELECT @days =DATEDIFF(day, @tempdate ,GETDATE())
      SELECT @Years as Years, @months as Months ,@days as [Days]

      Delete
  8. DECLARE @DOB Datetime, @tempdate Datetime, @years int, @months int, @days int
    SET @DOB='10/08/1982'

    SET @tempdate = @DOB

    Set @years = DATEDIFF(YEAR, @tempdate, GETDATE()) -
    CASE
    WHEN ((MONTH(@DOB) > MONTH(GETDATE()) OR
    (MONTH(@DOB) = MONTH(GETDATE())))

    AND (DAY(@DOB) > DAY(GETDATE())))
    THEN 1
    ELSE 0
    END



    SELECT @tempdate = DATEADD(YEAR, @Years, @tempdate)

    SELECT @months = DATEDIFF(MONTH, @tempdate, GETDATE()) -
    CASE
    WHEN (DAY(@DOB) > DAY(GETDATE()) )
    THEN 1
    ELSE 0
    END

    SELECT @tempdate = DATEADD(MONTH, @months, @tempdate)
    SELECT @days =DATEDIFF(day, @tempdate ,GETDATE())
    SELECT @Years as Years, @months as Months ,@days as [Days]

    ReplyDelete
  9. Hello Sir,
    Can i rename files place in folder through SQL query.
    If Yes Please just upload a code . I'll be thankful to you.
    The Problem is following..
    • There is a folder with 100s of pictures i.e. 834343.jpg, 843244.jpg etc
    • I need to update all files with the corresponding ID_NUMBER of the Personnel number attached to the photos (personnel number 834343).
    • The table aview_person has two distinct columns (extra_code_1 which holds the values of the personnel numbers (834343, 843244 and so on etc)… The table also has a column ID_Number (001.344324233232432,002.34453453453453) which is the reference ID number which is associated to the value in extra_code_1.
    • The pictures need to be updated with the ID_number and the extension. So the update once completed should look like this
    o Original picture (843423.jpg)
    o New Picture (001.334323432434234243.jpg)
    • I need the query to loop through all photos can change to the corresponding ID Number

    Query
    DECLARE @ID_NUMBER NVARCHAR(27)
    SELECT @ID_NUMBER = ID_NUMBER FROM aView_person WHERE EXTRA_CODE_1 ='photo name'

    ---PSEUDO---
    update
    'Photo name in File Path where photos are stored'
    set'photo name'= @ID_NUMBER +'.JPG'
    innerjoin aview_person per on'name of photo (without the .jpg extension)'= per.extra_code_1
    where per.extra_code_1 ='photo name'



    --Example--
    ---------Loop through all files in the folder until all files have been updated with the corresponding id_number'

    update'C:/Test/' ---photos location
    set'834567.jpg'='001.3434312759397368038'+'.jpg'
    innerjoin aview_person per on'834567'= per.extra_code_1
    where per.extra_code_1 ='834567'

    I Search for the solution my best, but can't find .
    Sir you are the only hope to help me. If it is possible then help me please.

    ReplyDelete
  10. This is one of the interview questions asked to me?
    How do you arrange data or what is procedure you apply to write code when a problem statement is given in 3 tier architecture?
    Ex : Whether you will add tables,data etc in Database or Add code in Presentation layer to display in front end or Create Business objects in Business layer or Data Access Objects in DAL.. Tell me the order you follow ?

    Kindly need an answer for this
    Pls Help

    ReplyDelete
  11. Can you please explain about CTE?

    ReplyDelete
  12. Hi,
    Can you explain types of locks in SQL?

    ReplyDelete
  13. Hi Sir,
    how do i grant privileges to specific user (based on role)

    ReplyDelete
  14. Hi venkat sir

    how can we store videos, audios and images in sql server 2008 and 2012

    ReplyDelete
  15. Hi Venkat Sir,
    I've got a query. I researched about this but didn't get a correct answer. following is the query.

    Can it be a good practice to join all tables in the same order on all queries if at all possible ? Are the tables with switched orders between queries the most common cause of a deadlock. For example, selecting from Client table inner join Order table in one query and Order table inner join Client table in another query - if they get executed at the same time, is there a deadlock potential ? What can be a standard rule for this ? Can joining all tables in the same alphabetical order on all queries help ?

    From : Sumit, sumitofficial7777@gmail.com

    ReplyDelete
  16. Hi Sir,
    what is #table and ##table, what is the difference between them and when we use it in real time.

    ReplyDelete
    Replies
    1. Both, #Table and ##Table are temporary tables. #Table is only accessible to that particular user whereas ##Table is accessible to anyone who has access to that Database.

      Delete
  17. i think we use it in query scripts we rarely use it and no need to save data that we want as a normal table.

    ReplyDelete
  18. HOW TO RECOVER DEADLOCK TRANSACTION ID PROCESS LOCK

    ReplyDelete
  19. Hello Guy, A very big regard to Mr.Vankat
    All the way from African precisely Nigeria, I copied your tutorial videos on Microsoft SQL from a friend of mine.
    It was a very good and excellent one.Your method of teaching is unique and classic. I pray that God will reward you and bless your family.

    ReplyDelete

If you are aware of any other sql server questions asked in an interview, please post them below. If you find anything missing or wrong, please feel free to correct by submitting the form below.

 
Disclaimer - Terms of use - Contact Us