Create Unique Index In SQL Server 2008
Posted in SQL | Index February 08, 2020
This article describes how to create unique index in SQL Server.
Index in SQL is used to quickly access the data from table or view. Indexes are created on table or view. Database have large amount of data like thousands of tables and view. When we try to access this data it takes more time.
A UNIQUE index assures that a column value or a value of combination of more then one column can not appear more than once in a table.
IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[Student1Details]') AND type in (N'U'))
DROP TABLE [dbo].Student1Details
create table Student1Details(
[ID] int NOT NULL,
[Name] [varchar](50) NULL,
[Branch] [varchar](10) NULL,
[Location] [varchar](10) NULL
constraint [PK_Student1] primary key clustered
)) on [PRIMARY]
insert into Student1Details
select 1, 'Nitin', 'CS','IND' union all
select 2, 'Ravi', 'EI','ENG' union all
select 3, 'Tim', 'ME','US' union all
select 4, 'Rick', 'ME','IND' union all
select 5, 'Rakesh', 'CS','ABD' union all
select 6, 'Tarun', 'ME','IND' union all
select * from Student1Details
CREATE UNIQUE INDEX index_student_normal