1). Remove Duplicate Records from a table?
Answer:
Select distinct * into #tmpEmp From Emp
Delete from Emp
Insert into Emp
Select * from #tmpEmp
Drop table #tmpEmp
Select * from Emp
2). What is the difference between "Stored Procedure" and "Function"?
Answer:
1. A stored procedure can have both input and output parameters, but a function can only have input parameters.
2. We can use DML (INSERT/UPDATE/DELETE) statements inside a stored procedure. But we can't use DML statements inside a function.
3. We can't utilize a stored procedure in a Select statement. But we can use a function in a Select statement.
4. We can use a Try-Catch Block in a stored procedure but inside a function we can't use a Try-Catch block.
5. Stored Procedures cannot be used in the SQL statements anywhere in the where/having/select section. But we can use a function anywhere.
6. A stored procedure can't be called from a function but we can call a function from a stored procedure.
7. We can use transaction management in a procedure but we can't in a function.
8. We can't join a stored procedure but we can join functions.