Can we create a clustered index on composite primary key.

Answers were Sorted based on User's Feedback



Can we create a clustered index on composite primary key...

Answer / monal

You can also do this.

create table Test
(officeid integer not null,
empid integer not null,
age integer ,
sex varchar(5),
name varchar(20),
PRIMARY KEY (OFFICEID, EMPID))


this will also create composite primary key and cluster
index on composite primary key.

Is This Answer Correct ?    17 Yes 2 No

Can we create a clustered index on composite primary key...

Answer / anil kumar

Here's the procedure:

Create a table with no primary key defined.
Create clustered index on the primary key columns.
Alter the table to define the primary key.

Table creation:

create table CDSWEB.Anil (officeid integer not null,
empid integer not null,
age integer ,sex varchar(5),
name varchar(20));

Index creation:
create index CDSWEB.AN001 on CDSWEB.Anil(officeid,empid)
CLUSTER;

Primary key defined:

alter table CDSWEB.ANIL
add primary key (officeid,empid);

Is This Answer Correct ?    2 Yes 0 No

Can we create a clustered index on composite primary key...

Answer / shatrunjay shukla

Yes
If you are creating a composite Primary Key, or a composite Clustered Index that is NOT a Primary Key, you are creating a single index that uses both column values as the clustering key.

CREATE TABLE T(id INT, cat INT, uName SYSNAME);

CREATE UNIQUE CLUSTERED INDEX ix_T_id_cat ON T (id,cat);



SELECT * FROM SYS.INDEXES WHERE object_id = OBJECT_ID('T');

Is This Answer Correct ?    1 Yes 0 No

Post New Answer

More SQL Server Interview Questions

What is full outer join in sql server joins?

0 Answers  


Can primary key be a foreign key?

0 Answers  


Is it possible to have more then one foreign key in a single table? if possible, is this the good way to design the table?

2 Answers  


How can u get the number of pupils connecting the database?

1 Answers   Cap Gemini,


What is recursion? Is it possible for a stored procedure to call itself or recursive stored procedure? How many levels of sp nesting is possible?

0 Answers  






How to count rows with the count(*) function in ms sql server?

0 Answers  


i want to create procedure for create table in sql server 2005 for example create procedure create_table @table varchar(20) as create @table( id int, name char(20) ) but it will get error what is solution?

5 Answers   Aptech,


Explain what you mean by 3 tier architecture.

0 Answers   TCS,


What are different types of Keys? Please explain all the keys with a suitable example.

4 Answers  


How to enter unicode character string literals in ms sql server?

0 Answers  


Describe in brief system database.

0 Answers  


difference between truncate, delete aur drop?

2 Answers  


Categories