Answers

Question and Answer:

  Home  MS SQL Server

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

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

 146 views

More Questions for you: