简体   繁体   English

SQL Server的最大大小.SQL文件或变量?

[英]Maximum size of .SQL file or variable for SQL server?

I have a SQL file/SQL string which is about 20MB. 我有一个大约20MB的SQL文件/ SQL字符串。 SQL server simply cannot accept this file. SQL服务器根本无法接受此文件。 Is there a limit on the maximum size of the .SQL file or variable which is used to query or insert data into SQL server ? 用于查询数据或将数据插入SQL服务器的.SQL文件或变量的最大大小是否有限制?

When I say variable, it means passing a variable to SQL server through some programming language or even ETL tool. 当我说变量时,它意味着通过某种编程语言甚至ETL工具将变量传递给SQL服务器。

Yep, I've seen this before. 是的,我以前见过这个。 There is no size limit to .sql files. .sql文件没有大小限制。 It's more about what kind of logic is being executed from within that .sql file. 它更多的是关于在.sql文件中执行什么样的逻辑。 If you have a ton of quick inserts into a small table ex: INSERT INTO myTable (column1) VALUES(1) then you can run thousands of these within one .sql file whereas if you're applying heavy logic in addition to your insert/deletes then you'll have these problems. 如果你有一小部分快速插入到一个小表ex:INSERT INTO myTable(column1)VALUES(1)然后你可以在一个.sql文件中运行数千个这样的文件,而如果你在插入/文件中使用重逻辑删除然后你会遇到这些问题。 The size of the file isn't as important as what's in the file. 文件的大小不如文件中的大小重要。

When we came across these in the past, we ran the .sql files from SQLCMD . 当我们在过去遇到这些时,我们从SQLCMD运行.sql文件。 Very easy to do. 很容易做到。 You could also create a streamreader in C# or vb to read the .sql file and build a query to execute. 您还可以在C#或vb中创建流读取器以读取.sql文件并构建要执行的查询。

SQLCMD: SQLCMD -S [Servername] -E -i [SQL Script]

Was that clear enough? 这够清楚了吗? If you post an example of what you're trying to do then I could write some sample code for you. 如果你发布了一个你想要做的例子,那么我可以为你编写一些示例代码。

When I first experienced this problem, the only solution I found was to split the .sql file into smaller ones. 当我第一次遇到这个问题时,我发现的唯一解决方案是将.sql文件拆分成较小的文件。 That didn't work for our solution but SQLCMD did. 这对我们的解决方案不起作用,但SQLCMD确实如此。 We later implemented a utility that read these large files and executed them with some quick c# programming and a streamreader. 我们后来实现了一个实用程序,它读取这些大文件并使用一些快速的c#编程和一个streamreader来执行它们。

You can use SQLCMD, but I just ran into a 2GB file size limit using that command-line tool. 您可以使用SQLCMD,但我刚刚使用该命令行工具遇到了2GB的文件大小限制。 This was even though I had a GO after every statement. 即使我在每次发言后都有一个GO,这也就是这样。 I get an Incorrect syntax error once the 2GB boundary is crossed. 一旦超过2GB边界,我会收到不正确的语法错误。

After some searching, I found this link: https://connect.microsoft.com/SQLServer/feedback/details/272757/sqlcmd-exe-should-not-have-a-limit-to-the-size-of-file-it-will-process 经过一番搜索,我找到了这个链接: https//connect.microsoft.com/SQLServer/feedback/details/272757/sqlcmd-exe-should-not-have-a-limit-to-the-size-of-file -它意志过程

The linked page above says that every character after 2GB is ignored. 上面的链接页面表示忽略2GB之后的每个字符。 That could explain my Incorrect syntax error. 这可以解释我的错误语法错误。

Size of the SQL file should be limited by memory available on your PC/workstation. SQL文件的大小应受PC /工作站上可用内存的限制。 However, if you don't want to use osql and/or third party tool(s), there is a solution for this in the very SSMS. 但是,如果您不想使用osql和/或第三方工具,那么在SSMS中就有了解决方案。 It's called SQLCMD Mode and it enables you to run a SQL file by referencing it, and not really opening it in editor. 它被称为SQLCMD模式 ,它使您能够通过引用它来运行SQL文件,而不是在编辑器中真正打开它。

