How To Create an Index on an Existing Table in MS SQL Server?
Submitted by: AdministratorIf 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
Submitted by: Administrator
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
Submitted by: Administrator
Read Online MS SQL Server Job Interview Questions And Answers
Top MS SQL Server Questions
☺ | How To Start SQL Server Browser Service? |
☺ | Does Index Slows Down INSERT Statements? |
☺ | What Is a Transact-SQL Statement Batch in MS SQL Server? |
☺ | How To Execute the Cursor Queries with "OPEN" Statements? |
☺ | What Happens If Strings Are Casted into Wrong Code Pages in MS SQL Server? |
Top Databases Programming Categories
☺ | RDBMS Interview Questions. |
☺ | SQL Interview Questions. |
☺ | SSRS Interview Questions. |
☺ | Database Administrator (DBA) Interview Questions. |
☺ | Sybase Interview Questions. |