SQL Server Interview Questions by topic
Basic SQL Server Interview Questions
What is the difference between Having and Where clause
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
Write a SQL Query to delete from a table that is involved in a SQL join
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?
Subscribe to:
Post Comments (Atom)
Can u please add more questions on SQL Server 2008? Thanks
ReplyDeleteSelect * from tblA, tblB
ReplyDeleteWhat is O/P.
Ans: Cross product.
It is a Cross Join.
two tables data will be displayed
Deletewhat is the order of execution of where having and groupby clause
ReplyDeleteThe order is first, WHERE gets executed, followed by GROUP BY and then Having clause.
DeleteWHERE - Filters the rows to be selected from the tables
GROUP BY - Groups the filtered rows
HAVING - Filters the Groups
ORDER BY - Finally sorts the groups
write a sql which will return nth(2nd highest salary) value from Employee table?
ReplyDeletehi
Deleteyou can find in 3 ways.
its very easy to find any number of salary using CTE(Common table expression)
second highest salary:
with result as(
select distinct salary,dense_rank() over (order by salary desc) as dens from tblempsal
)
select salary from result where dens=2
just change dens=3 then it will be third highest salary so on. so that u can find wt number salary u want to find ..
2.you can also find using < (lesser than symbol) or using NOT IN
select max(salary) from tblempsal where salary < (select max(salary) from tblempsal)
or
select max(salary) from tblempsal where salary not in (select max(salary) from tblempsal)
3. using top function
select top 1 salary from tblempsal where salary in (select top 2 salary from tblempsal order by salary desc) order by salary asc
Thank you
Sunil H A
HUNSUR
sunilgowda_91@yahoo.com
nth highest salary from Emp table
ReplyDeleteselect * from Emp E1 where (n-1) =
(select count(*) from Emp E2 where E1.salary <= E2.salary)
please make a different link for all question i added as anonymous.
Please correct my ans
elect salary from Employees1 where salary<(SELECT MIN(salary) salary FROM ( select top n salary from Employees1 order by salary desc) AS A)
DeleteAssume you have been asked to design the database structure for job site .what NORMALIZED table data model/table design would you recommended for storing the personal data of the candidate like name , address, and phone no. and their skill in multiple langauge so as to ensure that when a company searches based on a particular set of skill. the query is quick to return the result .
ReplyDeleteNote that each candidate would have multiple skills
Also write a query to retrive a list of all candidate along with their skill names
A friend of mine was asked a question in an interview. Here is the question. What is coalesce in SQL and when do you use this function?
ReplyDeleteCan u please explain what is ql tunning(database tunning)?
ReplyDeleteExcuse me, how to convert a type FLOAT to INT in SQL Server, but this field that was updated, should be insert into the table where comes. How do it?
ReplyDeleteFor example: I got a field into the table XYZ of FLOAT type. I need convert this field with all his data to INT, but this registers should appear in the table XYZ. When I use: "select * from XYZ" show or print the new field with the all datas updated.
show report header above the report parameters in report view using SSRS?
ReplyDeleteIs it possible ? pls suggest.
I have been asked a question, what are Concurrent Subqueries.
ReplyDelete
ReplyDeleteWhat is difference between Is Null,IsNull,= Null,Null ,' '(Empty Statement) & When it’s use ?
Find the second Max salary from max of salaries from a table having employee id and salary as columns
ReplyDeleteselect top 1 id,sal from
Delete(select top 2 id,sal from table_name order by sal) temp
order by sal desc
select top 1 sal from(select distinct top 2 sal from emp order by sal desc) a order by sal
DeleteHow to avoid deadlock
ReplyDeleteSir How to connect sql server database from C# programming form
ReplyDelete---How to avoid Divide by zero error ?
ReplyDeleteCreate table tblcompute
(
Numerator int not null,
Denominator int not null,
Result as (Numerator / Denominator)
)
Go
insert into tblcompute values (3,0)
when we issue a select querry
Select * from tblcompute
Msg 8134, Level 16, State 1, Line 1
Divide by zero error encountered.
even after adding new row also getting the same error
insert into tblcompute values (10,2)
Finally i comeup with these querys!
Select * from tblcompute where Result !=0
SELECT Numerator , Denominator, NULLif(Result, 0) as Results from tblcompute
SELECT Numerator , Denominator, NULLif(Result, null) as Results from tblcompute
Can you plz make a video session for clear explanation how it works & also i wanted to show the null value results as null
How to retrieve in between records from table without using where condition for eg in 100records would like to get 20-30 records only...is it possible???
ReplyDeleteya it is possible ..
Deletesolution:
select top 30.* from table order by NEWID()
Thank You
Sunil H A
Hunsur
sunilgowda_91@yahoo.com
Mouni, try group by with having. Where and having statement have different performance with queries. You might wanna check which is more effective
ReplyDeletesir join 2 tables employee and department and
ReplyDeletei want result insuch a way that
coloumns:deptname,maxsalar,employeename
Select DEPTNAME ,
DeleteNAME Employeename, SAL from
TBLEmp E
inner join TBLDEPT D
on E.DEPTID = D.DPTID
Where E.Sal in (Select max(sal) From TBLemp Group by DEPTID)
write a sql which will return nth(2nd highest salary) value from Employee table?
ReplyDeleteAnswer
select top 1 sal from(select distinct top 2 sal from emp order by sal desc) a order by sal
Thanks.
Sandeep nath
how to set identity column to random number generate.
ReplyDeletecan u please explain mirroring concepts?
ReplyDeleteHi Venkat,
ReplyDeleteWhen im trying to add new column in tblperson table its created with the null type.
But when im creating the same using not null its shows in error. (Error mention below)
Msg 4901, Level 16, State 1, Line 1
ALTER TABLE only allows columns to be added that can contain nulls, or have a DEFAULT definition specified, or the column being added is an identity or timestamp column, or alternatively if none of the previous conditions are satisfied the table must be empty to allow addition of this column. Column 'place' cannot be added to non-empty table 'tblperson' because it does not satisfy these conditions.
hello sir,
ReplyDeletehow can avoid errors during creating tables... how can i coded it..explain me sir
Hello Sir,
ReplyDeleteI have 2 tables T1(Id,Name) T2(Id,Name) I want to swap T1.Name to T2.Name and T2.Name to T1.Name Column values how to do it Please Answer me
Please define instances in SQL.
ReplyDeleteHello Sir,
ReplyDeleteRecently I attended a interview and I was asked, if a procedure is taking more time for executing what will you do and how will you do to reduce the execution time. Running each query is not an option because the procedure has more than 50 queries. Can you please tell me is there any tool or option in sql server which we can use for this.
Thanks in advance.
Database Engine tuning advisor tool will help you to reduce the execution time, It would suggest you indexing on columns which are part Where Clause in Select statement.
DeleteHi Venkat my Name Is Dattatreya , I have one doubt in View
ReplyDeletecan we delete table without deleting table related view