Top 10 SQL Interview Questions: Part 1
Hello Friends,
I will be providing few Interview
questions every week so that easily to learn. If get any doubts comment and if
you have any questions please feel free to ask.
1. What are the different subsets of SQL?
- DDL (Data Definition Language)
– It allows you to perform
various operations on the database such as CREATE, ALTER and DELETE
objects.
For example create table,Alter Table or delete.
- DML ( Data Manipulation Language) – It allows you to access and manipulate data. It
helps you to insert, update, delete and retrieve data from the
database.
For example insert data into table and update
data or delete.
- DCL ( Data Control Language) – It allows you to control access to the
database. Example – Grant, Revoke access permissions.
2. What is the difference between UNION and UNION ALL?
The difference between UNION and UNION
ALL is that UNION will omit duplicate
records whereas UNION ALL will include duplicate records.
Union will be used to merge 2 table result with same structure.
For example need to get data of 2 tables
with same structure will use Union that
will merge both results and give it as
one.
3. What are joins in SQL?
A JOIN clause is used to combine rows
from two or more tables, based on a related column between
them. It is used to merge two tables or retrieve data from there. There are 4
joins in SQL namely:
4.Write a sql query to get department wise highest salary?
SELECT DEPID, MAX(SALARY) FROM EMPLOYEE GROUP BY DEPID
5. Write a sql query
to get employees greater than 10000?
SELECT * FROM EMPLOYEE WHERE SALARY>10000
6. How to create new
GUID in Sql server?
We have a datatype called UNIQUEIDENTIFIER
that accepts GUID. To generate a new
GUID
use following code.
SELECT NEWID() AS GUID
7. Difference between
Stored Procedure and a function?
The function must return a
value but in Stored Procedure it is optional. Even a procedure can return zero or n values. Functions can have only
input parameters for it whereas Procedures can have input or output parameters. Functions can be called
from Procedure whereas Procedures cannot be called from a Function
8. What is a
constraint and most used constraints in SQL?
SQL
constraints are used to specify rules for the data in a table
Constraints
can be column level or table level. Column level constraints apply to a column,
and table level constraints apply to
the whole table.
NOT NULL - Ensures
that a column cannot have a NULL value
UNIQUE - Ensures that
all values in a column are different
PRIMARY KEY -
A combination of a NOT NULL and UNIQUE. Uniquely identifies each row in a table
FOREIGN KEY -
Uniquely identifies a row/record in another table
CHECK - Ensures that
all values in a column satisfies a specific condition
DEFAULT - Sets a
default value for a column when no value is specified
INDEX -
Used to create and retrieve data from the database very quickly
9. Find the employee
records with Name “Amar” it can be upper case or lower case “AMAR”,”aMar”,”amar”
SELECT * from Employees WHERE UPPER(EmpName) like '%AMAR%';
10. Can a Table have 2
Primary Keys?
Code to create
composite key.
DROP TABLE #TEMP1
CREATE TABLE #TEMP1(
ID INT
,
DONE INT ,
PRIMARY KEY (ID, DONE)
)
Thanks for reading
friends. If any questions on above, feel free to comment.
We are here to learn
and grow. Follow for more updates.
Post a Comment
0 Comments