多记录的情况下如何判断表中某一类记录是否存在?(100分)

  • 主题发起人 ch_100755
  • 开始时间
C

ch_100755

Unregistered / Unconfirmed
GUEST, unregistred user!
现有一个问题我有一个商品资料表
item_table 很多记录
item_no item_name type_no......
另有一个商品类别表
type_table
type_no,type_name
在类别资料删除时我要判断商品资料表中是否有此类别的资料存在
我是这样写的:
adoquery.close;
adoquery.sql.clear;
adoquery.sql.text:='select item_no from item_table where type_no='''+trim(edit1.text)+''' order by item_no'
adoquery.prepared:=true;
adoquery.open;
if not adoquery.isempty then
begin
showmessage('无法删除');
exit;
end;
这样写虽然没有错但是如果遇到一个类别资料在商品资料表中有很多项时如上万项速度就很慢
问一下有没有更快一点的方法?



 
adoquery.sql.text:='select count(item_no) from item_table where type_no='''+trim(edit1.text)+''' order by item_no'
.........
if assigen(adoquery) and (adoquery.fields[0].asinteger>0) then
//不能删除
 
建立外健约束
 

Similar threads

S
回复
0
查看
3K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
顶部