ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Software  >>  Databases  >>  SQL Server
 
 


 

 
 Oracle interview questions  Oracle Interview Questions
 SQL Server interview questions  SQL Server Interview Questions
 MS Access interview questions  MS Access Interview Questions
 MySQL interview questions  MySQL Interview Questions
 Postgre interview questions  Postgre Interview Questions
 Sybase interview questions  Sybase Interview Questions
 DB Architecture interview questions  DB Architecture Interview Questions
 DB Administration interview questions  DB Administration Interview Questions
 DB Development interview questions  DB Development Interview Questions
 SQL PLSQL interview questions  SQL PLSQL Interview Questions
 Databases AllOther interview questions  Databases AllOther Interview Questions
Question
Can we create clustered index on non primary key column
 Question Submitted By :: Dinesh Gupta
I also faced this Question!!     Rank Answer Posted By  
 
  Re: Can we create clustered index on non primary key column
Answer
# 1
no,we can't create clustered index on non primary key just 
because of the simple reason that in clstered 
index,physical sorting is done while in non primary key 
there might be hundreds of duplicate entries. so, if we 
create clusterd index on non primary key it will get 
confused and then error.
 
Is This Answer Correct ?    10 Yes 15 No
Gunjan Sapra
 
  Re: Can we create clustered index on non primary key column
Answer
# 2
no its not possible to place clustered index on non key 
column once the table contains any one key column, bcoz key 
column itself contains one clustered index based on that 
data sorted in ascending order.if u place one more 
clustered index how it is possible to arrange the data in 
soreted order.
 
Is This Answer Correct ?    6 Yes 9 No
Durgaprasad
 
 
 
  Re: Can we create clustered index on non primary key column
Answer
# 3
No, Because Constraints must have integrity. These are, 
Clustered and Non-Clustered. So, to use Primary key with 
any one Clustered or Non-Clustered index.

Example in SQL Server 2000:
Query :
-------
create table BookDetails
(
 Book_ID int identity(1,1) not null clustered,
 Book_Title varchar(20),
 Book_Type varchar(15),
 Book_Author varchar(25),
 Book_Edition float,
 Book_Publisher varchar(20),
 Book_Pub_Year datetime,
 Book_Price int
 )

Answer:
-------
Server: Msg 156, Level 15, State 1, Line 3
Incorrect syntax near the keyword 'clustered'.

Prevent this Error To use Clustered Primary Key:
------------------------------------------------
Query In SQL Server 2000:
-------------------------

create table BookDetails
(
 Book_ID int identity(1,1) not null primary key clustered,
 Book_Title varchar(20),
 Book_Type varchar(15),
 Book_Author varchar(25),
 Book_Edition float,
 Book_Publisher varchar(20),
 Book_Pub_Year datetime,
 Book_Price int
 )

Answer:
-------
The command(s) completed successfully.
 
Is This Answer Correct ?    2 Yes 9 No
Selvaraj.v
 
  Re: Can we create clustered index on non primary key column
Answer
# 4
we can creta clustered index on non primary column.
create table abc(eid int,ename varchar(50))
create clustered index abc_clustered on abc (eid)
 
Is This Answer Correct ?    17 Yes 1 No
Ashok
 
  Re: Can we create clustered index on non primary key column
Answer
# 5
YES, We can create a clustered index on a non-primary 
column. Check the folowing queries...

CREATE TABLE EMPLOYEES
(
empid int NOT NULL CONSTRAINT ix_pkEMPLOYEES PRIMARY KEY 
NONCLUSTERED
, name varchar(25) NOT NULL
, age tinyint NOT NULL
)

CREATE CLUSTERED INDEX ixcEMPLOYEES ON EMPLOYEES (name)
 
Is This Answer Correct ?    20 Yes 0 No
Pavan Kumar
 
  Re: Can we create clustered index on non primary key column
Answer
# 6
untill unless primary creating on the table we can create 
cl index on a table
 
Is This Answer Correct ?    1 Yes 5 No
Guest
 
  Re: Can we create clustered index on non primary key column
Answer
# 7
NO.If the table has the primary key column, then by default 
it will have a clustered index on that primary key 
cloumn.So if you want to create a clustered index on non 
primary key column then you have to create it before 
setting a column as the primary key column or u have to 
delete the clustered Primary key columns index to create a 
new one.but it is recommended to have a clustered index on 
primary key column.
 
