Following are some of the important SQL Server Interview Questions and Answers
What is DBMS?
Database Management System or DBMS is an application for managing data stored in a database.It lets users work with the stored data and provides facilities to retrieve,insert,update and delete data in the database.
What is RDBMS?
RDMBS is a software system which is used to manage the database.In RDBMS data is stored using collection of tables.Tables consists of columns and rows.
What is Primary key?
Primary key is a group of columns in a table which uniquely identifies a row.Primary key values cannot be NULL.Two rows never have the same primary key value.A table can have only ONE primary key.his primary key can consist of single or multiple columns.
Primary key can be a single column or consist of multiple columns.A table can have only ONE primary key.We can create a table with a primary key as:
CREATE TABLE Employee( Name varchar(100), ID int, PRIMARY KEY (ID) );
What is Unique Key?
Unique Key is a group of fields in a table which identifies row.Difference between primary key and unique key is that unique key can have a null value.
What is Join?
Join is used fetch rows from multiple tables using a common column.Column defined in the first table acts as the primary key while the column defined in the other table acts the foreign key.
What is Inner join?
Inner join return rows when both the tables have matching column values.
What is Right Join?
Right join return common rows in the tables and all rows of Right hand side table in the join.
What is Left Join?
Left join return common rows in the tables and all rows of Left hand side table in the join.
What is Full Join?
Full join returns rows from both the tables.
What is a View?
A view is a virtual table as it doesn’t exist physically unlike actual tables.It can consist of data from multiple tables.
We can filter and sort data when returning the view data.
What is a Stored Procedure?
Stored Procedure is a collection precompiled T-SQL statements which are stored in the database and can be executed using the stored procedure name.Since they are stored in the SQL Server they reduce network load.Stored procedures also makes the application more secure since application don’t need to send the SQL to the SQL Server and can just execute the Stored Procedure.
What is a function in SQL Server?
Like a Stored Procedure ,function is also a group of T-SQL statements.But the difference is that functions can return a value while stored procedures can not return a value.There are two types of functions:
- UDF or User Defined Functions Custom functions created by developer
- Inbuilt Functions Provided by SQL Server
What is a Index?
Index helps in faster retrieval of data from the table.Index is like an index of a book.Like an index in a book Index is used to get to the actual row containing the data.This results in faster execution of query when selecting rows.
What is a Clustered Index?
Clustered Index physically rearranges the data in a table.This is the reason that a table can have only one Clustered Index.
What is a Non-Clustered Index?
NonClustered Index does not physically rearranges the data in a table.This is the reason that a table can have multiple NonClustered Indexes.
What is a Cursor?
A cursor is used to traverse the rows in a table.A cursor points to a single row at a time.So it used when we need to traverse all the rows in a table.
A query is request to the RDBMS to retrieve the matching rows for a table or group of tables.
What is SQL?
SQL stands for Structured Query Language.It is the language supported by all the RDBMS such as Oracle and SQL Server.
What is a Sub Query?
A subquery is a query within another query. The outer query is called as main query, and inner query is called subquery.