Monday, 5 November 2012

Indexes in sql server


INDEXES

select * from EmployeeDummy
--clustered index
create unique clustered index sample_cluster on Employeenotnull(ID desc)
create unique clustered index sample123_clust on dbo.EmployeeDummy(emp_no)
/*note:if a table has duplicate records then we can't create
 clustered index on that*/
--Nonclustered index
create index Noncluster on dbo.classificationdummy(classif_ID)
--can a table have both clusterd and nonclustered index?
--yes,but not on same columns
create unique clustered index sample123_clust on dbo.EmployeeDummy(emp_no)
create index Noncluster345 on dbo.EmployeeDummy(emp_fname)
create index Noncluster345 on dbo.EmployeeDummy(emp_no)
--indexed view
--first create view
select * from dbo.Empdummt
create view sampleindexview
WITH SCHEMABINDING
as
select EmpNo,EmpName,Salery from dbo.Empdummt
select * from sampleindexview
--indexed view
create unique clustered index indexviewsample on sampleindexview(EmpNo Desc)



No comments:

Post a Comment