[Updated:2018] Most Popular Sql interview question for freshers

In this tutorial I going to show you some tricky sql interview queries which is ask in fresher's interviews. These query are very simple and easy, I hope it will help you to crack the SQL Server Interview.


Sql interview question for freshers
Sql interview question for freshers



create database DBTest
use DBTest

--Check all information about any database
exec sp_helpdb @dbname='Test11718'

create table Employee
(
 EID int primary key identity(1,1),
 Name varchar(50),
 Age int,
 salary int
)
insert into Employee values('Amar',21,5000),('Carry',22,3000),('Deepak',28,2000),('Ram',21,1000),('XYZ',25,4000)

insert into Employee(Name,Age,Salary) values('Simant',25,500)

Rename a table

sp_rename 'Emp','Employee'

Rename column name

sp_rename 'Employee.salary','EmpSalary'

Add new column

alter table Employee add address varchar(20)

Change the DataType of column

alter table employee alter column address int

Note:

But there is one problem a datatype of column can not be changed when it will have data inside it.
It can be changed also when it will have data too but only in case of upcasting  ex:- int to varchar.

Drop the column

alter table Employee drop column address

--------------------Some Select Command ask in interview-------------------------


  

Get all record of table

select * from Employee

Find Maximum Salary

select MAX(EmpSalary) from Employee

Find Minimum Salary

select MIN(EmpSalary) from Employee

Find Avarage Salary
select AVG(EmpSalary) from Employee

How to find Avarage of string(Like name,address)

select AVG(Name) from Employee

No, you can't find the avarage of name because Operand data type varchar is invalid for avg operator.

Count the record of any column, count function naver count the null value

select count(Name) from Employee

Try MIN and MAX function on another place

select MIN(Name) from Employee
select MAX(Name) from Employee



READ MORE - KNOW MORE



EmoticonEmoticon