Sibeesh Passion

Top Menu

  • Home
  • Search
  • About
  • Privacy Policy

Main Menu

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Home
  • Search
  • About
  • Privacy Policy

logo

Sibeesh Passion

  • Articles
    • Azure
    • .NET
    • IoT
    • JavaScript
    • Career Advice
    • Interview
    • Angular
    • Node JS
    • JQuery
    • Knockout JS
    • Jasmine Framework
    • SQL
    • MongoDB
    • MySQL
    • WordPress
  • Contributions
    • Medium
    • GitHub
    • Stack Overflow
    • Unsplash
    • ASP.NET Forum
    • C# Corner
    • Code Project
    • DZone
    • MSDN
  • Social Media
    • LinkedIn
    • Facebook
    • Instagram
    • Twitter
  • YouTube
    • Sibeesh Venu
    • Sibeesh Passion
  • Awards
  • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment

  • Build, Deploy, Configure CI &CD Your Static Website in 5 mins

  • Post Messages to Microsoft Teams Using Python

  • Get Azure Blob Storage Blob Metadata Using PowerShell

  • Deploy .net 6 App to Azure from Azure DevOps using Pipelines

DatabaseInterviewSQL
Home›Database›SQL Interview Questions And Answers

SQL Interview Questions And Answers

By SibeeshVenu
October 24, 2015
3698
12
Share:

In this article we will discuss about the most asked SQL interview questions and answers. If you need to know other interview questions and answers, I strongly recommend to follow this link: Interview Questions. Now in this post we are going to share the interview questions or the information which you must know as a programmer or a developer, especially if you are a Dot Net developer. We will explain few questions here, if you still need some additional information on SQL, you can read here: SQL . I hope you will like this article.

Background