Is This Answer Correct ?    7 Yes 1 No
Rima
 
  Re: Can we create clustered index on non primary key column
Answer
# 8
Yes, But on that table primary key should be created with 
non-clustered index and the columun u want to create a 
cluster index is should be unique
 
Is This Answer Correct ?    2 Yes 2 No
Laxman2610
 
  Re: Can we create clustered index on non primary key column
Answer
# 9
yes, we can create the cluster index on non prime attribute 
if it is unique & there is no prime attribute bcoz the 
cluster index should be once..
 
Is This Answer Correct ?    2 Yes 2 No
Grish Varshney
 
  Re: Can we create clustered index on non primary key column
Answer
# 10
We know sql server creates a clustered index by default 
when we create a primary key. If you create a PK first and 
then try to assign a candidate key a clustered index then 
it is not possible bcos sql server allows one clustered 
index per table.

But...

If you make a candidate key a clustered index and then 
define the primary key sql server doesnot create clustered 
index for the Primary Key column.

So the answer is yes...you can create a clustered index on 
non-pk column :D
 
Is This Answer Correct ?    4 Yes 1 No
Kaushik Ganguly
 
  Re: Can we create clustered index on non primary key column
Answer
# 11
Finally, i want to conclude by saying.

1. We can create Clustered Index on Non-Primary Key Columns
and this table should not contain any other column with
Primary Key.

2. It is recommended that we create Clustered Indexing on
Primary Key Columns
 
Is This Answer Correct ?    5 Yes 0 No
Surya Prakash
 
  Re: Can we create clustered index on non primary key column
Answer
# 12
I have created CLUSTERED on NON-PRIMARY Attribute because i
want my table has to be ordered in NON-PRIMARY column.
Because, most on my search and filtering will be on this
NON-PRIMARY column.

Is there any harm in this! Please recommend
 
Is This Answer Correct ?    1 Yes 0 No
Leelavinoth
 
  Re: Can we create clustered index on non primary key column
Answer
# 13
Yes, But on that table primary key should be created with 
non-clustered index and the columun u want to create a 
cluster index is should be unique
 
Is This Answer Correct ?    1 Yes 0 No
Vidit
 
  Re: Can we create clustered index on non primary key column
Answer
# 14
Yes, We can, only thing is that, we can create clustered 
index only on one key.If table contains any clustered index 
on any key(even on primary or on unique key) just drop it 
and create it on desired key. after it you can create a non 
clustered index on primary or on unique key.
 
Is This Answer Correct ?    2 Yes 0 No
Sandeep
 

 
 
 
Other SQL Server Interview Questions
 
  Question Asked @ Answers
 
how can we use a composite key for two tables and how can we represent it BoA1
What are the types of indexes available with SQL Server?  2
can any one answer this query,thank you in advance Table 1 has 2 columns: EmployeeId, T shirtsize(values can be 1,2,3) Table 2 has 2 columns: EmployeeId, Region Write SQL to Find the region which has the largest number of people with Tshirt size=3 Google10
About DTS usage ? Cognizent2
is there more the two primary key in a single table? Systematix22
How many types of cursors are there in SQL Server? 247Customer3
What are sub-queries? Give example? In which case sub-queries are not feasible? Infosys3
Whether the updations made to the views reflect the original records in the table NIIT5
What are statistics, under what circumstances they go out of date, how do you update them? HCL2
what operator performs pattern matching?  1
What are the all different types of Joins in SQL Server 2000, Anybody can explain each join with definition..Thanks in advance.... Siemens6
There is a trigger defined for INSERT operations on a table, in an OLTP system. The trigger is written to instantiate a COM object and pass the newly insterted rows to it for some custom processing. What do you think of this implementation? Can this be implemented better? HCL1
Explain the storage models of OLAP?  1
How to create logins using windows Authentication mode?  2
How do I list the available tables in a database I'm querying?  3
Which virtual table does a trigger use? TCS6
Explain Active/Active and Active/Passive cluster configurations  1
What is the use of CASCADE CONSTRAINTS?  2
wht is normalization?can u explain me in detail? TCS6
how to count datewise data in sqlserver IndusInd-Bank3
 
For more SQL Server Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com