sql怎麼把表的資料插入到另外表

時間 2022-03-02 13:05:24

1樓:小呀麼小鍋巴

語法一般用insert select 你只插1列?一般是整行插入的

sql怎麼將一個表的資料插入到另一個表中

2樓: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中去。

3樓:

不同的資料庫語法不同(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 原表;

4樓:冰悅精彩

您好:參考語句如下

insert into 目標表(欄位1,欄位2,欄位3)select 欄位1,欄位2,欄位3

from 源表

where 條件

5樓:匿名使用者

--複製原不存在表

select * into 新表 from 舊錶--複製原已存在表

insert into 新表(欄位1,欄位2)select 欄位1,欄位2 from 舊錶

6樓:匿名使用者

insert into 【表名a】 select* from 【表名b】

sql語句 怎麼把從一個表中查出來資料插入到另一個表中

7樓:鬱筱羽

標準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

8樓:匿名使用者

查詢的資料插入到另一張表中,分為兩種情況,一種是目標表不存在,另一種是目標表存在。

工具:oracle 10g

源表資料:

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

執行語句:

create table t1 as select * from person;

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

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

9樓:谷歌

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

即可實現你所說的功能。

10樓:shine光明飛

insert into 表a select a,b,c from 表b ;

其中查詢欄位abc需要與表a中的欄位對應。如果不是全表,也可以:

insert into 表a (a,b,c) select a',b',c' from 表b ;

11樓:

很簡單 就是一個

inert into table(col1,col2,…)select col1,col2,… 語句例如:insert into a(id,name) select id,name from emp;

表示從emp表中查詢出來的id,name值 插入到a表的id,name中

12樓:尹巧駿

(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。

13樓:匿名使用者

insert into tablea (col1,col2, col3)

(select tableb.col1, tableb.col2, tableb.col3

from tableb

where ...)

14樓:黑馬程式設計師

以下: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語句 怎麼把一個表的資料複製到另外一個表裡面

15樓:神祕原**

1、複製舊錶的資料到新表(假設兩個表結構一樣)

insert into 新表 select * from 舊錶

2、複製舊錶的資料到新表(假設兩個表結構不一樣)

insert into 新表(欄位1,欄位2,.......) select 欄位1,欄位2,...... from 舊錶

3、複製表結構及資料到新表

select * into 目標表名 from 源表名(要求目標表不存在,因為在插入時會自動建立)

4、只複製表結構到新表

create table 新表 select * from 舊錶 where 1=2 即:讓where條件不成立.

擴充套件資料

基本sql語句

1、資料表的建立

create table 資料表名稱(欄位1 型別1(長度),欄位2 型別2(長度) …… )

2、 資料記錄篩選

sql="select * from 資料表 where欄位名=欄位值 order by欄位名[desc]"

3、更新資料記錄

sql="update 資料表 set欄位名=欄位值 where 條件表示式"

4、刪除資料記錄

sql="delete from 資料表 where 條件表示式"

5、 新增資料記錄

sql="insert into 資料表 (欄位1,欄位2,欄位3 …) values (值1,值2,值3 …)"

16樓:匿名使用者

不同的資料庫語法不同(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 原表;

17樓:匿名使用者

怎麼把一個表的資料複製到另外一個表裡面,是因為這個表的資料快沒用了所以複製

複製到另一個表裡面了。

18樓:深圳市勵拓軟體****

如何把一個表中的資料複製到另一個表中,小剛seo為你解答

複製表結構及資料到新表 select * into 目標表名 from 源表名(要求目標表不存在,因為在插入時會自動建立)

步驟閱讀.2只複製表結構到新表 create table 新表 select * from 舊錶 where 1=2 即:讓where條件不成立.

步驟閱讀.3複製舊錶的資料到新表(假設兩個表結構一樣) insert into 新表 select * from 舊錶

步驟閱讀.4複製舊錶的資料到新表(假設兩個表結構不一樣) insert into 新表(欄位1,欄位2,.......) select 欄位1,欄位2,...... from 舊錶

步驟閱讀.5oracle資料庫也是類似的。

19樓:玉麒麟大魔王

語言怎麼把一個表的資料複製到另一個表裡面呢?複製貼上。

20樓:匿名使用者

如果sql中已經有一張存在的資料表,想複製一張屬於自己的資料表。可以:

create table 新表 as select * from 舊錶;

舉例子:

已經有的**:select * from

student;

(學生表)

複製一張學生表:

create table

student_one as select * from

student;

21樓:匿名使用者

inset into 表 (欄位1,欄位2) select 欄位1,欄位2 from 表2

22樓:匿名使用者

說清楚一點,是將一張表的內容更新為另一張還是插入到另一張,如果是更新到則用update..set

插入的話用insert ..into

23樓:匿名使用者

insert into tablename1 values(select * from tablename2)

sql怎樣把一個表的資料插入到另一個表裡?

24樓:

只插入id,title,content的值:insert into b(id,title,content) select id,title,content from a

插入b中並填寫b的所有欄位:insert into b select id,title,content,'adder的值','n_time的預設值' from a

25樓:愛笑的暖言兒

複製表結構及資料到新表 select * into 目標表名 from 源表名

只複製表結構到新表 create table 新表 select * from 舊錶 where 1=2 即:讓where條件不成立.

複製舊錶的資料到新表(假設兩個表結構一樣) insert into 新表 select * from 舊錶

複製舊錶的資料到新表(假設兩個表結構不一樣) insert into 新表(欄位1,欄位2,) select 欄位1,欄位2, from 舊錶

oracle資料庫也是類似的。

將資料庫a中某表的的某列欄位,更新到資料庫b中某表的某列欄位:(use master 資料庫)

update a

set a.name=b.name

from temp1.dbo.tablea a,temp2.dbo.tablea b

where a.id=b.id

sql問題從檢視獲取資料並插入到新表中非臨

因為我實在有點弄不懂你下面的補充,所以就回答一下操作方法,希望會對你有所幫助 1 從一個檢視獲取資料並存入一個新表中 表原先不存在 select 要獲取的資料 from 檢視名 where 條件 條件可要可不要 into table 表名 2 從一個檢視獲取資料並插入一個新表中 表原先已存在 要先把...

sql資料庫怎麼將A表的資料匯入到B表

糖糖寳寳 首先要保證的是b庫的testtableb1 表結構和a庫的testtablea1 表結構相同.set identity insert databaseb.dbo.testtableb1 on 匯入前開啟identity insert為on insert databaseb.dbo.test...

sql中如何把資料庫中幾個表的資料匯入到另資料庫中的表

insert into ddd 欄位1,欄位2,欄位3 select 欄位1,欄位2,欄位3 from aaa,bbb,ccc 插入的欄位和查詢的欄位數量型別一致 由於你的誇庫查詢插入 所以在表名前加 庫名.使用者名稱 insert into b.使用者.ddd 欄位1,欄位2,欄位3 select...