Can we create a clustered index on composite primary key.
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
Explain logical operators in sql server?
What are the differences between char and varchar in ms sql server?
Explain sql server service broker?
What do you mean by an execution plan? How would you view it?
How to invoke a trigger on demand?
What are different replication agents and what's their purpose? : sql server replication
What is the Main Difference between ACCESS and SQL SERVER?
When columns are added to existing tables, what do they initially contain?
What Is The Difference Between Primary Key & Super Key
How to select true false based on column value in sql server?
What are the advantages of passing name-value pairs as parameters?
when you create a database how is it stored? : Sql server database administration