我想要做這樣的事情如何在MS SQL Server中插入子查詢的內容?
insert into my table (select * from anothertable where id < 5)
什麼是正確的語法MSSQL?
謝謝!
我想要做這樣的事情如何在MS SQL Server中插入子查詢的內容?
insert into my table (select * from anothertable where id < 5)
什麼是正確的語法MSSQL?
謝謝!
這是你在找什麼?
INSERT INTO MyTable
SELECT * FROM AnotherTable
WHERE AnotherTable.ID < 5
該語法看起來正確,但您的字段必須完全匹配,否則將無法正常工作。
您可以指定字段,例如:
INSERT INTO myTable(COL1, COL2, COL3)
SELECT COL1, COL2, COL3 FROM anotherTable where anotherTable.id < 5
Insert Into MyTable ( Col1, Col2, Col3 ) Select Col1, Col2, Col3 From AnotherTable Where ID < 5
你也可以做
select *
into MyTable
from AnotherTable
where ID < 5
,這將創造MyTable的與所需的列,以及填補數據
太好了。 正如其他人所提到的,您需要確保從AnotherTable中選擇的列與MyTable中的列匹配。 – 2008-10-21 19:52:53