請問sql批量插入資料怎麼寫除了一條一條插入和

時間 2021-08-11 18:10:17

1樓:老k的財務自由之路

圖顯ip:

暈,為什麼要除insert into table1 select * from table2,最快就這個了,考試,規定不能用?

2樓:

如果id設定了自動遞增

insert into table1 (name) select name from table2

如果id沒設成標識自動遞增

declare @i int,@name varchar(200)set @i=1

declare test cursor forselect name from table2open test

fetch next from test into @namewhile @@fetch_status = 0begin

insert into a(id,nam) select @i,@name

set @i=@i+1

fetch next from test into @nameendclose test

deallocate test

3樓:

要實現自增長,先要建立sequence sequence_test

然後執行 insert into table1 select sequence_test.nextval , name from table2

4樓:匿名使用者

你用的是什麼資料庫?

5樓:匿名使用者

那就是 使用工具, 提取 外部的 txt 檔案, 匯入到目標表。

具體情況,要看你的資料庫是什麼。

至於你的

表a欄位:id name

問題:現在有好多個name 要插入,id自動遞增,一般來說。

就是insert into table1 ( name ) select name from table2

應該是可以的。

資料庫出了問題用insert into table select * from temp,這條語句插入資料偶爾很快,2min就搞定

6樓:匿名使用者

是不是insert進去的表有觸發器,看下可能是觸發器的sql造成的

7樓:匿名使用者

是否table中本來就有資料?如果本來就有很多資料,並且有主鍵,還有索引的話,速度可能就會慢。如果是偶爾快偶爾慢,那就要看看慢的時候表是否在鎖死狀態或者其他狀態。

怎樣用SQL向資料庫中批量的插入資料,主鍵是隨機生成的

使用資料型別uniqueidentifier最合適了 建立表 create table a tmp primary id uniqueidentifier not null col1 varchar 10 collate chinese prc ci as null,col2 varchar 10 ...

在資料表中新增欄位的sql語句怎麼寫

資料表中新增一個欄位的標準sql語句寫法為 alter table 表名 add 欄位 欄位型別 default 輸入預設值 null not null 舉例 alter table employee add spbh varchar 20 not null default 0 意思就是在表empl...

SQL重複資料只顯示一條,查詢語句怎麼寫

吳佳航 sql重複資料只顯示一條,查詢語句編碼的寫法是 如果是所有欄位都重複,使用 distinct。如果部分欄位重複,只能使用group by 或是其他的方法。結構化查詢語言 structured query language 簡稱sql 發音 es kju el s q l 是一種特殊目的的程式...