0% found this document useful (0 votes)
2 views

SQL_Server_Practical_Questions

Uploaded by

Vikash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

SQL_Server_Practical_Questions

Uploaded by

Vikash Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

SQL Server Practical Questions (Topic-Wise)

1. SQL Basics
1. Write a query to create a table with columns for ID, Name, and Salary.

2. Insert multiple rows of data into the created table.

3. Update the Salary of an employee based on their ID.

4. Delete an employee record where the Name is 'John'.

5. Fetch all records from the table.

6. Write a query to fetch only the Name and Salary of employees.

7. Retrieve employees whose Salary is greater than ₹50,000.

8. Fetch distinct departments from an employee table.

9. Sort employees by Name in descending order.

10. Count the total number of employees in the table.

2. Joins
1. Write a query to perform an INNER JOIN between two tables.

2. Fetch all records using a LEFT JOIN.

3. Retrieve unmatched records using a RIGHT JOIN.

4. Combine data from two tables using a FULL OUTER JOIN.

5. Write a query to perform a SELF JOIN to compare rows within the same table.

6. Find the employees and their department names using a join.

7. Retrieve employees who do not have a department assigned using a join.

8. Perform a join with more than two tables.

9. Write a query to use CROSS JOIN between two tables.

10. Fetch employees along with department details, handling nulls gracefully.

3. Stored Procedures
1. Create a stored procedure to retrieve employee details by Department.

2. Write a stored procedure to update an employee’s Salary by a given percentage.


3. Create a procedure to delete records older than a certain date.

4. Write a stored procedure to insert a new employee into the table.

5. Create a stored procedure to calculate the average Salary of employees in a department.

6. Develop a stored procedure to count employees by Department.

7. Write a procedure to fetch employees with a Salary greater than a given value.

8. Create a stored procedure with input and output parameters.

9. Write a procedure to log changes made to employee details into a log table.

10. Handle errors in a stored procedure using TRY...CATCH.

4. Functions
1. Create a scalar function to calculate the age of an employee based on their DateOfBirth.

2. Write a function to return the full name (FirstName + LastName) of an employee.

3. Develop a table-valued function to return employees in a given department.

4. Create a function to check if a Salary is within a specific range.

5. Write a function to calculate the factorial of a given number.

6. Build a function to return the department name given a DepartmentID.

7. Write a function to return the number of employees in a department.

8. Create a function to calculate the sum of salaries in a department.

9. Write a scalar function to return the initials of an employee’s name.

10. Build a function to validate email format for employees.

5. Indexes
1. Create a clustered index on the EmployeeID column.

2. Create a non-clustered index on the Name column.

3. Drop an index from the Salary column.

4. Write a query to check if an index is being used in a query plan.

5. Identify missing indexes using sys.dm_db_missing_index_details.

6. Optimize a query using a non-clustered index.

7. Create a composite index on Name and Department.


8. Rebuild an index to improve performance.

9. Write a query to check the fragmentation of an index.

10. Disable and then re-enable an index on a table.

You might also like