查询 CSV 文件/一般数据库问题

发布于 2024-10-14 09:35:19 字数 592 浏览 0 评论 0原文

好吧,总的来说我对数据库有点陌生。我了解它们背​​后的基本理论,并且到处都搞出了奇怪的 Access DB。

我正在努力了解的一件事是 SQL 查询如何访问数据库的细节。

假设您有一个场景,LAN 服务器上有一个数据库(为了论证起见,假设它是 MS Access)。您可以从客户端计算机上运行一些 SQL 查询或其他查询。客户端计算机是否必须下载整个数据库才能运行所述查询(即使查询结果只有一行)?或者它是否以某种方式设法只获取它想要通过 ol' CAT5 传输的数据?服务器必须运行任何东西才能做到这一点吗?不太明白客户端如何在服务器不必做一些工作的情况下获得查询结果......

我在谷歌搜索时看到了关于这个问题的两个相互矛盾的故事。

因此,接下来的问题(可能已经得到解答)是这样的:如果您可以查询数据库而不必获取整个该死的东西,并且服务器不需要运行任何其他软件,那么可以使用 CSV 完成同样的事情吗?如果没有,为什么不呢?

我问的原因是我正在为移动设备开发一个应用程序,需要与某种类型的数据库或 CSV 文件通信,并且它将以相当高的速率更新记录(条形码扫描),所以不想网络逐渐停止(这是一个缓慢的[插入相关侮辱]的袋子)。从设备到服务器传输的数据越少越好。

提前致谢

OK so I'm kinda new to databases in general. I understand the basic theory behind them and have knocked up the odd Access DB here and there.

One thing I'm struggling to learn about is the specifics of how e.g. an SQL query accesses a database.

So say you have a scenario where there's a database on a LAN server (let's say it's MS Access for arguments sake). You run some SQL query or other on it from a client machine. Does the client machine have to download the entire database to run said query (even if the result of the query is just one line)? Or does it somehow manage to get just the data it wants to come down the ol' CAT5? Does the server have to be running anything to do that? Can't quite understand how the client could get JUST the query results without the server having to do some of the work...

I'm seeing two conflicting stories on this matter when googling stuff.

And so this follows on the next question (which may already be answered): if you CAN query a DB without having to get the whole damn thing, and without the server running any other software, can the same be done with a CSV? If not, why not?

Reason I ask is I'm developing an app for a mobile device that needs to talk to a db or CSV file of some kind, and it'll be updating records at a pretty high rate (barcode scanning), so don't want the network to grind to a halt (it's a slow bag of [insert relevant insult] as it is). The less data travelling from device to server, the better.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

隱形的亼 2024-10-21 09:35:19

各种 SQL 服务器只是:一台服务器。它是一个监听客户端查询并发回响应的程序。它不仅仅是它的数据。

CSV 文件或“平面文件”只是数据。它无法自行响应查询。

因此,当您在网络上时,您的查询将发送到服务器,服务器负责查找适当的结果。当您打开平面文件时,您正在使用网络和/或文件系统来读取/写入整个文件。

编辑以添加有关您的具体用法的注释。您可能需要使用数据库引擎,因为查询将占用最少的网络流量。例如,当您扫描条形码时,您的查询可能与以下文本一样简单:

INSERT INTO barcode_table ('code', 'scan_date', 'user') VALUES ('1234567890', '2011-01-24 12:00:00', '1');

上述字符串由数据库引擎处理,并存储代码(以及任何相关支持数据)。您的应用程序不需要打开文件、向其中追加数据以及关闭它。一旦文件变得很大,后者就会变得非常慢,并且并发可能会成为许多用户访问它的问题。

如果您的应用程序需要向用户显示一些数据,它将以相同的方式请求特定信息,并且服务器将生成相关结果。因此,想象一个场景,用户想要一个与某些过滤器匹配的产品列表。如果您的产品是书籍,假设用户请求特定作者的列表:

SELECT products.title, barcode_table.code
FROM products, barcode_table
WHERE products.author = 'Anders Hejlsberg'
ORDER BY products.title ASC;

在此示例中,只有这些产品标题及其条形码从服务器发送到移动应用程序。

希望这些示例有助于证明使用某种结构数据库引擎而不是使用平面文件。然而,数据库的具体风格和实现本身就是另一个问题。

The various SQL servers are just that: a server. It's a program that listens for client queries and sends back a response. It is more than just its data.

A CSV file, or "flat file" is just data. There is no way for it to respond to a query by itself.

So, when you are on a network, your query is sent to the server, which does the work of finding the appropriate results. When you open a flat file, you're using the network and/or file system to read/write the entire file.

Edit to add a note about your specific usage. You'll probably want to use a database engine, as the queries are going to be the least amount of network traffic. For example, when you scan a barcode, your query may be as simple as the following text:

INSERT INTO barcode_table ('code', 'scan_date', 'user') VALUES ('1234567890', '2011-01-24 12:00:00', '1');

The above string is handled by the database engine and the code (along with whatever relevant support data) is stored. No need for your application to open a file, append data to it, and close it. The latter becomes very slow once files get to a large size, and concurrency can become a problem with many users accessing it.

If your application needs to display some data to your user, it would request specific information the same way, and the server would generate the relevant results. So, imagine a scenario in which the user wants a list of products that match some filter. If your products were books, suppose the user requested a list by a specific author:

SELECT products.title, barcode_table.code
FROM products, barcode_table
WHERE products.author = 'Anders Hejlsberg'
ORDER BY products.title ASC;

In this example, only those product titles and their barcodes are sent from the server to the mobile application.

Hopefully these examples help make a case for using a structure database engine of some kind, rather than using a flat file. The specific flavor and implementation of database, however, is another question unto itself.

对岸观火 2024-10-21 09:35:19

一般来说,关系数据库存储在远程服务器上,您可以通过客户端界面访问它们。每个数据库供应商都有安装在远程计算机上的软件,允许您访问服务器上的数据库。执行查询时,整个数据库不会发送回客户端,但如果您不小心构建查询,它可能会发送非常大的结果集。一般来说流程是这样的:

  • 数据库服务器监听客户端连接
  • 客户端连接并发出 SQL
    向数据库发出命令
  • 数据库构建一个查询计划
    弄清楚如何得到结果
  • 计划被执行并得到结果
    被发送回客户端。

CSV 只是一种文件格式,而不是像关系数据库那样功能齐全的平台。

Generally speaking, relational databases are stored on a remote server, and you access them via a client interface. Each database vendor has software that you'd install on your remote computer that would allow you to access the database on a server. The entire DB is not sent back to the client when a query is executed, although it can send very large result sets if you are not careful about how to structure your query. Generally speaking the flow is like this:

  • A database server listens for clients to connect
  • A client connects and issues a SQL
    command to the database
  • The database builds a query plan to
    figure out how to get the result
  • The plan is executed and the results
    are sent back to the client.

CSV is simply a file format, not a fully functional platform like a relational database.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文