Answer: Creating an Index
Find a detailed explanation of creating an index in SQL.
We'll cover the following...
Solution
The solution is given below:
-- Query to create an index on employee namesCREATE INDEX idx_employee_names ON Employees (EName);-- Code to see the performance of the querySET PROFILING = 1;SELECT * FROM Employees WHERE EName = 'John';SHOW PROFILES;
Code explanation
The explanation of the solution code is given below:
Line 2: The
CREATE INDEXstatement creates an index namedidx_employee_nameson theENamecolumn in theEmployeestable.Line 5: The statement
SET PROFILING = 1;is used to enable profiling.Line 6: The
SELECTquery retrieves all columns from theEmployeestable and theWHEREclause specifies the condition on which we want to retrieve the data from the table.Line 7: The
SHOW PROFILEScommand displays a list of all queries executed in the current session, along with theirQuery_ID,Duration(execution time), and the query itself. This helps in monitoring the performance of queries.
The following code can be used to check ...