写SQL语句的时候条件使用变量,这样可以缓存执行计划,减轻内存压力。比如 SELECT Feild1 from Table1 where Feild1 == '1' SELECT Feild1 from Table1 where Feild1 == '2' SELECT Feild1 from Table1 where Feild1 == '3'写成: SELECT Feild1 from Table1 where Feild1 == @Condition
我到网上找了些资料,举例子如下: sqlcon = new SqlConnection(strCon); sqlcon.Open(); DataSet ds = new DataSet(); SqlDataAdapter myda1 = new SqlDataAdapter("select top 6 news_title from tb_News", sqlcon); SqlDataAdapter myda2 = new SqlDataAdapter("select top 6 patent_title from tb_Patent", sqlcon); myda1.Fill(ds, "tb_news"); myda2.Fill(ds, "tb_patent"); 本来,我要执行形如:“select * from tb_news where 字段a1 in (select 字段b2 from tb_patent where 字段b1 = 'a')” 要频繁执行,大约每次会执行上千次请问,能够运用这种技术吗?
就像你说的这样,为什么不使用连接查询而要用到in关键字呢? select * from tb_news news join tb_parent p on news.字段a1 = p.字段b2 wher p.字段b1 = 'a'
SELECT Feild1 from Table1 where Feild1 == '1'
SELECT Feild1 from Table1 where Feild1 == '2'
SELECT Feild1 from Table1 where Feild1 == '3'写成:
SELECT Feild1 from Table1 where Feild1 == @Condition
我在网上查的资料也这样说,能更详细点介绍吗?或者哪有demo
跪求
sqlcon = new SqlConnection(strCon);
sqlcon.Open();
DataSet ds = new DataSet(); SqlDataAdapter myda1 = new SqlDataAdapter("select top 6 news_title from tb_News", sqlcon);
SqlDataAdapter myda2 = new SqlDataAdapter("select top 6 patent_title from tb_Patent", sqlcon);
myda1.Fill(ds, "tb_news");
myda2.Fill(ds, "tb_patent");
本来,我要执行形如:“select * from tb_news where 字段a1 in (select 字段b2 from tb_patent where 字段b1 = 'a')” 要频繁执行,大约每次会执行上千次请问,能够运用这种技术吗?
select *
from tb_news news
join tb_parent p on news.字段a1 = p.字段b2
wher p.字段b1 = 'a'
是吗? 请问我这种情况 用LINQ的效果好吗?