首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

怎么优化SQL语句

2012-02-17 
如何优化SQL语句?C# codeselect * from news where id1 or id2 or id4 or id18 or id22 or id33上面

如何优化SQL语句?

C# code
select * from news where id=1 or id=2 or id=4 or id=18 or id=22 or id=33


上面这段SQL能否优化一下?

[解决办法]
select * from news 
where id in(1,2,4,18,22,33)
[解决办法]
id列上加索引

SQL code
select * from news where id=1 union allselect * from news where id=2union allselect * from news where id=4union allselect * from news where id=18union allselect * from news where id=22union allselect * from news where id=33 

热点排行