Solved

creating index tables sql server 2005

Posted on 2007-03-26
7
146 Views
Last Modified: 2010-03-19
how do you create index to your tables? for sql server 2005 server
0
Comment
Question by:gianitoo
  • 3
  • 3
7 Comments
 
LVL 142

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 142

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 142

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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

707 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now