火星文 技术研习社

Noname Cat, Keep Thinking
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Inserting and Creating Tables Using INSERT/SELECT INTO

Posted on 2006-06-22 09:36  剑廿三  阅读(267)  评论(0)    收藏  举报

INSERT INTO

INSERT INTO allows the output of a SELECT to be used to insert values into an existing table. INSERT INTO table [ ( column [, ...] ) ] SELECT query Example "List of student names": INSERT INTO name_list (name) SELECT name FROM stud; SELECT * from name_list ; name ------ fred tom john lisa (4 rows)


SELECT INTO

SELECT INTO creates a new table and fills it with data computed by a query. The data is not returned to the client, as it is with a normal SELECT. The new table's columns have the names and data types associated with the output columns of the SELECT. SELECT [ ALL | DISTINCT [ ON ( expression [, ...] ) ] ] * | expression [ AS output_name ] [, ...] INTO [ TEMPORARY | TEMP ] [ TABLE ] new_table FROM from_table Example "List of student names": SELECT name AS stud_name INTO name_list FROM stud; SELECT * from name_list ; stud_name ----------- fred tom john lisa (4 rows)