使用select into 語句

2021-04-13 05:10:59 字數 1048 閱讀 6873

在新建臨時表時,如果一次性插入資料量很大,那麼可以使用select into代替create table,
避免log,提高速度;如果資料量不大,為了緩和系統表的資源,建議先create table,然後insert。
語法:

select column_name(s) into newtable [in externaldatabase]

from source

下面的示例製作乙個"persons" 表的備份。

select * into persons_backup

from persons

in子句可用於複製表到另乙個資料庫。

select persons.* into persons in 'backup.mdb'

from persons

如果你只希望複製一些字段,你也可以在select語句後列出字段清單。

select lastname,firstname into persons_backup

from persons

你也可以新增乙個子句。下面的示例通過從"persons" 表篩選居住於 "sandnes" 的人,用兩列 (firstname and lastname) 建立乙個"persons_backup"

select lastname,firstname into persons_backup

from persons

where city='sandnes'

從多於乙個表選擇資料也是可能的。下面的示例建立乙個包含employees和orders兩個表資料的新錶 "empl_ord_backup"。

select employees.name,orders.product

into empl_ord_backup

from employees

inner join orders

on employees.employee_id=orders.employee_id

select into語句的應用技巧

select into語句的應用技巧 1.將乙個資料表的結構複製到乙個新表上,但是不移動記錄 select into newtable from dbo.inventorywhere 1 1 2.select into 語句建立乙個新錶 並用select 的結果集填充該錶 例1select ship...

儲存過程中SELECT INTO的使用

在mysql儲存過程中使用select into語句為變數賦值 用來將查詢返回的一行的各個列值儲存到區域性變數中。要求 查詢的結果集中只能有1行。select col name into var name table expr 使用select into語句在資料庫中進行查詢,並將得到的結果賦值給變...

儲存過程中SELECT INTO的使用

在mysql儲存過程中使用select into語句為變數賦值 用來將查詢返回的一行的各個列值儲存到區域性變數中。查詢的結果集中只能有1行。select col name into var name table expr使用select into語句在資料庫中進行查詢,並將得到的結果賦值給變數。co...