读书人

怎么优化SQL语句

发布时间: 2012-02-17 17:50:42 作者: rapoo

如何优化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 

读书人网 >SQL Server

热点推荐