Assuming you have no constraints or indexes on the table like in your question, this clustered index should improve performance:
CREATE UNIQUE CLUSTERED INDEX cdx ON dbo.PartsHaveBestDisplayOrder (CodeRulesId,PackageId,DisplayOrder,PartId);
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I work on sql server 2019 i face issue on slow running
when I have 100000 part on table PartsHaveBestDisplayOrder
and all these parts have same package and same coderulesid and Different display order
so it take too much time
so are there are any way to achieve that quickly
script code sql server
IF OBJECT_ID(N'Extractreports.dbo.PartsHaveBestDisplayOrder') Is NOT NUll
BEGIN
DROP TABLE Extractreports.dbo.PartsHaveBestDisplayOrder
END
create table Extractreports.dbo.PartsHaveBestDisplayOrder
(
PartId int,
CodeRulesId int,
PackageId int,
DisplayOrder int
)
insert into Extractreports.dbo.PartsHaveBestDisplayOrder(PartId,CodeRulesId,PackageId,DisplayOrder)
values
(12111,120,19110,1),
(12901,120,19110,5),
(33091,120,19110,4),
(30911,120,19110,3),
(55899,120,19110,2),
(80122,120,19110,1),
(30918,120,19110,3),
(76012,120,19110,2),
(54031,120,19110,4),
(30401,120,19110,5)
what i try as below :
select T1.PartID as OrignalPartId , T2.PartId as RecomendationPartId,T1.DisplayOrder as OriginalDisplayOrder,T2.DisplayOrder as RecomendedDisplayOrder
from Extractreports.dbo.PartsHaveBestDisplayOrder T1 inner join
Extractreports.dbo.PartsHaveBestDisplayOrder T2 on T1.CodeRulesId =T2.CodeRulesId and T1.PackageID=t2.PackageID
where T2.DisplayOrder >t1.DisplayOrder
so please can you help me by another way to achive that quickly
Assuming you have no constraints or indexes on the table like in your question, this clustered index should improve performance:
CREATE UNIQUE CLUSTERED INDEX cdx ON dbo.PartsHaveBestDisplayOrder (CodeRulesId,PackageId,DisplayOrder,PartId);
Hi @ahmed salah ,
Creating indexes is one of the more effective ways to improve query performance, so if you want to use SQL Graph, then check out this article:
https://learn.microsoft.com/en-us/sql/relational-databases/graphs/sql-graph-overview?view=sql-server-ver16
Best regards
Niko
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".