我想要做这样的事情如何在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