Home > database >  Indexing on product table's Column (itemId)
Indexing on product table's Column (itemId)

Time:09-15

I want to do indexing on product table's column i.e ItemId. product's table primary key is Id. by default primary key i.e Id is clusted index I want to do indexing in one column i.e itemId the images are shown below.

enter image description here

enter image description here

CodePudding user response:

You can create it as follow, you take into consideration why you are doing indexing, if you have lot of insert,update or delete operation on this table then it can affect performance Indexing Dos and Don’ts

Non Clustured Index
CREATE INDEX NCLIItemID ON product(itemId);

Clustured Index
CREATE CLUSTERED INDEX CLIItemID ON product(itemId);

UNIQUE Index
CREATE UNIQUE INDEX UIItemID ON product(itemId);

CodePudding user response:

CREATE NONCLUSTERED INDEX IX_Product_ItemId   
    ON dbo.Product (ItemId); 

Please have a look into the references based upon type of index you are looking to create for column ItemId (Can't have more than one clustered index for a table)

https://docs.microsoft.com/en-us/sql/relational-databases/indexes/create-nonclustered-indexes?source=recommendations&view=sql-server-ver16

https://docs.microsoft.com/en-us/sql/relational-databases/indexes/create-clustered-indexes?view=sql-server-ver16

https://docs.microsoft.com/en-us/sql/relational-databases/indexes/create-unique-indexes?view=sql-server-ver16

  • Related