Tôi cũng nghĩ rằng bảng tạm thời có thể là giải pháp tốt nhất.
Nếu bạn đã thực hiện "xóa từ .. trong đó ID trong (chọn id từ ...)" thì vẫn có thể chậm với các truy vấn lớn.Do đó, tôi khuyên bạn nên xóa bằng cách sử dụng kết nối - nhiều người không biết về chức năng đó.
Vì vậy, cho ví dụ này bảng:
-- set up tables for this example
if exists (select id from sysobjects where name = 'OurTable' and type = 'U')
drop table OurTable
go
create table OurTable (ID integer primary key not null)
go
insert into OurTable (ID) values (1)
insert into OurTable (ID) values (2)
insert into OurTable (ID) values (3)
insert into OurTable (ID) values (4)
go
Sau đó chúng tôi có thể viết mã xóa của chúng tôi như sau:
create table #IDsToDelete (ID integer not null)
go
insert into #IDsToDelete (ID) values (2)
insert into #IDsToDelete (ID) values (3)
go
-- ... etc ...
-- Now do the delete - notice that we aren't using 'from'
-- in the usual place for this delete
delete OurTable from #IDsToDelete
where OurTable.ID = #IDsToDelete.ID
go
drop table #IDsToDelete
go
-- This returns only items 1 and 4
select * from OurTable order by ID
go
là ASE này hoặc ASA? Bạn có biết số phiên bản của mình không? – AdamH
Đây là phiên bản ASE 10x. – amit