2014-07-08 166 views
4

(類似問題涉及到SQL Server:SO Link插入在Sybase ASE多行

我知道在SQL Server 2008或以上,你可以插入多行執行以下操作:

INSERT INTO MyTable (Name, ID) 
VALUES ('First',1), ('Second',2), ('Third',3) 

然而,看起來這種語法在Sybase Adaptive Server Enterprise中不起作用,因爲這給了我一個錯誤..

任何人都知道Sybase中實現相同目標的語法嗎?

的Sybase ASE是基於事務處理SQL ..

感謝

回答

2

試試這個:

INSERT INTO MyTable (Name, ID) 
Select 'First',1 
Union All 
Select 'Second',2 
Union All 
Select 'Third',3 

我知道這工作在舊版本的SQL Server,並懷疑它會與合作SYBASE。

+0

這個工作,並且它可以與參數化的值一起工作:... select?,? union all ... – Joel

2

貌似這種語法是不是在Sybase ASE的有效,但在建議的鏈接SO後你可以使用UNION ALL同樣喜歡

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

的Sybase doen't有INSERT語法的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 
+0

什麼是「錯誤」或者更好的不方便是你必須不斷重複INSERT INTO MyTable(Name,ID)VALUES' – broetchen

+0

這對我的Sybase版本不起作用。 – Joel

+0

@Joel你的Sybase版本是什麼? – Parado