SQL 在 Sybase ASE 中插入多行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24635327/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Inserting Multiple Rows in Sybase ASE
提问by user2436815
(Similar question related to SQL Server : SO Link)
(与 SQL Server 相关的类似问题:SO Link)
I know in Sql Server 2008 or above, you can insert multiple rows doing the following:
我知道在 Sql Server 2008 或更高版本中,您可以插入多行,执行以下操作:
INSERT INTO MyTable (Name, ID)
VALUES ('First',1), ('Second',2), ('Third',3)
However, it seems like this syntax DOES NOT work in Sybase Adaptive Server Enterprise, since this gives me an error..
但是,这种语法似乎在 Sybase Adaptive Server Enterprise 中不起作用,因为这给了我一个错误..
Anyone know the syntax in Sybase that achieves the same thing?
任何人都知道 Sybase 中实现相同功能的语法?
Sybase ASE is based on Transact SQL..
Sybase ASE 基于 Transact SQL..
Thanks
谢谢
回答by Robert
Sybase doen't have insert syntax as SQL Server. What's wrong with showed below classic method?
Sybase 没有 SQL Server 那样的插入语法。下面显示的经典方法有什么问题?
INSERT INTO MyTable (Name, ID) VALUES ('First',1)
INSERT INTO MyTable (Name, ID) VALUES ('Second',2)
INSERT INTO MyTable (Name, ID) VALUES ('Third',3)
go
回答by George Mastros
try this:
尝试这个:
INSERT INTO MyTable (Name, ID)
Select 'First',1
Union All
Select 'Second',2
Union All
Select 'Third',3
I know this works on older versions of SQL server, and suspect that it will work with sybase.
我知道这适用于旧版本的 SQL 服务器,并且怀疑它可以与 sybase 一起使用。
回答by Rahul
Looks like that syntax is not valid in Sybase ASE but as suggested in the linked SO post you can get the same using UNION ALL
like
看起来该语法在 Sybase ASE 中无效,但正如链接的 SO 帖子中所建议的,您可以使用UNION ALL
类似的方法获得相同的结果
INSERT INTO MyTable (Name, ID)
SELECT 'First',1
UNION ALL
SELECT 'Second',2
UNION ALL
SELECT 'Third',3
回答by Subhojeet
The syntax in SQL Server for this example will not work in Sybase. Either go with individual statements, or UNION ALL clause
此示例的 SQL Server 中的语法在 Sybase 中不起作用。要么使用单独的语句,要么使用 UNION ALL 子句