简体   繁体   English

SQL Server导出到Excel

[英]SQL Server export to Excel

How to increase performance on exporting a database with tables with one to many relationship (in so case many to many relationship) into a single excel file. 如何提高将具有一对多关系(在这种情况下为多对多关系)的表的数据库导出到单个excel文件中的性能。

Right now, I get all the data from the database and process it into a table using a few for loops, then i change the header of the html file to download it as an excel file. 现在,我从数据库中获取所有数据,并使用一些for循环将其处理到表中,然后更改html文件的标题以将其下载为excel文件。 But it take a while for the number of records i have (about 300 records. ) 但是我要花一些时间(大约300条记录)。

I was just wondering, if there is a faster way to improved performance. 我只是想知道,是否有更快的方法来提高性能。

Thanks 谢谢

It sounds like you're loading each table into memory with your c# code, and then building a flat table by looping through the data. 听起来好像您正在使用c#代码将每个表加载到内存中,然后通过遍历数据来构建平面表。 A vastly simpler and faster way to do that would be to use a SQL query with a few JOINs in it: http://www.w3schools.com/sql/sql_join.asp http://en.wikipedia.org/wiki/Join_(SQL ) 一种更简单,更快捷的方法是使用带有一些JOIN的SQL查询: http : //www.w3schools.com/sql/sql_join.asp http://en.wikipedia.org/wiki/ Join_(SQL

Also, I get the impression that you're rendering the resulting flat table to html, and then saving that as an excel file. 另外,我得到的印象是您将生成的平面表呈现为html,然后将其另存为excel文件。 There are several ways that you can create that excel (or csv) file directly, without having to turn it into an html table first. 您可以通过多种方法直接创建该excel(或csv)文件,而不必先将其转换为html表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM