Inserting Multiple Rows in Sybase ASE

牧云@^-^@ 提交于 2019-12-01 17:39:42

问题


(Similar question related to SQL Server : SO Link)

I know in Sql Server 2008 or above, you can insert multiple rows doing the following:

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..

Anyone know the syntax in Sybase that achieves the same thing?

Sybase ASE is based on Transact SQL..

Thanks


回答1:


Sybase doen't have insert syntax as SQL Server. What's wrong with showed below classic method?

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



回答2:


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.




回答3:


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

INSERT INTO MyTable (Name, ID)
SELECT 'First',1
UNION ALL
SELECT 'Second',2
UNION ALL
SELECT 'Third',3



回答4:


The syntax in SQL Server for this example will not work in Sybase. Either go with individual statements, or UNION ALL clause



来源:https://stackoverflow.com/questions/24635327/inserting-multiple-rows-in-sybase-ase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!