Can we create a clustered index on composite primary key.

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do you need a sql server?

497


What are key constraints?

505


A trigger can reference objects outside the current database? State true or false.

542


Write a SQL query to make a column as unique?

623


How can I create a report based on a query? : sql server management studio

552






Explain about Joins?

597


What is it unwise to create wide clustered index keys?

575


What is unique key constraint?

626


Can an automatic recovery be initiated by a user?

549


How to sort the query output with order by clauses in ms sql server?

621


Can we use trigger new in before insert?

507


How to change the ownership of a schema in ms sql server?

548


What are the disadvantages of using querystrings to send data from one page to another?

578


Where are full-text indexes stored?

560


How to optimize stored procedure optimization?

510