Solved

creating index tables sql server 2005

Posted on 2007-03-26
7
148 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
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Select - Help with CASE 4 42
issue installing SQL SERVER 2012 express on windows 7 9 40
T-SQL: Subtracting Amounts from "Among Rows" 3 43
TSQL - IF ELSE? 3 28
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

910 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

20 Experts available now in Live!

Get 1:1 Help Now