Basically, all you have to do is: 基本上,您所要做的就是:

  1. In your Query menu select SQLCMD Mode 在“ Query菜单中,选择“ SQLCMD Mode
  2. Look up the path to your called script (large SQL file) 查找被调用脚本的路径(大型SQL文件)
  3. Open up a New Query (or use existing one) and write this code in a new line 打开一个New Query (或使用现有New Query )并将该代码写入新行

    :r D:\\PathToMyLargeFile\\MyLargeFile.sql

  4. Run that (calling) script 运行该(调用)脚本

If you need to use a variable in your called script, you have to declare it in a calling script. 如果需要在被调用脚本中使用变量 ,则必须在调用脚本中声明它。 Then your calling script should look like this: 然后你的调用脚本应如下所示:

:setvar myVariable "My variable content"
:r D:\PathToMyLargeFile\MyLargeFile.sql

Let's say your called script uses the variable for content that should be inserted into rows. 假设您的被调用脚本将该变量用于应插入行的内容。 Then it should look something like this... 然后它应该看起来像这样......

INSERT INTO MyTable (MyColumn)
SELECT '$(myVariable)'

Pranav was kind of on the right track in referencing the Maximum Capacity Specifications for SQL Server article; Pranav在引用SQL Server最大容量规范文章时走在正确的轨道上; however, the applicable limit to executing queries is: 但是,执行查询的适用限制是:

Length of a string containing SQL statements (batch size) 1 65,536 * Network packet size 包含SQL语句的字符串的长度(批处理大小) 1 65,536 *网络包大小

1 Network Packet Size is the size of the tabular data stream (TDS) packets used to communicate between applications and the relational Database Engine. 1网络数据包大小是用于在应用程序和关系数据库引擎之间进行通信的表格数据流(TDS)数据包的大小。 The default packet size is 4 KB, and is controlled by the network packet size configuration option. 默认数据包大小为4 KB,由网络数据包大小配置选项控制。

Additionally, I have seen problems with large numbers of SQL statements executing in SQL Server Management Studio. 此外,我在SQL Server Management Studio中看到了大量SQL语句的问题。 (See SQL Server does not finish execution of a large batch of SQL statements for a related problem.) Try adding SET NOCOUNT ON to your SQL to prevent sending unnecessary data. (请参阅SQL Server未完成针对相关问题的大批SQL语句的执行 。)尝试将SET NOCOUNT ON添加到SQL以防止发送不必要的数据。 Also, when doing large numbers of INSERT statements, try breaking them into batches using the GO batch separator. 此外,在执行大量INSERT语句时,请尝试使用GO批处理分隔符将它们分批。

I think your concern comes from trying to open your file in SSMS. 我认为您的担忧来自于尝试在SSMS中打开您的文件。 Within SSMS, opening a 20mb file would likely be problematic -- no different than trying to open the same file in Notepad or most text editors. 在SSMS中,打开一个20mb的文件可能会有问题 - 与尝试在记事本或大多数文本编辑器中打开相同的文件没什么不同。

For the record - for other posters - I don't think the questions has anything to do at all with SQL column, table, object, or database sizes! 对于记录 - 对于其他海报 - 我不认为这些问题与SQL列,表,对象或数据库大小有任何关系! It's simply a problem with using the IDE. 这只是使用IDE的一个问题。

If the file is pure data to be imported, with NO sql commands, try bulk import. 如果文件是要导入的纯数据 ,使用NO sql命令,请尝试批量导入。

If the file is SQL commands, you're going to need an editor that can handle large files, like Vedit. 如果文件是SQL命令,那么您将需要一个可以处理大文件的编辑器,例如Vedit。 http://www.vedit.com/ It won't be able to execute the sql. http://www.vedit.com/它将无法执行sql。 You must do that from the command line using sqlcmd as noted above. 您必须使用sqlcmd从命令行执行此操作,如上所述。

