Solved

creating index tables sql server 2005

Posted on 2007-03-26
7
152 Views
Last Modified: 2010-03-19
how do you create index to your tables? for sql server 2005 server
0
Comment
Question by:gianitoo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18792807
in short, TSQL:
CREATE INDEX <indexname> ON <tablename> ( <column list>)

in the table design, or table menu context you find the manage indexes to do it using GUI.

note that for big tabes, creating the index can take some time ...
0
 
LVL 7

Expert Comment

by:Jonathan Kelly
ID: 18792815
you can use the client tools
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=C243A5AE-4BD1-4E3D-94B8-5A0F62BF7796

or you can use TSQL to alter your tables.

give more detail about your situation.
0
 
LVL 1

Author Comment

by:gianitoo
ID: 18792831
i just have a simple table.  want to make sure it is indexed so it can run faster when the table begins to grow.  it will be for a future survey and last time we had 500,000 hits and start running slower.

USE [JMI]
GO
/****** Object:  Table [dbo].[vote]    Script Date: 03/26/2007 10:05:06 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[vote](
      [ID] [int] IDENTITY(1,1) NOT NULL,
      [voteid] [int] NULL,
      [Email] [varchar](max) NULL,
 CONSTRAINT [PK_vote] PRIMARY KEY CLUSTERED
(
      [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO
SET ANSI_PADDING OFF
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 18792895
>want to make sure it is indexed so it can run faster
simply adding index(es) is not the good way to proceed.
you have to identify WHICH queries will run on the table, and by that means add indexes if needed.

note: the primary key field is indexed automatically!

now, looking at the table, I assume that you will search for voteid or by email, and you might want to have that index clustered instead of the primary key one...
0
 
LVL 1

Author Comment

by:gianitoo
ID: 18792931
on that table the query that will run will look for voteid.   how can i make it so it performs better?

what would you do?

for instance this is the query that i am concerned about.  when we had 500,000 votes then it created an issue.

      SELECT     TOP (6) COUNT(vote.voteid) AS ['Count Of Teams'], racerinfo.racername, CAST(COUNT(vote.voteid) AS real) /
                          (SELECT     CAST(COUNT(voteid) AS real) AS Expr1
                            FROM          vote) * 100 AS TotalPercentage
FROM         vote INNER JOIN
                      racerinfo ON vote.voteid = racerinfo.ID
GROUP BY racerinfo.racername, vote.voteid
ORDER BY ['Count Of Teams'] DESC
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 18793112
as I said, create a clustered index on the voteid field, and remove the clustered keyword from the table PRIMARY key.
0
 
LVL 1

Author Comment

by:gianitoo
ID: 18793175
thanks angel.  
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question