我的桌子大约有60000行。我正在使用MS SQL Server Express 2012。
更新时,需要很长时间才能完成。
我的桌面设计如下。
CREATE TABLE [dbo].[Entry_Jangad_Lot](
[Srno] [bigint] IDENTITY(1,1) NOT NULL,
[Kapan] [nvarchar](50) NOT NULL,
[Lotno] [int] NOT NULL,
[Quality] [nvarchar](50) NOT NULL,
[Pcs] [int] NOT NULL,
[Caret] [decimal](18, 2) NOT NULL,
[JangadNo] [int] NOT NULL,
[IssuedTo] [nvarchar](50) NULL,
[IssuedDate] [nvarchar](50) NULL,
[Status] [nvarchar](50) NULL,
[ReceivedPcs] [int] NULL,
[ReceivedCaret] [decimal](18, 2) NULL,
[ReceivedDate] [nvarchar](50) NULL,
[ReceivedType] [nvarchar](50) NULL,
[Position] [nvarchar](50) NULL,
[Process] [nvarchar](50) NULL,
[MergedStatus] [nvarchar](50) NULL,
[MergedToLotno] [int] NULL,
CONSTRAINT [PK_Entry_Jangad_Lot_1] PRIMARY KEY CLUSTERED
(
[Srno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
我正在使用以下过程来更新表记录。
CREATE procedure [dbo].[sp_add_update_lot_receive]
(
@mode nvarchar(50),
@Kapan nvarchar(50),
@Lotno int,
@ReceivedPcs int,
@ReceivedCaret decimal(18,2),
@ReceivedDate nvarchar(50),
@ReceivedType nvarchar(50)
)
as
if @mode='ADD'
begin
declare @srno int
select @srno=srno from Entry_Jangad_Lot where Kapan=@Kapan
and Lotno=@Lotno
and Position='CURRENT'
update Entry_Jangad_Lot set
ReceivedPcs=@ReceivedPcs,
ReceivedCaret=@ReceivedCaret,
ReceivedDate=@ReceivedDate,
ReceivedType=@ReceivedType,
Status='RECEIVED'
where srno=@srno
--where Kapan=@Kapan
--and Lotno=@Lotno
--and Position='CURRENT'
if @ReceivedType='POLISH'
begin
update Entry_Jangad_Lot set
Process='POLISH'
where srno=@srno
--where Kapan=@Kapan
--and Lotno=@Lotno
--and Position='CURRENT'
end
else
begin
if @ReceivedType='TABLE'
begin
update Entry_Jangad_Lot set
Process='TABLE'
where srno=@srno
--where Kapan=@Kapan
--and Lotno=@Lotno
--and Position='CURRENT'
end
else
begin
update Entry_Jangad_Lot set
Process='NOTPOLISH'
where srno=@srno
--where Kapan=@Kapan
--and Lotno=@Lotno
--and Position='CURRENT'
end
end
end
GO
也可以使用以下索引。
ALTER TABLE [dbo].[Entry_Jangad_Lot] ADD CONSTRAINT [PK_Entry_Jangad_Lot_1] PRIMARY KEY CLUSTERED
(
[Srno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20150422-160201] ON [dbo].[Entry_Jangad_Lot]
(
[Kapan] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
CREATE NONCLUSTERED INDEX [NonClusteredIndex-20150422-155655] ON [dbo].[Entry_Jangad_Lot]
(
[Kapan] ASC,
[Lotno] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
修改
/****** Object: Statistic [_WA_Sys_00000003_47DBAE45] Script Date: 27/04/2015 12:33:24 ******/
CREATE STATISTICS [_WA_Sys_00000003_47DBAE45] ON [dbo].[Entry_Jangad_Lot]([Lotno]) WITH STATS_STREAM = 0x01000000010000000000000000000000B90F1C72000000000B19000000000000CB18000000000000380374003800000004000A00000000000000000042004300070000002508C40085A400004ECE000000000000ADA80000000000005DCA253D8A4B863B0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000C1000000C1000000010000001400000000008040004E4E4700000000000080400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000005F17000000000000671700000000000008060000000000001F0600000000000036060000000000004D0600000000000064060000000000007B060000000000009206000000000000A906000000000000C006000000000000D706000000000000EE0600000000000005070000000000001C0700000000000033070000000000004A07000000000000610700000000000078070000000000008F07000000000000A607000000000000BD07000000000000D407000000000000EB0700000000000002080000000000001908000000000000300800000000000047080000000000005E0800000000000075080000000000008C08000000000000A308000000000000BA08000000000000D108000000000000E808000000000000FF0800000000000016090000000000002D0900000000000044090000000000005B0900000000000072090000000000008909000000000000A009000000000000B709000000000000CE09000000000000E509000000000000FC09000000000000130A0000000000002A0A000000000000410A000000000000580A0000000000006F0A000000000000860A0000000000009D0A000000000000B40A000000000000CB0A000000000000E20A000000000000F90A000000000000100B000000000000270B0000000000003E0B000000000000550B0000000000006C0B000000000000830B0000000000009A0B000000000000B10B000000000000C80B000000000000DF0B000000000000F60B0000000000000D0C000000000000240C0000000000003B0C000000000000520C000000000000690C000000000000800C000000000000970C000000000000AE0C000000000000C50C000000000000DC0C000000000000F30C0000000000000A0D000000000000210D000000000000380D0000000000004F0D000000000000660D0000000000007D0D000000000000940D000000000000AB0D000000000000C20D000000000000D90D000000000000F00D000000000000070E0000000000001E0E000000000000350E0000000000004C0E000000000000630E0000000000007A0E000000000000910E000000000000A80E000000000000BF0E000000000000D60E000000000000ED0E000000000000040F0000000000001B0F000000000000320F000000000000490F000000000000600F000000000000770F0000000000008E0F000000000000A50F000000000000BC0F000000000000D30F000000000000EA0F000000000000011000000000000018100000000000002F1000000000000046100000000000005D1000000000000074100000000000008B10000000000000A210000000000000B910000000000000D010000000000000E710000000000000FE1000000000000015110000000000002C1100000000000043110000000000005A11000000000000711100000000000088110000000000009F11000000000000B611000000000000CD11000000000000E411000000000000FB1100000000000012120000000000002912000000000000401200000000000057120000000000006E1200000000000085120000000000009C12000000000000B312000000000000CA12000000000000E112000000000000F8120000000000000F1300000000000026130000000000003D1300000000000054130000000000006B1300000000000082130000000000009913000000000000B013000000000000C713000000000000DE13000000000000F5130000000000000C1400000000000023140000000000003A14000000000000511400000000000068140000000000007F140000000000009614000000000000AD14000000000000C414000000000000DB14000000000000F2140000000000000915000000000000201500000000000037150000000000004E1500000000000065150000000000007C150000000000009315000000000000AA15000000000000C115000000000000D815000000000000EF1500000000000006160000000000001D1600000000000034160000000000004B16000000000000621600000000000079160000000000009016000000000000A716000000000000BE16000000000000D516000000000000EC1600000000000003170000000000001A1700000000000031170000000000004817000000000000100014005CD2ED43000000000000803F01000000040000100014004036ED43000000000000803F02000000040000100014006255E843000000000000803F03000000040000100014004036ED43000000000000803F0400000004000010001400786EEE43000000000000803F05000000040000100014006255E843000000000000803F0600000004000010001400D1C5EA43000000000000803F0700000004000010001400AFA6EF43000000000000803F0800000004000010001400B529EA43000000000000803F0900000004000010001400C5BFF543000000000000803F0A00000004000010001400AA23F543000000000000803F0B00000004000010001400E7DEF043000000000000803F0C0000000400001000140008FEEB43000000000000803F0D0000000400001000140046B9E743000000000000803F0E0000000400001000140046B9E743000000000000803F0F00000004000010001400D1C5EA43000000000000803F10000000040000100014000E81E643000000000000803F11000000040000100014000E81E643000000000000803F1200000004000010001400ED61EB43000000000000803F1300000004000010001400D748E543000000000000803F14000000040000100014001404E143000000000000803F15000000040000100014003623DC43000000000000803F1600000004000010001400FEEADA43000000000000803F1700000004000010001400DCCBDF43000000000000803F18000000040000100014004C3CE243000000000000803F19000000040000100014004C3CE243000000000000803F1A00000004000010001400A593DE43000000000000803F1B00000004000010001400F867E043000000000000803F1C0000000400001000140073DED743000000000000803F1D00000004000010001400C12FDF43000000000000803F1E00000004000010001400E24EDA43000000000000803F1F00000004000010001400FEEADA43000000000000803F2000000004000010001400F2E4E543000000000000803F21000000040000100014001A87DB43000000000000803F22000000040000100014003BA6D643000000000000803F2300000004000010001400E8D1D443000000000000803F2400000004000010001400046ED543000000000000803F2500000004000010001400CC35D443000000000000803F260000000400001000140094FDD243000000000000803F27000000040000100014007961D243000000000000803F28000000040000100014005DC5D143000000000000803F29000000040000100014009A80CD43000000000000803F2A00000004000010001400B099D343000000000000803F2B0000000400001000140094FDD243000000000000803F2C00000004000010001400D2B8CE43000000000000803F2D00000004000010001400258DD043000000000000803F2E000000040000100014007EE4CC43000000000000803F2F000000040000100014002B10CB43000000000000803F3000000004000010001400258DD043000000000000803F31000000040000100014006E4EC143000000000000803F320000000400001000140015F7C443000000000000803F3300000004000010001400B61CCE43000000000000803F3400000004000010001400DDBEC343000000000000803F3500000004000010001400C7A5BD43000000000000803F3600000004000010001400E341BE43000000000000803F3700000004000010001400A686C243000000000000803F3800000004000010001400FFDDBE43000000000000803F3900000004000010001400906DBC43000000000000803F3A000000040000100014001B7ABF43000000000000803F3B00000004000010001400E341BE43000000000000803F3C00000004000010001400B18CB743000000000000803F3D00000004000010001400E9C4B843000000000000803F3E000000040000100014007FD7B043000000000000803F3F0000000400001000140095F0B643000000000000803F40000000040000100014000AE4B343000000000000803F4100000004000010001400EF47B343000000000000803F4200000004000010001400421CB543000000000000803F4300000004000010001400643BB043000000000000803F4400000004000010001400643BB043000000000000803F4500000004000010001400F4CAAD43000000000000803F460000000400001000140016EAA843000000000000803F47000000040000100014002680B443000000000000803F48000000040000100014003286A943000000000000803F490000000400001000140069BEAA43000000000000803F4A000000040000100014004E22AA43000000000000803F4B000000040000100014004E22AA43000000000000803F4C0000000400001000140000D1A243000000000000803F4D0000000400001000140053A5A443000000000000803F4E000000040000100014000BD79743000000000000803F4F000000040000100014000BD79743000000000000803F5000000004000010001400430F9943000000000000803F510000000400001000140006549D43000000000000803F5200000004000010001400CE1B9C43000000000000803F530000000400001000140080CA9443000000000000803F5400000004000010001400B8029643000000000000803F550000000400001000140080CA9443000000000000803F56000000040000100014009C669543000000000000803F5700000004000010001400BE859043000000000000803F580000000400001000140033798D43000000000000803F59000000040000100014006AB18E43000000000000803F5A00000004000010001400864D8F43000000000000803F5B00000004000010001400A86C8A43000000000000803F5C00000004000010001400E5278643000000000000803F5D0000000400001000140017DD8C43000000000000803F5E00000004000010001400E5278643000000000000803F5F0000000400001000140038FC8743000000000000803F6000000004000010001400DFA48B43000000000000803F610000000400001000140054988843000000000000803F6200000004000010001400ADEF8443000000000000803F63000000040000100014003E7F8243000000000000803F6400000004000010001400CF0E8043000000000000803F650000000400001000140022E38143000000000000803F6600000004000010001400C03C7B43000000000000803F6700000004000010001400AA237543000000000000803F6800000004000010001400037B7143000000000000803F69000000040000100014007DF16843000000000000803F6A00000004000010001400249A6C43000000000000803F6B00000004000010001400249A6C43000000000000803F6C0000000400001000140046B96743000000000000803F6D00000004000010001400ED616B43000000000000803F6E00000004000010001400249A6C43000000000000803F6F00000004000010001400249A6C43000000000000803F7000000004000010001400D7486543000000000000803F710000000400001000140030A06143000000000000803F720000000400001000140051BF5C43000000000000803F730000000400001000140073DE5743000000000000803F7400000004000010001400CC355443000000000000803F75000000040000100014007EE44C43000000000000803F760000000400001000140068CB4643000000000000803F770000000400001000140068CB4643000000000000803F780000000400001000140068CB4643000000000000803F79000000040000100014007EE44C43000000000000803F7A00000004000010001400A0034843000000000000803F7B000000040000100014005EB83543000000000000803F7C0000000400001000140052B24043000000000000803F7D000000040000100014008AEA4143000000000000803F7E0000000400001000140095F03643000000000000803F7F00000004000010001400EF473343000000000000803F8000000004000010001400E3413E43000000000000803F8100000004000010001400CD283843000000000000803F82000000040000100014005EB83543000000000000803F8300000004000010001400489F2F43000000000000803F840000000400001000140005613943000000000000803F8500000004000010001400D92E2D43000000000000803F860000000400001000140010672E43000000000000803F8700000004000010001400B70F3243000000000000803F8800000004000010001400A1F62B43000000000000803F8900000004000010001400EF473343000000000000803F8A000000040000100014005EB83543000000000000803F8B000000040000100014007FD73043000000000000803F8C0000000400001000140010672E43000000000000803F8D00000004000010001400D92E2D43000000000000803F8E00000004000010001400ACFC2043000000000000803F8F0000000400001000140075C41F43000000000000803F9000000004000010001400ACFC2043000000000000803F9100000004000010001400CE1B1C43000000000000803F92000000040000100014008BDD2543000000000000803F9300000004000010001400CE1B1C43000000000000803F9400000004000010001400C3080B43CA0F1A43CA0F1A43960000000400001000140080CA1443000000000000803F9700000004000010001400E52706433EAA0C433EAA0C43990000000400001000140067D8E2429BF201439BF201439B000000040000100014001A87DB42000000000000803F9C00000004000010001400EE54CF42000000000000803F9D0000000400001000140089F7DD42000000000000803F9E00000004000010001400A003C8427B62DE427B62DE42A00000000400001000140052B2C0427B62DE427B62DE42A200000004000010001400D92EAD42A88DBB42A88DBB42A400000004000010001400489FAF42000000000000803FA500000004000010001400CE1B9C42EE83B342EE83B342A7000000040000100014008BDDA542000000000000803FA8000000040000100014005FAB9942000000000000803FA900000004000010001400A2E98F42000000000000803FAA000000040000100014005FAB9942000000000000803FAB0000000400001000140076B78342000000000000803FAC00000004000010001400115A9242000000000000803FAD0000000400001000140033798D42ED0A9642ED0A9642AF0000000400001000140076B78342000000000000803FB000000004000010001400F03A974290C2A04290C2A042B2000000040000100014001A875B427BDB7B427BDB7B42B400000004000010001400D7486542000000000000803FB500000004000010001400F867604207C86B4207C86B42B7000000040000100014003BA65642000000000000803FB80000000400001000140069BE2A42000000000000803FB900000004000010001400056139421DA14B421DA14B42BB00000004000010001400A0034842000000000000803FBC000000040000100014008BDD2542A88D3B42A88D3B42BE0000000400001000140033790D42BE669B42BE661B42C10000000400001000140033790D42621E2642621E2642C3000000040000100014002FADFD41000000000000803FC40000000400001000140076B70342BE661B42BE661B42C600000004000010001400F867E041000000000000803FC7000000040000100014002FADFD41000000000000803FC8000000040000100014000561B941000000000000803FC9000000040000100014000561B941AA7F7642AA7FF641CC000000040000100014007EE4CC41000000000000803FCD000000040000100014008BDDA541ED0A9642910EC841D100000004000010001400C2224341BE661B42BE669B41D400000004000010001400489F2F4107C8EB4107C86B41D7000000040000100014007D6E9940AA7F76421C552441DE000000040000100014003505C240000000000000803FDF0000000400001000140038720040356C6642480A4240F3000000040000100014000000803F000000000000803FF40000000400004ECE000000000000
GO
/****** Object: Statistic [_WA_Sys_0000000A_47DBAE45] Script Date: 27/04/2015 12:33:24 ******/
CREATE STATISTICS [_WA_Sys_0000000A_47DBAE45] ON [dbo].[Entry_Jangad_Lot]([Status]) WITH STATS_STREAM = 0x01000000010000000000000000000000EE2F86BC000000006C020000000000002C02000000000000E7020000E7000000640000000000000008D000346C080000070000008A27C40085A400004ECE00000000000003AA000000000000000000000000003F000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000002000000020000000100000010000000E7C17E41004E4E4700000000E7C17E410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000005C00000000000000B800000000000000C0000000000000001000000000000000350000000000000030001000522C0045000000000000803F04000001002500500045004E00440049004E004700300010003B4B4647000000000000803F0400000100270052004500430045004900560045004400FF01000000000000008A08000002000000280000002800000000000000000000000F000000500045004E00440049004E00470052004500430045004900560045004400030000004000000000900700000055200807000035080000004ECE000000000000
GO
/****** Object: Statistic [_WA_Sys_0000000E_47DBAE45] Script Date: 27/04/2015 12:33:24 ******/
CREATE STATISTICS [_WA_Sys_0000000E_47DBAE45] ON [dbo].[Entry_Jangad_Lot]([ReceivedType]) WITH STATS_STREAM = 0x010000000100000000000000000000009D06313800000000F602000000000000B602000000000000E7020000E7000000640000000000000008D0003400000000070000000208C40085A400004ECE00000000000003AA00000000000000000000ABAA2A3E000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005000000050000000100000010000000798F0841004E4E4700000045798F0841000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000013000000000000000000000000000000C50000000000000042010000000000004A010000000000002800000000000000470000000000000062000000000000008100000000000000A40000000000000030001000DF227F44000000000000803F04000001001F00320049004E00310030001000238D8B46000000000000803F04000001001B00340050003000100042A10044000000000000803F04000001001F00470048004100540030001000256DD046000000000000803F0400000100230050004F004C00490053004800300010001A919245000000000000803F040000010021005400410042004C004500FF01000000550000008A080000060000002800000028000000000000000000000015000000320049004E00310034005000470048004100540050004F004C004900530048005400410042004C00450006000000400000000090040000002AA002040000E4020000900406000015A0060A0000500400001005100000C2004ECE000000000000
GO
/****** Object: Statistic [_WA_Sys_0000000F_47DBAE45] Script Date: 27/04/2015 12:33:24 ******/
CREATE STATISTICS [_WA_Sys_0000000F_47DBAE45] ON [dbo].[Entry_Jangad_Lot]([Position]) WITH STATS_STREAM = 0x01000000010000000000000000000000064DC76D000000002702000000000000E701000000000000E7020050E7000000640000000000000008D0003400000000070000007927C40085A400004ECE00000000000003AA000000000000000000000000003F0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000010000000100000001000000100000004130FC40004E4E470058B4464130FC400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000002D0000000000000073000000000000007B00000000000000080000000000000030001000B444E846000000000000803F04000001002500430055005200520045004E005400FF01000000BC0300008A080000020000002800000028000000000000000000000007000000430055005200520045004E0054000200000040000000002007000000CE040000004ECE000000000000
GO
/****** Object: Statistic [_WA_Sys_00000010_47DBAE45] Script Date: 27/04/2015 12:33:24 ******/
CREATE STATISTICS [_WA_Sys_00000010_47DBAE45] ON [dbo].[Entry_Jangad_Lot]([Process]) WITH STATS_STREAM = 0x01000000010000000000000000000000DB5E8FA9000000009C020000000000005C02000000000000E7020000E7000000640000000000000008D0003400000000070000001808C40085A400004ECE00000000000003AA00000000000000000000ABAAAA3E000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003000000030000000100000010000000961F6241004E4E4700000000961F62410000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000130000000000000000000000000000008500000000000000E800000000000000F00000000000000018000000000000004100000000000000640000000000000030001000A282A046000000000000803F040000010029004E004F00540050004F004C00490053004800300010007C8ED246000000000000803F0400000100230050004F004C0049005300480030001000852BA645000000000000803F040000010021005400410042004C004500FF01000000000000008A08000003000000280000002800000000000000000000000E0000004E004F00540050004F004C004900530048005400410042004C004500040000004000000000A00900000053030000A0060300005B0400001005090000DC004ECE000000000000
GO
修改
DECLARE @return_value int
EXEC @return_value = [dbo]。[sp_add_update_lot_receive] @mode = N' ADD',@ Kapan = N' / SL',@ Point = 164,@ ReceivedPcs = 300, @ReceivedCaret = 2.90,@ ReceivedDate = N' 27/04 / 2015', @ReceivedType = N' POLISH'
SELECT'返回值' = @return_value
GO
答案 0 :(得分:0)
如果我理解你的逻辑,那么这不是更简单的做法:
CREATE procedure [dbo].[sp_add_update_lot_receive]
(
@mode nvarchar(50),
@Kapan nvarchar(50),
@Lotno int,
@ReceivedPcs int,
@ReceivedCaret decimal(18,2),
@ReceivedDate nvarchar(50),
@ReceivedType nvarchar(50)
)
as
if @mode='ADD'
begin
update Entry_Jangad_Lot set
ReceivedPcs=@ReceivedPcs,
ReceivedCaret=@ReceivedCaret,
ReceivedDate=@ReceivedDate,
ReceivedType=@ReceivedType,
Status='RECEIVED',
Process = coalesce (t.Process, 'NOTPOLISH')
from Entry_Jangad_Lot
outer apply (values
('TABLE'),
('POLISH')
) t(Process)
where Kapan=@Kapan
and Lotno=@Lotno
and Position='CURRENT'
and t.Process = Entry_Jangad_Lot.Process
end
答案 1 :(得分:-1)
看起来并不太糟糕。如果我不得不猜测(我这样做是因为我不在SQL Server Express附近),我会说这是因为你在索引上有一个INT srno转换为BIGINT版本。这可能导致隐式转换停止使用索引。
另外,你有一个不需要的索引(Kapan和Lotno的索引也只是Kapan)。
另外,定义“长时间”:)