这里有几个链接2我希望它们可能对您有所帮助

I came through this article on MSDN which specifies " Maximum Capacity Specifications for SQL Server ", going through this, I was able to find : 我在MSDN上看到了这篇文章,它指定了“ SQL Server的最大容量规范 ”,通过这个,我能够找到:

For Sql Server 2012, 2008 R2, 2005 : 对于Sql Server 2012,2008 R2,2005

Maximum File size (data): 16 terabytes 最大文件大小(数据): 16 TB

Maximum Bytes per varchar(max), varbinary(max), xml, text, or image column: 2^31-1 Bytes (~2048 GB) 每个varchar(max),varbinary(max),xml,text或image列的最大字节数: 2 ^ 31-1 Bytes(~2048 GB)

For more details on Maximum Capacity Specifications for SQL Server, refer: 有关SQL Server最大容量规范的更多详细信息,请参阅:

For SQL Server 2012: http://msdn.microsoft.com/en-us/library/ms143432(v=sql.110).aspx 对于SQL Server 2012: http//msdn.microsoft.com/en-us/library/ms143432(v = sql.110).aspx

For SQL Server 2008 R2: http://msdn.microsoft.com/en-us/library/ms143432(v=sql.105).aspx 对于SQL Server 2008 R2: http//msdn.microsoft.com/en-us/library/ms143432(v = sql.105).aspx

For SQL Server 2005: http://msdn.microsoft.com/en-us/library/ms143432(v=sql.90).aspx 对于SQL Server 2005: http//msdn.microsoft.com/en-us/library/ms143432(v = sql.90).aspx

For Sql server 2000, I am not sure since MSDN seems to have removed related documentation . 对于Sql server 2000,我不确定,因为MSDN似乎已删除相关文档。

It is not clear from your question what the SQL file contains. 从您的问题中不清楚SQL文件包含什么。 The solution I suggest below is only applicable if the SQL file you refer to has only insert statements. 我建议的解决方案仅适用于您引用的SQL文件只有insert语句。

The fastest way to insert large amounts of data into SQL server is to use bulk copy functionality (BCP BCP Utility ) 将大量数据插入SQL Server的最快方法是使用批量复制功能(BCP BCP Utility

If you have SQL Server management studio then you should also have the bcp utlity look in C:\\Program Files (x86)\\Microsoft SQL Server\\90\\Tools\\Binn (or equivalent). 如果您有SQL Server管理工作室,那么您还应该在C:\\ Program Files(x86)\\ Microsoft SQL Server \\ 90 \\ Tools \\ Binn(或等效的)中查看bcp utlity。

If you want to use BCP utility then you would need to create a file that contains the data, this can be comma delimited. 如果要使用BCP实用程序,则需要创建包含数据的文件,这可以用逗号分隔。 Refer to bcp documentation on what the file should look like. 有关文件的外观,请参阅bcp文档。

For Maximum Capacity Specifications for SQL Server , you can check in here. 对于SQL Server的最大容量规范,您可以在此处签到。 http://msdn.microsoft.com/en-us/library/ms143432(v=sql.120).aspx . http://msdn.microsoft.com/en-us/library/ms143432(v=sql.120).aspx

if you ask "Is there a limit on the maximum size of the .SQL file or variable which is used to query or insert data into SQL server ?" 如果你问“用于查询数据或将数据插入SQL服务器的.SQL文件或变量的最大大小是否有限制?” I will say yes there is a limit for each variabel.and if you want upload file with big size, i recommended you convert your file to varbinary or you can increasing the Maximum Upload Size in your sistem web. 我会说是的,每个变量都有一个限制。如果你想要大尺寸的上传文件,我建议你将你的文件转换为varbinary,或者你可以增加你的sistem web中的最大上传大小。 here i give some example http://msdn.microsoft.com/en-us/library/aa479405.aspx 这里我举一些例子http://msdn.microsoft.com/en-us/library/aa479405.aspx

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

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