Need Help with SQL Server (Indexes)

  Watch video Indexes In SQL Server 

1. Run the script file “Create database 1.sql”, this will create the database Index_Examples and two tables, dbo.raw_data, dbo.index_example. & it will insert 2000 rows of data into dbo.raw_data. Next run the script Script File for Index Assignment.sql”. It will insert 4,000,000 rows into the dbo.index_example table (id, first_name, last_name, birthday). If I created a database with more it will bog down your CPU. With 4 million rows, you will see the difference in time between a non-index query and an index query. You are looking for the SQL Server Execution Time.

2. Run the following queries separately and record the time it took to complete each (see attached document “Example of Solution of Index Assignment.pdf”). You will have to set up the query window to show statistics & time. Go to the pull down menu Query, click on Query Options, under Execution, Advance check the box SET STATISTICS TIME, click OK.

  

USE [Index_Examples]

GO

select count(*) from dbo.index_example where last_name =’Waters’;

Screen Shot Goes Here!

select count(*) from dbo.index_example where first_name =’Colman’;

Screen Shot Goes Here!

select count(*) from dbo.index_example where birthday =’2000-01-01′;

Screen Shot Goes Here!

select first_name, last_name, birthday from index_example where last_name =’Waters’ order by last_name, first_name, birthday;

Screen Shot Goes Here!

select first_name, last_name, birthday from index_example where first_name =’Colman’ order by last_name, first_name, birthday;

Screen Shot Goes Here!

select first_name, last_name, birthday from index_example where birthday = ‘2000-01-01’ order by last_name, first_name, birthday;

Screen Shot Goes Here!

select first_name, last_name, birthday from index_example where last_name = ‘Waters’ and birthday = ‘2000-01-01’ order by last_name, first_name, birthday;

Screen Shot Goes Here!

3. Create 3 indexes for this database, and record the time it took to create each.

a) Create an index for the Last_Name column

Index Goes Here!

Screen Shot Goes Here!

b) Create an index for the First_Name column

Index Goes Here!

Screen Shot Goes Here!

c) Create an index for the birthday column

Index Goes Here!

Screen Shot Goes Here!

d) Create an index for the Last_Name and birthday column

Index Goes Here!

Screen Shot Goes Here!

4. Run the seven queries from step 1, separately and record the time it took to complete each (see attached document “Example of Solution of Index Assignment.pdf”).

USE [Index_Examples]

GO

select count(*) from dbo.index_example where last_name =’Waters’;

Screen Shot Goes Here!

select count(*) from dbo.index_example where first_name =’Colman’;

Screen Shot Goes Here!

select count(*) from dbo.index_example where birthday =’2000-01-01′;

Screen Shot Goes Here!

select first_name, last_name, birthday from index_example where last_name =’Waters’ order by last_name, first_name, birthday;

Screen Shot Goes Here!

select first_name, last_name, birthday from index_example where first_name =’Colman’ order by last_name, first_name, birthday;

Screen Shot Goes Here!

select first_name, last_name, birthday from index_example where birthday = ‘2000-01-01’ order by last_name, first_name, birthday;

Screen Shot Goes Here!

select first_name, last_name, birthday from index_example where last_name = ‘Waters’ and birthday = ‘2000-01-01’ order by last_name, first_name, birthday;

Screen Shot Goes Here!

5. In DETAIL what conclusion did you come to about indexes?