使用select插入值

时间:2009-08-14 10:12:11

标签: sql syntax select insert

我有两张桌子

create table p
(
  x number,
  y number,
  z number
);


create table q 
(
  a number,
  b number,
  c number,
  d  varchar2(20)
);

我已插入

insert into p values('1','2','3');

现在我需要插入到q中选择p中的值,最后一个字段的名称如表q中的表_name

表q包含

的值
a  b  c  d
1  2  3   table_name

尽快帮助

2 个答案:

答案 0 :(得分:2)

INSERT INTO q(a,b,c,d)SELECT x,y,z,'table_name'FROM p

答案 1 :(得分:0)

CREATE TABLE TestTable (FirstName VARCHAR(100), LastName VARCHAR(100))

INSERT INTO TestTable (FirstName, LastName)
SELECT FirstName, LastName
FROM Person.Contact
WHERE EmailPromotion = 2
SELECT FirstName, LastName
FROM TestTable

DROP TABLE TestTable

http://blog.sqlauthority.com/2007/08/15/sql-server-insert-data-from-one-table-to-another-table-insert-into-select-select-into-table/