SQL_Server_Topics_Practical_Questions
SQL_Server_Topics_Practical_Questions
1. SQL Basics
1. Write a query to create a table with columns for ID, Name, and Salary.
2. Joins
1. Write a query to perform an INNER JOIN between two tables.
5. Write a query to perform a SELF JOIN to compare rows within the same table.
10. Fetch employees along with department details, handling nulls gracefully.
3. Stored Procedures
1. Create a stored procedure to retrieve employee details by Department.
7. Write a procedure to fetch employees with a Salary greater than a given value.
9. Write a procedure to log changes made to employee details into a log table.
4. Functions
1. Create a scalar function to calculate the age of an employee based on their DateOfBirth.
5. Indexes
1. Create a clustered index on the EmployeeID column.
6. Views
1. Create a view to show only Name and Salary from the Employees table.
7. Create a view to display employee details, excluding employees in the 'HR' department.
7. Transactions
1. Write a transaction to update the Salary of multiple employees and commit it.
6. Begin a transaction to insert multiple rows and rollback if any insertion fails.
7. Combine a CTE with a join query to fetch department details for each employee.
7. Write a query to automate database backups using a SQL Server Agent job.
6. Analyze the query plan for a stored procedure and suggest optimizations.
7. Rewrite a CURSOR-based query to a set-based query for better performance.