使用 SQL Server 2000 插入多个值时出现问题
我有以下插入语句,该语句在运行 SQL Server 2008 的系统上运行良好,但我在运行 SQL Server 2000 的系统上尝试了同样的操作,但它给出了错误...
是否有一个简单的解决方案,因为我有超过 3000 条记录插入,我不想一次只做一个!
INSERT INTO uk_postcodes (outcode, lat, lng)
VALUES ('AB12', '57.098381', '-2.172400'),('AB13', '57.108', '-2.237')
I have the following insert statement which works fine on one system running SQL Server 2008 but I've tried the same thing on a system running 2000 and it gives an error...
Is there an easy fix for this since I have over 3000 records to insert and I don't want to have to do them all one at a time!
INSERT INTO uk_postcodes (outcode, lat, lng)
VALUES ('AB12', '57.098381', '-2.172400'),('AB13', '57.108', '-2.237')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
使用 SQL Server 2000,有两种方法可以做到这一点 -
一种是
第二种方法是使用 UNION ALL -
Using SQL server 2000, there are two ways to do this -
one is
Second way is using UNION ALL-
通过一些字符串替换,您将能够将脚本转换为以下应该可以工作的内容:
With a bit of string replacing you will be able to convert the script into the following which should work:
这两个答案都会起作用。欲了解更多信息:
http://en.wikipedia.org/wiki/Insert_(SQL) )
ANSI SQL-92 添加了多记录插入语法,使用逗号分隔 VALUES,这正是您尝试使用的。特别是对于 SQL-Server,自 2008 版本以来添加了对此语法的支持
为了速度,过长的字符串会出现一些问题,因此使用该
表单,但在大约 100 或 1000 条记录后中断并开始另一个 INSERT。
* 表值构造函数不仅限于 INSERT 语句。 SQL Server 2008 更进一步,允许定义
<派生表>
,例如Both answers give will work. For more information:
http://en.wikipedia.org/wiki/Insert_(SQL)
ANSI SQL-92 added the multi-records insert syntax, separating VALUES using comma, which is what you are trying to use. For SQL-Server specifically, support for this syntax was added since version 2008.
For speed, there are some issues with overly long strings, so use the
form, but break and start another INSERT after about 100 or 1000 records.
* table value constructors are not limited to the INSERT statement only. SQL Server 2008 goes one further to allow it to define a
<derived table>
, e.g.假设您的所有数据都是这样,请尝试将所有 "),(" 替换为 ");INSERT INTO uk_postcodes (outcode, lat, lng) VALUES ("
Assuming that you all your data is like that try replacing all "),(" with ");INSERT INTO uk_postcodes (outcode, lat, lng) VALUES ("