MS SQL Server Concepts and Programming Question:
Download Questions PDF

How To Create an Index on an Existing Table in MS SQL Server?

Answer:

If you want to an index on an existing table, you can use the CREATE INDEX statement in a simple syntax:

CREATE INDEX index_name ON table_name (column_name)

The tutorial exercise below shows you how to add an index for the "in" column of the "ggl_links" table:

USE GlobalGuideLineDatabase;
GO

-- Drop the old table, if needed
DROP TABLE ggl_links;
GO

-- Create a fresh new table
CREATE TABLE ggl_links (
id INT NOT NULL,
url VARCHAR(80) NOT NULL,
notes VARCHAR(1024),
counts INT,
created DATETIME NOT NULL DEFAULT(getdate())
);
GO

-- Create an index for "id"
CREATE INDEX ggl_links_id ON ggl_links (id);
GO

-- Create an index for "url"
CREATE INDEX ggl_links_url ON ggl_links (url);
GO


Download MS SQL Server Interview Questions And Answers PDF

Previous QuestionNext Question
What Are Indexes in MS SQL Server?How To View Existing Indexes on an Given Table using SP_HELP?