1樓:寶貝程珍
你好,下面這個是oracle的語法,其他資料庫估計大同小異insert into a as select * from abak;
如果不行的話把as去掉試試,好久沒用,記不太清楚了希望能解決你的問題。
2樓:
假設你有3個字段,主鍵a
select a,b,c from abakunion all
select a,b,c
from abak as t
left join 目標表 as p on t.a=p.awhere p.a is null
sql怎麼將乙個表的資料插入到另乙個表中
3樓:ff酒後少女的夢
在hh中列出要插入列的列表跟select from mm表中的選擇的列的列表一一對應就可以了,當然兩邊的資料型別應該是相容的。
1、insert into hh (fielda,fieldb,fieldc) select fieldx,fieldy,fieldz from mm
2、聲名:a,b ,都是表 。
3、若兩表只是有部分(字段)相同。
4、把錶a插入到表b中去。
4樓:
不同的資料庫語法不同(sql server和oracle為例),且複製包括目標表已存在和目標表不存在的情況,分別回答:
sql server中,如果目標表存在:
insert into 目標表 select * from 原表;
sql server中,,如果目標表不存在:
select * into 目標表 from 原表;
oracle中,如果目標表存在:
insert into 目標表 select * from 原表;
commit;
oracle中,如果目標表不存在:
create table 目標表 as select * from 原表;
5樓:冰悅精彩
您好:參考語句如下
insert into 目標表(欄位1,欄位2,欄位3)select 欄位1,欄位2,欄位3
from 源表
where 條件
6樓:匿名使用者
--複製原不存在表
select * into 新錶 from 舊表--複製原已存在表
insert into 新錶(欄位1,欄位2)select 欄位1,欄位2 from 舊表
7樓:匿名使用者
insert into 【表名a】 select* from 【表名b】
資料庫從一張表向另一張表怎麼插入資料
8樓:千鋒教育
下面以mysql資料庫為例分情況一一說明:
兩張表:inserttest和inserttest2,前者中有測試資料:
1.如果2張表的字段一致,並且希望插入全部資料,可以用這種方法:
insert into 目標表 select * from **表;
insert into inserttest select * from inserttest2;
2.如果只希望匯入指定字段,可以用這種方法:
insert into 目標表 (欄位1, 欄位2, ...) select 欄位1, 欄位2, ... from **表;
注意欄位的順序必須一致。
insert into inserttest2(id) select id from inserttest2;
3.如果您需要只匯入目標表中不存在的記錄,可以使用這種方法:
insert into 目標表
(欄位1, 欄位2, ...)
select 欄位1, 欄位2, ...
from **表
where not exists (select * from 目標表
where 目標表.比較字段 = **表.比較字段);
1>.插入多條記錄:
insert into inserttest2
(id,name)
select id,name
from inserttest
where not exists (select * from inserttest2
where inserttest2.id=inserttest.id);
2>.插入一條記錄:
insert into inserttest
(id, name)
select 100, 'liudehua'
from dual
where not exists (select * from inserttest
where inserttest.id = 100);
9樓:賓士
"insert into stocksale(cardid,pcode,pname,price,pnum) select" +cardid.text+"," +pcode.text+"," +pnum.
text+",pname,price,pnum from 表2"
---以上,希望對你有所幫助。
10樓:匿名使用者
以pcode為查詢條件,先從另乙個表中將你要的資料取出,取放入你的insert 語句就可以了。
從資料結構 上看,你的2個表設計 有問題的
sqlserver將一張表的資料全部匯入到另一張表應該怎麼寫?
11樓:匿名使用者
有兩種寫法
1.insert into select語句
語句形式為:insert into table2(field1,field2,...) select value1,value2,... from table1
要求目標表table2必須存在,由於目標表table2已經存在,所以我們除了插入源表table1的字段外,還可以插入常量。
2.select into from語句
語句形式為:select vale1, value2 into table2 from table1
要求目標表table2不存在,因為在插入時會自動建立表table2,並將table1中指定字段資料複製到table2中。
12樓:匿名使用者
1 兩張表多存在實體,兩表的字段相同,欄位的順序相同的話。
insert into 表b select * from 表a2 兩張表多存在實體,兩表的字段相同,欄位的順序不相同的話。
表b欄位
insert into 表b ( f1,f2,f3) select f1,f2,f3 from 表a
總之要對應使用
13樓:
1、生成原來表的sql,在sql server management studio中操作,只有這樣才可以保證表結構,無論你怎麼select into都只能帶過來欄位等資訊,無法帶來約束
tips:直接在選中表,按ctrl+c複製,然後在查詢視窗中ctrl+v就可以得到生成表的sql,記得改下表名再create
2、如果有自增列,先設定允許更新
3、insert into xx select * from yy where或者其他任何辦法都成(資料匯入匯出其實蠻實用的)
順便:2008裡有表複製,不知道05裡有沒有
再鑽個牛角尖:如果有其他表從這個表引用了外來鍵,你怎麼把結構再複製乙份啊?因為那個外來鍵不可能關聯到兩個父表,哈哈
14樓:匿名使用者
中文說明是這樣 插入到新錶從指定表(表的字段跟結構都相同)
inset into 新錶 select * from 指定表;
15樓:
insert into tabb
select * from taba
16樓:墮天之翼
insert into b
select * from a
如果沒有那個表,你想建立乙個表結構一模一樣的,可以select * into b from a
17樓:
select * into newtable from oldtable
(newtable :新錶名 oldtable:有資料的表名)
這種方式叫投影
18樓:情感勵志語錄小白
insert into table2(field1,field2,...) select value1,value2,... from table1
table2必須存在
filed1對應value1
filed2對應value2
。。。。
資料型別也必須對應相同
19樓:古本三
select tablea.欄位名....
into tableb
from tablea.
兩個表的字段都是一樣。
20樓:匿名使用者
可以看下 sql自帶的 匯入匯出
21樓:匿名使用者
insert into b select from a
22樓:匿名使用者
select * into 表a from 表b
23樓:風影技師
select into table_a from table_b
24樓:sd陣風
應該是樓上所說的那樣。。我經常用二樓的的寫法。
sql語句 怎麼把從乙個表中查出來資料插入到另乙個表中
25樓:鬱筱羽
標準sql語句
bai格式:
insert
into 表名(
du欄位zhi
名)select 欄位名
from 表面
例子:dao將內查詢出的s表中容sno,j表中jno,p表中pno插入spj表中
insert
into spj(sno,jno,pno)select sno,jno,pno
from s,j,p
26樓:sql的藝術
insert into table2 (col1,col2,col3)
select col1,col2,col3 from table1
記得插入表的列數要與查詢結果列數一致,並且資料格式也需一致
27樓:育知同創教育
使用insert into 目標表(字段列表) select 字段列表 from 原始表
即可實現你所說的功能。
28樓:匿名使用者
你要查什麼資料據?算了,我這是巢狀語句,你看著往裡面換字段就可以了
insert into 表(select 條件 from 表)
29樓:
很簡單 就是一bai個du
inert into table(col1,col2,…)select col1,col2,… 語句例如:insert into a(id,name) select id,name from emp;
表示zhi從emp表中查dao
詢出來的
id,name值專 插入到屬a表的id,name中
30樓:尹巧駿
(1).select * into desttbl from srctbl
(2).insert into desttbl(fld1, fld2) select fld1, 5 from srctbl
以上兩句都是將 srctbl 的資料插入到 desttbl,但兩句又有區別的:
第一句(select into from)要求目內標表(desttbl)不存在,因容為在插入時會自動建立。
第二句(insert into select from)要求目標表(desttbl)存在,由於目標表已經存在,所以我們除了插入源表(srctbl)的字段外,還可以插入常量,如例中的:5。
如何將EXCEL多張表彙總到一張表裡。見圖,要求使用公式
假入姓名那列在a列,表一中語文對應的那列是b列,數學那列是c列,彙總表中李明對應的總分那公式為 sumif 限於表一的所有a列,李明 限於表一的所有b列 sumif 限於表一的所有a列,李明 限於表一的所有c列 sumif 去選定姓名列,李明 去選定語文列 將excel 多張表 彙總到一張表裡,方法...
如何將一張表中查詢出來的資料複製到另一張表oracle
insert into gl acc item select from gl acc item20100706 t where t.fiscal 2010 and t.acc item code acc item5 and length t.gl item code 1 and t.gl item ...
如何將oracle中其中一張表的資料行匯出到ecel中
無法直接儲存到excel中,但是可以儲存到csv檔案,同樣是excel的格式,方法如下 譬如要把檔案生成在d盤下的test目錄下 1,在d盤根目錄下新建test目錄 2,sqlplus以system用sysdba登入 3,create or replace directory tmp as d te...
如何將華為手機的備份到電腦,如何將華為手機的資料備份到電腦
華為手機可以通過新增到收藏夾來備份,步驟如下 1 開啟簡訊介面 2 開啟需要備份的重要資訊 3 點選右上角更多標籤,選擇 收藏資訊 這樣你的資訊就已經備份在收藏夾了,刪除了簡訊,收藏夾中依然能夠查閱。怎麼把華為手機的所有資料備份到電腦 用魔樂手機助手等軟體,可以備份簡訊。聯絡歷史和 簿!1 開啟簡訊...
在EXCEL中如何將一張表中一列的資料(其中有重複的資料)在另外一張表中的某列中將其不重複的顯現出來
如圖b1 if countif a 1 a1,a1 1,a1 下拉選定b列 f5 定位條件 公式 邏輯值 確定 右擊選定單元格 刪除 下方單元格上移 確定 2003 可用高階篩選 勾選 選擇不重複的記錄。將結果儲存到當前工作表,然後再複製貼上到新錶中。2007及以上版本 複製原工作表 選中該列 資料...