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 ? | 18 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 |
What is instead of trigger sql server?
what is the information that can be stored inside a bit column? : Sql server database administration
Can you link only other SQL Servers or any database servers such as Oracle?
What is the difference between deallocate cursor and close cursor?
Which are the new data types introduced in sql server 2008?
What is difference between global temporary tables and local temporary tables?
1.How to check the backup file details if we do not have access to that folder 2.how to check the backup file size without connecting to the folder
3 Answers CarrizalSoft Technologies, IBM,
Can we add an identity column to decimal datatype?
What are the different ways of moving data/databases between servers and databases in SQL Server?
What is use of @@ spid in sql server?
How to loop through result set objects using odbc_fetch_row()?
What is coalesce in sql server?
Oracle (3259)
SQL Server (4518)
MS Access (429)
MySQL (1402)
Postgre (483)
Sybase (267)
DB Architecture (141)
DB Administration (291)
DB Development (113)
SQL PLSQL (3330)
MongoDB (502)
IBM Informix (50)
Neo4j (82)
InfluxDB (0)
Apache CouchDB (44)
Firebird (5)
Database Management (1411)
Databases AllOther (288)