I am a dot net developer. As a dot net developer, there are so many things that I must be aware of. I am sharing those in the form of articles, you can always read my other interview questions here in the below links.

  • Interview Questions For Experienced and Beginner .NET Professionals
  • Infosys Interview Questions For DotNet Professionals
  • So shall we now discuss about SQL interview questions?

    SQL Interview Questions

    What are the types of Joins in SQL? Explain?

  • INNER JOIN
  • Returns all rows when there is at least one match in BOTH tables

  • LEFT JOIN
  • Return all rows from the left table, and the matched rows from the right table

  • RIGHT JOIN
  • Return all rows from the right table, and the matched rows from the left table

  • FULL JOIN
  • Return all rows when there is a match in ONE of the tables

    What is the default join in SQL? Give an example query?

    The default join is INNER JOIN.

    Example:

    [sql]
    SELECT column_name(s)
    FROM table1
    INNER JOIN table2
    ON table1.column_name=table2.column_name;
    [/sql]

    Describe all the joins with examples in SQL?

    SQL LEFT JOIN

    The LEFT JOIN keyword returns all rows from the left table (table1), with the matching rows in the right table (table2). The result is NULL in the right side when there is no match.

    [sql]
    SQL LEFT JOIN Syntax
    SELECT column_name(s)
    FROM table1
    LEFT JOIN table2
    ON table1.column_name=table2.column_name;
    [/sql]

    SQL RIGHT JOIN

    The right join returns all the rows in the right table ie table 2 with the matching ones in the left table(table1).

    [sql]
    SELECT column_name(s)
    FROM table1
    RIGHT JOIN table2
    ON table1.column_name=table2.column_name;
    [/sql]

    SQL FULL OUTER

    The full join returns all rows from the left table (table1) and from the right table (table2)

    [sql]
    SELECT column_name(s)
    FROM table1
    FULL OUTER JOIN table2
    ON table1.column_name=table2.column_name;
    [/sql]

    What is Union And Union All ? Explain the differences?

    SQL UNION

    The UNION operator is used to combine the result-set of two or more SELECT statements.

    Notice that each SELECT statement within the UNION must have the same number of columns. The columns must also have similar data types. Also, the columns in each SELECT statement must be in the same order.

    Note: The UNION operator selects only distinct values by default.

    [sql]
    SELECT column_name(s) FROM table1
    UNION
    SELECT column_name(s) FROM table2;
    [/sql]

    SQL UNION ALL

    [sql]
    SQL UNION ALL Syntax
    SELECT column_name(s) FROM table1
    UNION ALL
    SELECT column_name(s) FROM table2;
    [/sql]

    Allows duplicate values.

    Differentiate Clustered and Non clustered Index in SQL?

    A clustered index is one in which the index’s order is arranged according to the physical order of rows in the table. Due to this reason there can only be one clustered index per table, usually this is the primary key.

    A non clustered index is one in which the order of index is not in accordance with the physical order of rows in the table.

    Create Index Syntax

    [sql]
    CREATE INDEX [ CLUSTERED | NONCLUSTERED ] PIndex ON Persons (LastName,FirstName)
    [/sql]

    Explain the difference between Stored Procedure and User Defined Function?

    Stored Procedure

    Stored procedures are reusable code in database which is compiled for first time and its execution plan saved. The compiled code is executed when everytime its called. You

    Function

    Function is a database object in SQL Server. Basically it is a set of SQL statements that accepts only input parameters, perform actions and return the result. Function can return only single value or a table. We can’t use function to Insert, Update, Delete records in the database table(s). It is compiled eveyrtime its invoked.

    Basic Difference

    Function must return a value but in Stored Procedure it is optional( Procedure can return zero or n values).
    Functions can have only input parameters for it whereas Procedures can have input/output parameters .
    Functions can be called from Procedure whereas Procedures cannot be called from Function

    Advanced Difference

    Procedure allows SELECT as well as DML(INSERT/UPDATE/DELETE) statement in it whereas Function allows only SELECT statement in it.
    Procedures cannot be utilized in a SELECT statement whereas Function can be embedded in a SELECT statement.
    Stored Procedures cannot be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section whereas Function can be.
    The most important feature of stored procedures over function is to retention and reuse the execution plan while in case of function it will be compiled every time.

    Functions that return tables can be treated as another rowset. This can be used in JOINs with other tables.
    Inline Function can be though of as views that take parameters and can be used in JOINs and other Rowset operations.
    Exception can be handled by try-catch block in a Procedure whereas try-catch block cannot be used in a Function.
    We can use transactions in stored procedure but not in functions.

    That’s all. Have a great day.

    Conclusion

    Did I miss anything that you may think which is needed? Could you find this post as useful? I hope you liked this article. Please share me your valuable suggestions and feedback.

    Your turn. What do you think?

    A blog isn’t a blog without comments, but do try to stay on topic. If you have a question unrelated to this post, you’re better off posting it on C# Corner, Code Project, Stack Overflow, Asp.Net Forum instead of commenting here. Tweet or email me a link to your question there and I’ll definitely try to help if I can.

    Kindest Regards
    Sibeesh Venu

    TagsCareer AdviceDatabaseInterviewSQLSQL Interview Questions And Answers
    Previous Article

    Custom Pager Using prev and next In ...

    Next Article

    Important ADO.NET Interview Questions

    0
    Shares
    • 0
    • +
    • 0
    • 0
    • 0

    SibeeshVenu

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer.

    Related articles More from author

    • Code SnippetsSQLSQL Server

      Find Which Are All Table has Set Identity

      May 31, 2015
      By SibeeshVenu
    • SQL

      Foolproof Tips for Reading and Shrinking Transaction logs in SQL Server

      June 7, 2018
      By Andrew Jackson
    • Stored Procedure With Common Table Expression Or CTE
      DatabaseSQL

      Stored Procedure With Common Table Expression Or CTE

      February 29, 2016
      By SibeeshVenu
    • How toSQL

      Understand the Internal Structure of SQL Database File

      March 23, 2017
      By Andrew Jackson
    • Career AdviceVideos

      Video: How to be a successful software engineer

      April 22, 2017
      By SibeeshVenu
    • .NETADO.NETInterview

      Important ADO.NET Interview Questions

      October 24, 2015
      By SibeeshVenu
    0

    My book

    Asp Net Core and Azure with Raspberry Pi Sibeesh Venu

    YouTube

    MICROSOFT MVP (2016-2022)

    profile for Sibeesh Venu - Microsoft MVP

    Recent Posts

    • Linux Azure Function Isolated Dot Net 9 YAML Template Deployment
    • Build, Deploy, Configure CI &CD Your Static Website in 5 mins
    • Easily move data from one COSMOS DB to another
    • .NET 8 New and Efficient Way to Check IP is in Given IP Range
    • Async Client IP safelist for Dot NET
    • Post Messages to Microsoft Teams Using Python
    • Get Azure Blob Storage Blob Metadata Using PowerShell
    • Deploy .net 6 App to Azure from Azure DevOps using Pipelines
    • Integrate Azure App Insights in 1 Minute to .Net6 Application
    • Azure DevOps Service Connection with Multiple Azure Resource Group

    Tags

    Achievements (35) Angular (14) Angular 5 (7) Angular JS (15) article (10) Article Of The Day (13) Asp.Net (14) Azure (65) Azure DevOps (10) Azure Function (10) Azure IoT (7) C# (17) c-sharp corner (13) Career Advice (11) chart (11) CSharp (7) CSS (7) CSS3 (6) HighChart (10) How To (9) HTML5 (10) HTML5 Chart (11) Interview (6) IoT (11) Javascript (10) JQuery (82) jquery functions (9) JQWidgets (15) JQX Grid (17) Json (7) Microsoft (8) MVC (20) MVP (9) MXChip (7) News (18) Office 365 (7) Products (10) SQL (20) SQL Server (15) Visual Studio (10) Visual Studio 2017 (7) VS2017 (7) Web API (12) Windows 10 (7) Wordpress (9)
    • .NET
    • Achievements
    • ADO.NET
    • Android
    • Angular
    • Arduino
    • Article Of The Day
    • ASP.NET
    • Asp.Net Core
    • Automobile
    • Awards
    • Azure
    • Azure CDN
    • azure devops
    • Blockchain
    • Blog
    • Browser
    • C-Sharp Corner
    • C#
    • Career Advice
    • Code Snippets
    • CodeProject
    • Cognitive Services
    • Cosmos DB
    • CSS
    • CSS3
    • Data Factory
    • Database
    • Docker
    • Drawings
    • Drill Down Chart
    • English
    • Excel Programming
    • Exporting
    • Facebook
    • Fun
    • Gadgets
    • GitHub
    • GoPro
    • High Map
    • HighChart
    • How to
    • HTML
    • HTML5
    • Ignite UI
    • IIS
    • Interview
    • IoT
    • JavaScript
    • JQuery
    • jQuery UI
    • JQWidgets
    • JQX Grid
    • Json
    • Knockout JS
    • Linux
    • Machine Learning
    • Malayalam
    • Malayalam Poems
    • MDX Query
    • Microsoft
    • Microsoft ADOMD
    • Microsoft MVP
    • Microsoft Office
    • Microsoft Technologies
    • Microsoft Windows
    • Microsoft Windows Server
    • Mobile
    • MongoDB
    • Monthly Winners
    • MVC
    • MVC Grid
    • MySQL
    • News
    • Node JS
    • npm
    • Number Conversions
    • October 2015
    • Office 365
    • Office Development
    • One Plus
    • Outlook
    • Page
    • PHP
    • Poems
    • PowerShell
    • Products
    • Q&A
    • Raspberry PI
    • React
    • SEO
    • SharePoint
    • Skype
    • Social Media
    • Software
    • Spire.Doc
    • Spire.PDF
    • Spire.XLS
    • SQL
    • SQL Server
    • SSAS
    • SSMS
    • Storage In HTML5
    • Stories
    • Third Party Software Apps
    • Tips
    • Tools
    • Translator Text
    • Uncategorized
    • Unit Testing
    • UWP
    • VB.Net
    • Videos
    • Virtual Machine
    • Visual Studio
    • Visual Studio 2017
    • Wamp Server
    • Web API
    • Web Platform Installer
    • Webinars
    • WebMatrix
    • Windows 10
    • Windows 7
    • Windows 8.1
    • Wordpress
    • Writing

    ABOUT ME

    I am Sibeesh Venu, an engineer by profession and writer by passion. Microsoft MVP, Author, Speaker, Content Creator, Youtuber, Programmer. If you would like to know more about me, you can read my story here.

    Contact Me

    • info@sibeeshpassion.com

    Pages

    • About
    • Search
    • Privacy Policy
    • About
    • Search
    • Privacy Policy
    © Copyright Sibeesh Passion 2014-2025. All Rights Reserved.
    Go to mobile version