How to create Index in the table:-
Non Clustered Index:-
Suppose we have a table tbl_Student and the Sql script for creating this table is given below:-
(
[StudentId] [int] IDENTITY(1,1) NOT NULL,
[FirstName] [nvarchar](150) ,
[LastName] [nvarchar](150),
[Phone] [nvarchar](20),
[Email] [nvarchar](50),
[StudentAddress] [nvarchar](200),
[RegistrationDate] [datetime],
[Enddate] [datetime]
)
Suppose it contains the following data-
Now First we can check whether the table contains any index or not.For this we can use the following queries:
sp_helpindex tbl_student
select name from sysindexes where id=object_id(‘tbl_student’)
Now, since we don’t make any index on the table tbl_student yet, so when we run the sql statement “sp_helpindex tbl_student” , it will give us the following result:-
The object ‘tbl_student’ does not have any indexes, or you do not have permissions.
Now , we can make the index on this table by using the following Sql Statement:-
This sql statement will create a non clustered index “Index_Firstname” on the table tbl_student. We can also make a index on a combination of the columns of the table.This can be done by using the following Sql Statement:- Create Index (Index name) ON (Table name)(ColumnName1, ColumnName2)
For Example:-
Create Index Index_StudentName on tbl_student(FirstName, Lastname)
This Sql Statement will create a non clustered Index Index_studentname on the combination of the two columns FirstName and LastName.
Clustered Index:- We can also create a Clustered index by using the given Sql Statement:-
For Example,
The above Sql statement will create a Clustered index Index_Studentid on the table tbl_student. Now we can use the Sql Statements, which I described earlier to find out all the index made on the table tbl_student If we execute the statement “sp_helpindex tbl_student” , it will give us the following results:-
Droping an Index We can drop an Index by using the following Sql Statement:- Drop Index (Index Name) on (Table Name)
For Example,
The Above Sql Statement will delete the Index Index_Firstname on the table tbl_student. Now if we execute the statement “sp_helpindex tbl_student” , it will give us the following results:-
There are some difference between the Clustered Index and Non Clustered Index.You can read these difference in my article “Difference between Clustered Index and Non Clustered Index”.You can also click on the given url to read this article http://www.techmixing.com/2010/01/difference-between-clustered-and.html
Discover more from Technology with Vivek Johari
Subscribe to get the latest posts sent to your email.
… [Trackback]
[…] Find More here on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Info on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Information on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Info on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Here you can find 34277 additional Info on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Find More Information here on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Read More Information here on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Find More on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Read More to that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Info on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] There you can find 79276 additional Info on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] There you can find 46610 more Info on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Find More on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Here you will find 66965 additional Information to that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Information to that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] There you will find 6549 more Info to that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Here you can find 5654 more Information on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Find More Info here to that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Information on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Read More here to that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Find More on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Here you can find 68622 more Information to that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Read More Info here on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Info on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]
… [Trackback]
[…] Here you can find 32862 more Info on that Topic: techmixing.com/2010/01/indexes-in-sql-server.html […]