可以在SQL数据库中完成二进制搜索吗? [英] Can a binary search be done in a database in SQL?

查看:118
本文介绍了可以在SQL数据库中完成二进制搜索吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好。我正在使用C#编程语言访问简单的数据库(在Microsoft SQL Server上)



当前,我正在使用DataReader对象访问数据库。
所以这是我的问题:是否可以对特定数据执行二进制搜索(在C#中),以便我可以使搜索更快?



<当前,我正在使用一个简单的while循环来搜索数据库的内容。我相信这是按顺序完成的。

 而(pReader.Read())
{
if((String)pReader [ theData ] == The_thing_im_searching_for)
休息;
}

那么有什么方法可以进行二进制搜索?

解决方案

如果您仍在使用数据库,则应编写一条select语句来搜索要查找的内容,而不是遍历数据库手动。没有理由重新发明轮子。


OK. I am using the C# programming language to access a simple database (on Microsoft SQL Server)

Currently, I am using the DataReader object to access the database. So here is my question: is it possible to do a binary search (in C#) for a particular piece of data so that i can make the search faster?

Currently, I'm using a simple while loop to search the contents of the database. I believe this is done sequentially.

while (pReader.Read())
{
   if ((String)pReader["theData"] == "The_thing_im_searching_for")
   break;
}

So is there any way to do a binary search?

解决方案

If you're using a database anyways, you should write a select statement to search for what you're looking for instead of iterating through the database manually. There's no reason to reinvent the wheel.

这篇关于可以在SQL数据库中完成二进制搜索吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