Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 使用表值构造函数作为派生表插入1000多行_Sql_Sql Server_Tsql_Derived Table - Fatal编程技术网

Sql 使用表值构造函数作为派生表插入1000多行

Sql 使用表值构造函数作为派生表插入1000多行,sql,sql-server,tsql,derived-table,Sql,Sql Server,Tsql,Derived Table,我有下面的T-SQL查询,它将值列表插入到临时表中。我的问题是INSERT函数被限制为1000行,而我有一个4000行的列表 以下是查询摘要: USE MyDatabase create table #t1 ( ResaID numeric (20) NOT NULL, CtyRes varchar (20) NOT NULL ); INSERT INTO #t1 VALUES ('304475','GB'), ('304482','GB'), ('304857','GB'),

我有下面的T-SQL查询,它将值列表插入到临时表中。我的问题是INSERT函数被限制为1000行,而我有一个4000行的列表

以下是查询摘要:

USE MyDatabase

create table #t1 
( 

ResaID numeric (20) NOT NULL,
CtyRes varchar (20) NOT NULL

); 

INSERT INTO #t1 VALUES

('304475','GB'),
('304482','GB'),
('304857','GB'),
('314643','GB'),
('321711','GB'),
('321714','GB'),
...
…这个名单一直排到第4000行

根据Microsoft文档,使用表值构造函数作为派生表可以绕过此限制

来自Microsoft的示例:


如何修改现有SQL查询以使其适应此示例?

您可以使用以下方法扩展MS示例以处理多个列:

INSERT INTO #t1(ResaID, CtyRes) 
SELECT ResaId, CtyRes
FROM (VALUES 
('304475','GB'),
('304482','GB'),
('304857','GB'),
('314643','GB')) AS sub( ResaId, CtyRes);

你不懂的文档怎么办;它向您展示了如何更改逻辑。这里显示的示例有什么问题吗?-示例2columns@LarnuOP希望将此逻辑扩展到多个列。MS示例演示了如何为单个用户执行此操作one@Larnu我不是说这是错的。在我的例子中,我遇到了一些困难,每行有2个值。@LukaszSzozda感谢链接。正是我需要的。如果你作为答案发表文章,我将据此投票。
INSERT INTO #t1(ResaID, CtyRes) 
SELECT ResaId, CtyRes
FROM (VALUES 
('304475','GB'),
('304482','GB'),
('304857','GB'),
('314643','GB')) AS sub( ResaId, CtyRes);