求教INSERT INTO SELECT FROM這語句怎麼用具體的例項謝謝了

2022-03-14 00:20:50 字數 4090 閱讀 9964

1樓:匿名使用者

select into from 和 insert into select都是用來複製表,兩者的主要區別為: select into from 要求目標表不存在,因為在插入時會自動建立。insert into select from 要求目標表存在。

備份表資料: create table emp as select * from scott.emp

還原表資料:insert into emp select * from scott.emp

複製表結構及其資料:

create table table_name_new as select * from table_name_old

只複製表結構:

create table table_name_new as select * from table_name_old where 1=2;

或者:create table table_name_new like table_name_old

只複製表資料:

如果兩個表結構一樣:

insert into table_name_new select * from table_name_old

如果兩個表結構不一樣:

insert into table_name_new(column1,column2...) select column1,column2...

from table_name_old pasting

2樓:匿名使用者

如果兩表欄位相同,則可以直接這樣用。

insert into table_a select * from table_b

如果兩表欄位不同,a表需要b中的某幾個欄位即可,則可以如下使用:

insert into table_a(field_a1,field_a2,field_a3) select field_b1,field_b2,field_b3) from table_b

以上語句前提條件是每個欄位對應的欄位型別相同或可以自動轉換。

sql 關於insert into select from中where的用法

3樓:匿名使用者

這個語句的意思是:從一個表中通過條件查詢出需要的資料之後插入到另外一張表中,進行儲存。

sql:insert into tablename2 (id) as select id from tablename1 where id>5;

解釋:上面語句的意思就是從tablename1中讀取出來id大於5的id欄位,之後插入到tablename2表中(as欄位可以省略)。

備註:查詢表中的欄位結果必須與插入欄位表欄位型別一致。

4樓:千鋒教育

insert into 語句用於向**插入新行insert into 表名稱 values (值1, 值2,....)

我指定所要插入資料列:

insert into table_name (列1, 列2,...) values (值1, 值2,....)

5樓:匿名使用者

insert into b select * from a where not exists(select 1 from b where a.id=b.id)

另外,not in的效率太低,勸樓主不要使用。

6樓:匿名使用者

標準的語法是這樣的:

insert into b

select a.*

from a join b on a.id<>b.id;

7樓:無極園

insert into b

select a.*

from a join b

on a.id=b.id

and a.id is null;

8樓:匿名使用者

試試這樣 where a.id not in (select id from b)

9樓:匿名使用者

insert into b

select * from a

where a.id not in(select idfrom b)

oracle 語句insert into select from 如何用一個sql插入兩個欄位 30

10樓:

select語句查出的兩個值對應的是tablea中的一列b? 好難理解哦

insert tablea a, b, cselect b.x, (select 兩列值 from ...where...

) from tableb b, tablec c where ......

把你的語句調整下吧(select 兩列值 from ...where...) ,這裡的where 跟後面的tableb,c有關聯嗎?

11樓:匿名使用者

這個是可以的

sql:insert into tablename1(filename1,filename2) as select t2.filename1,t2.

filename2 from tablename2 t2 where t2.id>5;

解釋:從tablename2表中找到id大於5的 filenam1欄位和filename2欄位 插入到tablename1表中的filename1欄位和filename2欄位中;除此之外,表tablename1和表tablename2中的欄位型別必須對應。

12樓:匿名使用者

你寫的方法是對的,只不過子查詢 (select 兩列值 from ...where...) 的結果必需是隻有一行,如果出現多行,查詢一下原因,或者加rownum=1條件

sql insert into select from 多條插入多條語句:表a欄位 (編號,字母,名字) 30

13樓:依紅旭

insert a select * from dbo.test_del a,(select number from  master..spt_values where type = 'p' and  number between 1 and 5 ) as b

14樓:知道不知道巨蟹

insert into tablea select 編號,編號b, 名字 from tableb 編號b是tableb的欄位,編號和名字是固定的 比如編號是2,名字是張三

最後應該是

2 1 張三

2 2 張三

2 3 張三

2 4 張三

2 5 張三

oracle語句insert into select如何加後續插入條件

15樓:李鵬飛

a中有3例,b表中你只能獲得2列,可以用常量佔位解決insert into tablea (列1,列2,列3) select 列1,列2,常量 from tableb

例:如下

insert into tablea (列1,列2,列3) select 列1,列2,'123' from tableb 【字串常量】

insert into tablea (列1,列2,列3) select 列1,列2,123 from tableb 【數值常量】

【希望可以幫到你】

16樓:匿名使用者

insert into tablea (列1,列2,『 』)

加個空格不行嗎?

17樓:匿名使用者

那把列3隨便賦個值就行了

mysql insert into select from 其餘欄位怎麼插入

oracle中用insert into select語句和select into from語句插入時如何獲取插入記錄的條數?

18樓:宦文玉暴己

如果是用plsql的話,執行完插入語句,下面的狀態列也會顯然出來插入的條數.

數學思維求教,數學思維 求教!!!!!!!

數學公式肯定是要背得,要背的很熟,特別是數列那塊立體幾何那,要把那些公理記到很熟,熟到什麼程度呢,就是別人一問那題,你就知道要考什麼 怎麼說呢,文科數學,好拿高分,你一定要多做題!多做!做個幾本習題,你的水平就差不多了,對自己要有信心,這比什麼都重要,還有不要急,一點記住不要急躁,每天給自己安排安排...

大神求教excel問題,求教大神,EXCEL問題

資料量大嗎,這個到不需要什麼複雜的公式,使用分列,選擇性貼上,簡單的公式等技巧就可以完成。只不過語言描述不是太方便。這個最好是用vba來處理了,給你一個轉換的辦法,供參考 1 將上述資料複製貼上到工作表1 2 採用 資料 分列 的方法,選擇 分隔符 勾選 空格 和 其他 在 其他 中輸入 按提示點選...

小白求教Matlab初級程式設計,小白求教MATLAB如何定義兩個變數ab,並且讓ab

t 0 0.8 你這裡,如果沒指定步進值,則預設為1的,但是你最終值是0.8,這顯然是不行的,你可以試試t 0 0.01 0.8 q0 10 r 60 l 9 c 0.00005 t 0 0.8 q q0 exp r t 2 l cos t sqrt 1 l c r 2 l 2 plot q,r.x...