sql資料庫批量新增資料,SQL資料庫批量新增資料

時間 2022-07-19 18:22:13

1樓:匿名使用者

一、針對批量插入資料,如果量不是太多,可以多條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.具體的匯入規則

2樓:鄞臨婁溶溶

下面的**已驗證過,直接在查詢分析器裡執行就可以了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

3樓:酒濃侍星暉

在表上做乙個觸發器。假設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插入的時候一條一條插入就可以了

4樓:匿名使用者

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

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

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

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

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

補充::

有**就好辦法。

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

5樓:

insert biao select * from anotherbiao

sql資料庫 如何快速修改一列所有的資料

6樓:

更新update語句分為三部分:更新的表、列名和新的值、確定更新哪些行的過濾條件。

如果是整列修改的話,不用加任何條件。假設要將所有學生的成績都改為及格,sql語句要這麼寫:update 成績表 set 成績='及格'

如果只是修改部分資料,要加上條件。假設要將jason和annie的成績改為及格,sql語句要這麼寫:update 成績表 set 成績='及格' where 姓名 in ('jason','annie')

7樓:匿名使用者

update [user] set money=0修改user表下,所有的money欄位為0update [userse] set seq=10如果seq欄位為非數字型請用

update [userse] set seq='10'

8樓:匿名使用者

開啟 查詢分析器,開啟相應的資料庫,開啟編寫sql的視窗,寫一段sql語句,

update userse set seq = 10

或update userse set seq = '10'

9樓:似明珠

如果自己做不好 就去找專業人士去做吧 很靠譜

10樓:匿名使用者

update userse set seq=10

11樓:匿名使用者

update userse set seq=10 where seq=1

12樓:犀利的胡茬子

update [userse] set seq=10 where [seq] = 1

只有是1的才會變成10

如何向乙個sql sever 資料庫表中插入大量資料?

13樓:

一次性插入大量資料,只能使用迴圈,

如:游標,while 迴圈語句

下面介紹while 迴圈插入資料,

sql **如下:

if object_id('dbo.nums') is not null

drop table dbo.nums;

gocreate table dbo.nums(n int not null primary key);

declare @max as int, @rc as int;

set @max = 5000000;

set @rc = 1;

insert into nums values(1);

while @rc * 2 <= @max

begin

insert into dbo.nums select n + @rc from dbo.nums;

set @rc = @rc * 2;

endinsert into dbo.nums select n + @rc from dbo.nums where n + @rc <= @max;

--以上函式取自inside sql server 2005: t-sql query一書。

insert dbo.sample select n, rand(cast(newid() as binary(16))) from nums

14樓:開拓寂寞

declare @datese datetimeset @datese='2012-06-04 00:00:000'

while @datese<'2012-06-18 23:59:59:000'

begin

set @datese=dateadd(s,3,@datese)insert into 你的表名 values([nodeaddr]的值,@datese,[flag_comm],……,[expand20]的值

) end

就這樣,直接把表名一改執行

如何將excel資料批量匯入sql資料庫

15樓:匿名使用者

把excel資料匯入到sql資料庫中:

1、在資料庫上點選右鍵,然後選擇「任務」,選擇「匯入資料」,就看到彈出淡入資料的對話方塊

2、excel 上面的字段命名最好跟要匯入到最終的那個表的字段相同。假設終表為a表。組裝好 如下圖:

3、按照操作步驟走下去,最終會生成乙個新的表(臨時表b表)。

可以借助工具,mssql表資料匯出成insert語句的工具 即:將查詢出來的這些資料都生成insert into語句。

最終在a表中執行該insert into語句就可以將excel中的資料最終放入資料庫中。

求sql怎麼一次用insert 新增多條資料

16樓:匿名使用者

--一條insert只能插入一行資料,除非你有乙個相同資料型別的表需要複製表資料批量插入可以使用

insert into table2(field1,field2,...) select value1,value2,... from table1

--要求目標表table2必須存在,由於目標表table2已經存在,所以我們除了插入源表table1的字段外,還可以插入常量。

17樓:匿名使用者

使用insert into select 格式

前提是 你要新增的資料是可以通過select 查詢出來的

18樓:考拉的小小鋪

寫迴圈或insert table values(..)select ..from table2

19樓:匿名使用者

例如insert into table(col1,col2,col3)

select 3,4,5

union all

select 6,7,8

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

20樓:

使用資料型別uniqueidentifier最合適了

--建立表

create table [a_tmp] (

[primary_id] [uniqueidentifier] not null ,

[col1] [varchar] (10) collate chinese_prc_ci_as null,

[col2] [varchar] (10) collate chinese_prc_ci_as null,

[col3] [varchar] (10) collate chinese_prc_ci_as null

constraint [pk_a_tmp] primary key nonclustered

( [primary_id]

) with fillfactor = 90 on [primary]

) on [primary]

go declare @myid uniqueidentifier

declare @int as int

set @int = 0

while @int < 500000 --這裡設定需要插入多少行

begin

set @int = @int + 1

set @myid = newid()

insert into a_tmp (primary_id, col1, col2, col3) select @myid, '', '', ''end

21樓:秀乞群群

**如下:

--建立測試表

create table [identity](

id int identity(1,2) not null primary key,--種子的起始值1,步長2

number varchar(20) unique not null,

name varchar(20) not null,

password varchar(20) default(123),

description varchar(40) null

) --插入記錄

insert into [identity](number,name,description) values('001','1st','id=1,因為起始值1')

insert into [identity](number,name,description) values('002','2nd','id=3,因為起始值1,步長2')

insert into [identity](number,name,description) values('003','3rd','id=5,由於字元長度超長,報錯插入失敗,造成此id產生後被放棄')

insert into [identity](number,name,description) values('004','4th','id=7 not 5,因為第三條記錄插入失敗')

--檢索記錄,檢視結果

select * from [identity]

sql資料查詢,批量修改sql資料庫查詢出來的資料

第一種寫法,比較好理解 declare num int set num 0 select case when rowindex in 1,2 then num num score else num num 2 score endfrom select row number over order by...

sql資料庫問題,SQL資料庫問題?

既然用了左連線,那麼a表中極有可能會出現空值,而a.dept 20080203 and a.dept 20080204 and a.status o 卻又將空值排除在外了 我想知道的是,這個外連線究竟起什麼作用呢?看不大出來。有點兒覺得在 left join tn stock as c where ...

資料庫sql題目,資料庫SQL題目

sql資料庫題目 sql資料庫練習題,急求!5 sql資料庫題目誰能給做一下 if object id n member is not null drop table member create table member mid char 10 not null primary key,mname ...

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

你的文件是什麼型別還是表?如果是表,直接插 insert into 要插表 對應欄位1,對應欄位2,對應欄位3 select 欄位1,欄位2,欄位3 from 文件 如果文件不是表,而是其他型別的,先把資料放到excel,同過excel匯入資料庫 再通過上面的方式插入吧 把這些資料放到excel表中...

sql資料庫檔案如何還原,SQL資料庫如何還原

在企業管理器下很方便操作的,直接右鍵可以看到還原資料庫,備份資料庫等操作。 要還原資料庫首先得後有資料庫的備份檔案。如果sqlsever2000沒有這個資料庫,你先建立乙個空資料庫,記住這個資料庫的資料檔案路徑和日子檔案路徑,然後右鍵資料庫,點還原 選從裝置 選擇裝置 就是選資料庫的備份檔案 點選項...