sql語句怎麼從一張表中查詢資料插入到另一張表中

2021-10-05 03:11:48 字數 3450 閱讀 5397

1樓:千鋒教育

首先,查詢出來的資料**式要與待插入的另一張表的格式相同,欄位型別相同。

insert into b in 'd:\另一張表所在文件' select * from a where ....

上面就是把從a表中查詢到的資料插入到另一個文件中的b表中。

2樓:匿名使用者

insert into 表a(列1,列2) select 列1,列2 from 表b

3樓:鬱筱羽

標準sql語句格式:

insert

into 表名(欄位名)

select 欄位名

from 表面

例子:將查詢出的s表中sno,j表中jno,p表中pno插入spj表中

insert

into spj(sno,jno,pno)select sno,jno,pno

from s,j,p

sql語句 怎麼從一張表中查詢資料插入到另一張表中

4樓:黑馬程式設計師

以下:1、

insert into a([id], ids, [name], type, time)

select [id], null, [name], 'dd', getdate() from b where type='dd'

2、declare @

num int,@i int;

set @i=0;

set @num=(select 欄位

專 from 表1 where 條件

屬);while @i<@num

begin

set @i=@i+1;

insert into 表2(欄位) select 欄位 from 表1 where 條件;

end;

3、insert into b (column1,datecolumn)

select column1,getdate() from a

sql語句 怎麼從一張表中查詢資料插入到另一張表中

5樓:匿名使用者

查詢的資料bai插入到另一張表中du,分為zhi兩種情況

,一dao種是目標表不存在,專另一種是目屬標表存在。

工具:oracle 10g

源表資料:

情況一(目標表不存在,建立表名為t1的表,將person表中全部資料插入):

執行語句:

create table t1 as select * from person;

情況二(目標表t1存在,將person表中agegrade為年輕人的資料插入):

insert into t1 select * from person where agegrade='年輕人';

6樓:千鋒教育

select into 語句

select into 語句從一個表中選取資料,然後把資料插入另一個表中。

select into 語句常用於建立表版的備份復件或權者用於對記錄進行存檔。

sql select into 語法

把所有的列插入新表:

select *

into new_table_name [in externaldatabase]

from old_tablename

或者只把希望的列插入新表:

select column_name(s)

into new_table_name [in externaldatabase]

from old_tablename

sql語句 怎麼從一張表中查詢資料插入到另一張表中

7樓:育知同創教育

使用insert into 目標表(欄位列表) select 欄位列表 from 原始表

即可實現你所說的功能。

怎麼用一條sql,將一張表中資料插入到兩張表中

8樓:七彩虹科技****

oracle 9i 及以上 可以用insert all insert all into t_table1 (tid, tname) values (object_id, object_name) into t_table2 (tid, tname) values (object_id, object_name) select object_id, object_name, object_type from dba_objects where wner = 'test';

怎麼在oracle資料庫的一張表中新增一另一張表的一個欄位

9樓:千鋒教育

可以通過insert into …… as select 語句來進行實現。

sql:insert into tablename(newname) as select oldname from tablename where 條件語句。

備註:以上語句中插入的欄位順序必須要和查詢的語句的順序保持一致,否則會報錯,如果有條件語句的話,可以增加 where條件。

10樓:莊經略

你是說的新增一個欄位還是插入那個欄位的資料如果是新增欄位

alter table table_name add 欄位 type;

如果是插入資料

insert into table_name as select * from ....

或者是先新增欄位再插入對應的值

那這樣就是用update語句即可

如何用sql語句查詢兩張表中的相同欄位資料

11樓:千鋒教育

select * from 表1 a,表2 b where a.aid=b.bid

有兩張表:表1表2 兩表裡

內一一對應的是aid和bid

a,b分別容

代表:表1,表2 的別名,換句話說a就是表1,b就是表2a.aid 就是:表1的欄位aid

b.bid 就是 : 表2的欄位bid

如何用sql語句查詢兩張表中的相同欄位資料

12樓:千鋒教育

假設表1位table1 ,表2位table2select a.col

from (select column_name col from user_tab_columns where table_name = 'table1') a ,

(select column_name col from user_tab_columns where table_name = 'table2') b

where a.col = b.col

這樣就可以查詢出兩個表得相同欄位了

sql語句從一張表查詢欄位值插入另表中

標準sql語句格式 insert into 表名 欄位名 select 欄位名 from 表面 例子 將查詢出的s表中sno,j表中jno,p表中pno插入spj表中 insert into spj sno,jno,pno select sno,jno,pno from s,j,p insert i...

用SQL查詢語句怎麼讓表中ID按照順序來

這個首先你要寫出你要查詢的內容,如 select name,age from student order by id asc asc 代表升序這也是預設的desc代表降序 select row number over order by id asc as rowno from 表 降序 order ...

mysql資料庫怎麼複製一張表,SQL資料庫中同一張表內資料怎麼複製?

不用匯出,假如你的表111已存在資料庫中,可以很方便的複製 create table 222 as select from 111 create table 222 as select from 111 這樣是能複製全部資料和結構的,但是沒有索引 create table 222 asselect ...