如何用SQL語句將資料批量插入資料庫

時間 2022-07-21 00:13:53

1樓:帶我信樂

你的文件是什麼型別還是表?

如果是表,直接插

insert into 要插表(對應欄位1,對應欄位2,對應欄位3)select 欄位1,欄位2,欄位3

from 文件

如果文件不是表,而是其他型別的,先把資料放到excel,同過excel匯入資料庫

再通過上面的方式插入吧

2樓:匿名使用者

把這些資料放到excel表中,然後再用excel匯入到資料庫

3樓:匿名使用者

sql server 可以用bulk insert 速度超快

具體用法參考:

4樓:倪榮庫蘭澤

批量增加資料,能再具體點嗎,具體問題的處理方式不同,如果要從一張表中取資料,增加到另一張表中,那直接

insert

tablea

select

column1,column2....fromtableb

where

......(where條件根據實際需要)這樣就可以實現批量插資料

insert

tablea(column1,column2....)values(a,b,c,...)這種只能一次插一條如果還複雜點的話,也可以用迴圈來做。

5樓:星珧厲涵易

這種情況使用xml來進行批量插入.

1.asp.net頁面上抓取資料,轉換成xml字串2.將這個字串作為引數傳給儲存過程

3.儲存過程裡,將這個xml讀取成臨時表

4.整個臨時表插入到目標資料表中,這個過程可以使用sqlserver的事務;其實在這裡用不用事務問題都不大了,因為儲存過程出錯,資料插不進去的,還會丟擲異常到asp.net後台,讓後台進行處理異常.

您用游標或asp.net**來迴圈,速度會比較慢的.

6樓:匿名使用者

jdbc迴圈語句,夠詳細了吧

sql資料庫批量新增資料

7樓:匿名使用者

一、針對批量插入資料,如果量不是太多,可以多條sql語句執行就可以了,

類似下面的語句,當然可以使用excel 編輯後,複製到查詢器中執行,

insert into table(a,b) values('1','a')

insert into table(a,b) values('2','b')

insert into table(a,b) values('3','c')

二、大量數批量插入,即資料表的移植,資料備份轉換之類的,就需要工具,比如mssql的dts工具,pb的資料通道 等等。這裡介紹一下 dts工具。

1、在sql安裝目錄下開啟匯入和匯出資料,即dts。

2、選擇乙個批量的資料,可以是表,也可以是帶分隔符的檔案,或excel文件之類,如圖中選擇,匯入的格式

3、選擇匯入的目標

4、選擇匯入方式

5.具體的匯入規則

8樓:鄞臨婁溶溶

下面的**已驗證過,直接在查詢分析器裡執行就可以了create

table#1(

time

datetime

)--select

*from

#1declare

@iint,@starttime

datetime

select@i=

0,@starttime

='2010-3-17

8:30:00'

while

@i<3begin

insert

into

#1values(dateadd(dd,@i,@starttime))

set@i=@i+1

endselect

*from

#1drop

table#1

9樓:酒濃侍星暉

在表上做乙個觸發器。假設id是表的主鍵,t_time時間字段,tb_name表名

declare

@idint

declare

@nint

declare

@tdatetime

select

@id=id,@t=t_time

from

inserted

select

@n=count(*)

from

tb_name

if@n=0

begin

select

@t=max(t_time)

from

tb_name

endupdate

tb_name

sett_time

=dateadd(dd,1,@t)

whereid=

@id插入的時候一條一條插入就可以了

10樓:匿名使用者

沒有原始記錄的情況下。必須手輸入。。

我們一般在excel表上輸入。。格式和資料庫表一樣。

完了。用sql的匯入嚮導匯入。。

在excel上輸入可以自由弄格式。。。。

沒有原始記錄是什麼辦法都沒有了。只有在excel上做快一點。

補充::

有**就好辦法。

【開始】-》【程式】->microsoft sql server-》匯入和匯入資料-》資料來源為excel表。目的就是sql的表

11樓:

insert biao select * from anotherbiao

資料庫中我想要批量插入資料sql語句怎麼寫。

12樓:雪天看海

用sql語句即可實現,例項如下:

insert into `ad` (`id`, `title`, `type_id`, `source`, `remark`, `pic`, `pic1`, `content`, `filepath`, `in_date`, `if_zhiding`, `hit_count`, `ad_type`, `imgurl`) values

(1, '頻道頁保健學堂

(2, '頻道頁養生長壽

13樓:匿名使用者

for迴圈

不知道你用什麼語言

如何往sql資料庫中快速插入大量資料

14樓:匿名使用者

是的,只要你建了對應的序列

不僅可以自動加1,加2加3都行

看你的資料資料級了,如果是海量資料。你可以建臨時表來做資料的插入,如果果資料不多就直接插入好了

15樓:

有declare語句是可以的

比如建立了乙個表a:

create table a

( aid int identity(1,1) not null primary(key),

adata int)

插入資料:

declare @n int

set @n = 0

while @n < 2000

begin

set @n = @n+1

insert into a(adata) values(@n)end

自己改改就可以了

16樓:突擊手覓患

能說具體些嗎?你的資料來源是什麼?

如何在資料庫中批量插入資料

17樓:匿名使用者

你可以將兩個日期之前的天數求出來,然後作為控制迴圈的次數,然後定義個起始日期,迴圈裡對這個日期進行遞增。

像下面這樣 :

declare

v_date date;

v_days number;

v_date_begin date;

v_date_end date;

begin

v_date_begin := to_date('20101101',

'yyyymmdd');

v_date_end := to_date('20100301',

'yyyymmdd');

v_days := v_date_end - v_date_begin;

for i in 1 .. v_days

loop

v_date := v_date_begin + i;

insert into tablename values (v_days) ;

end loop;

end;

18樓:跳動的葉綠素

應該使用insert into語句,我也是菜鳥一枚,只知道這麼多咯

如何用sql語句查詢excel資料

在通過ado對excel物件進行連線時 此時excel則認為是乙個資料來源 需要配置對excel資料來源對應的連線串,這個連線串中包括了provider資訊 其實類似對資料庫進行連線操作時,都需要指定連線字串 以下是一行連線串源 strconnstring provider microsoft.ac...

如何用SQL迴圈查詢語句,如何用SQL語句查詢Excel資料

declare i int select i 304 while i 600 你要查詢的最大分數 begin exec select 學校 學校名稱,count as 人數,304 305 as 總成績 from cjd where 總成績 convert varchar 5 i and 總成績 c...

如何用sql語句將銷量排名前十的商品查詢出來

假設訂單明細表orderdetails的結構如下 create table orderdetails order id char 10 not null foreign key references orders order id p id char 10 not null foreign key ...

如何使用sql語句建立資料庫,用sql語句建立資料庫

1 使用create database語句建立資料庫最簡單的方式,該方式只需要指定database name引數即可,該引數表示要建立的資料庫的名稱,其他與資料庫有關的選項都採用系統的預設值。2 如果希望在建立資料庫時明確指定資料庫的檔案和這些檔案的大小以及增長的方式,就需要了解create dat...

如何用SQL語句刪除check約束

刪除約束的語法如下 alter table 表名 drop constraint 約束名 附加 在建立表的時候同時新增約束的寫法 use studb goif exists select from sysobjects where name stuinfo drop table stuinfo go...