Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 19th, 2005, 10:23 AM
Ben Ben is offline
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default Developing Queries On Existing DB

I've been asked to develop some queries on an existing database. The queries I've been asked to develop frequently reference a date column in their conditions however the date column isn't indexed. I would like to create an index on the date column to speed up my queries, but the database supports an existing application of which I have no sight of the code - Could my creating this extra index impact the existing app in any other way besides marginally slowing the updates/inserts.

Thanks in advance
Ben
 
Old January 19th, 2005, 12:25 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

creating an additional indexes may or may not impact one particular query but may impact others queries requesting data from that table.
once you created that index you should re-analyse the other queries using the indexes with that column and see if any of the other indexes are now redundant. Run the index tuning wizard check its recommendation. The index tuning wizard normally makes a good choice based on queries run against the table.

Also read the "Designing an Index" from Books Online

When Microsoft® SQL Server™ 2000 executes a query, the query optimizer evaluates the costs of the available methods for retrieving the data and uses the most efficient method. SQL Server can perform a table scan, or it can use an index if one exists. When performing a table scan, SQL Server starts at the beginning of the table, steps row-by-row through all the rows in the table, and extracts the rows that meet the criteria of the query. When SQL Server uses an index, it finds the storage location of the rows needed by the query and extracts only the needed rows.

When you are considering whether to create an index on a column, consider if and how an indexed column is to be used in queries. Indexes are useful when a query:



Jaime E. Maccou
 
Old January 19th, 2005, 12:39 PM
Ben Ben is offline
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for your input Jaime

The database supports a 3rd party application, I have a good understanding of the datacaptured, and I've taken a look over all the tables and have discovered the whole database hasn't been set up very well. Some PK/FK Relationships haven't been set up when they clearly should have been. Would I be getting into dangerous ground if I added these without seeing the applications code?
 
Old January 19th, 2005, 12:45 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

Before you make changes use profiler and create a trace file, then add your indexes, create another trace and compare the results. Creating the indexes is not going to break your application but can create locks if not constructed correctly.

Jaime E. Maccou
 
Old January 19th, 2005, 12:52 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 625
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to jemacc
Default

On another note. The application may be constructing the relationship code at the application level. This is why you should profile the app to find out what is doing and what tables its touching.

Jaime E. Maccou
 
Old January 20th, 2005, 06:34 AM
Ben Ben is offline
Authorized User
 
Join Date: Jun 2003
Posts: 75
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Again thanks for your input.

One other question regarding indexes:

If an index is built on 2 columns, when applying a condition to one of the columns do I have to reference other columns aswell to make use of the index (even though I only want to restrict the values based on the first column)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Connecting existing program to SQL Express DB jscammell VB Databases Basics 2 April 19th, 2007 02:03 PM
Combining Queries or results from 2 queries Ford SQL Server 2000 24 November 7th, 2005 08:54 PM
Adding existing and non-existing attributes spencer.clark XSLT 5 July 27th, 2005 04:02 PM
How to insert a column values in existing db (msac gilgalbiblewheel Classic ASP Databases 0 April 6th, 2005 06:53 PM
developing on a server blitzkriegbop General .NET 1 January 4th, 2005 04:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.