1樓:匿名使用者
也可以先查詢出結果儲存下來,再把儲存的值放到insert語句。
mysql 是一個關係型資料庫,目前屬於 oracle
旗下公司。mysql是開放原始碼軟體,因此可以大大降低總體擁有成本。支援多執行緒,充分利用cpu資源。
提供tcp/ip、odbc和jdbc等多種資料庫連線途徑。支援大型的資料庫。可以處理擁有上千萬條記錄的大型資料庫
2樓:奔跑的窩牛的家
其實很簡單,只是為了忘記,做個記錄,用的時候方便。
不管是在**開發還是在應用程式開發中,我們經常會碰到需要將mysql或ms sqlserver某個表的資料批量匯入到另一個表的情況,甚至有時還需要指定匯入欄位。
本文就將以mysql資料庫為例,介紹如何通過sql命令列將某個表的所有資料或指定欄位的資料,匯入到目標表 中。此方法對於sqlserver資料庫,也就是t-sql來說,同樣適用 。
類別一、 如果兩張張表(匯出表和目標表)的欄位一致,並且希望插入全部資料,可以用這種方法:
insert into 目標表 select * from **表 ;
例如,要將 articles 表插入到 newarticles 表中,則可以通過如下sql語句實現:
insert into newarticles select * from articles ;
類別二、 如果只希望匯入指定欄位,可以用這種方法:
insert into 目標表 (欄位1, 欄位2, ...) select 欄位1, 欄位2, ... from **表 ;
請注意以上兩表的欄位必須一致,否則會出現資料轉換錯誤。
insert into tpersonnelchange(
userid,
depid,
subdepid,
postiontype,
authorityid,
changedates,
insertdate,
updatedate,
sakuseisyaid
)select
userid,
depid,
subdepid,
postiontype,
authorityid,
date_format(employdate, '%y%m%d'),
now(),
now(),
1from
tusermst
where
`status` = 0
and quit*** = 0
and userid > 2
sql語句 怎麼把從一個表中查出來資料插入到另一個表中
3樓:明月照溝渠
1、假如
則 insert into a(a,b,c) (select a,b,c from b)
2、假如a表不存在
select a,b,c into a from b
3、假如需要跨資料庫
insert into adb.[dbo].a(a,b,c) (select a,b,c from bdb.[dbo].b)
擴充套件資料:
sql匯入語句
1、如果要匯出資料到已經生成結構(即現存的)foxpro表中,可以直接用下面的sql語句
insert into openrowset('msdasql',
'driver=microsoft visual foxpro driver;sourcetype=dbf;sourcedb=c:\',
'select * from [aa.dbf]')
select * from 表
說明:sourcedb=c:\ 指定foxpro表所在的資料夾
aa.dbf 指定foxpro表的檔名.
2、匯出到excel
exec master..xp_cmdshell 'bcp settledb.dbo.
shanghu out c:\temp1.xls -c -q -s"gnetdata/gnetdata" -u"sa" -p""'
3、/** 匯入文字檔案
exec master..xp_cmdshell 'bcp dbname..tablename in c:
\dt.txt -c -sservername -usa -ppassword'
4樓:鬱筱羽
標準sql語句
bai格式:
insert
into 表名(
du欄位zhi
名)select 欄位名
from 表面
例子:dao將內查詢出的s表中容sno,j表中jno,p表中pno插入spj表中
insert
into spj(sno,jno,pno)select sno,jno,pno
from s,j,p
5樓:sql的藝術
insert into table2 (col1,col2,col3)
select col1,col2,col3 from table1
記得插入表的列數要與查詢結果列數一致,並且資料格式也需一致
6樓:day忘不掉的痛
方法如下:
insert into 表2(欄位名1,欄位名2,.....)select 欄位1,欄位2,...
from 表1
where ...
其中欄位型別必須完全符合。
7樓:育知同創教育
使用insert into 目標表(欄位列表) select 欄位列表 from 原始表
即可實現你所說的功能。
8樓:匿名使用者
你要查什麼資料據?算了,我這是巢狀語句,你看著往裡面換欄位就可以了
insert into 表(select 條件 from 表)
9樓:
很簡單 就是一bai個du
inert into table(col1,col2,…)select col1,col2,… 語句例如:insert into a(id,name) select id,name from emp;
表示zhi從emp表中查dao
詢出來的
id,name值專 插入到屬a表的id,name中
10樓:尹巧駿
(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。
11樓:匿名使用者
insert into table_dest(column1, column2...)select column1, column2...
from table_source
where ....
12樓:匿名使用者
insert into t1 value (select * from t2);
13樓:楊春三月
insert into users1(id,name,age) select users.user_id,users.user_name,users.
user_age from users ;
親測試可用!
內!容!
sql如何將一個資料庫中查到的結果加入到另一個資料庫
14樓:託多羅夫
語句形式為:insert into 資料庫名.框架名.表名(列名) select (列名) from 資料庫名.框架名.表名 where 條件。
類似這樣寫就行了:
insert into myemp.dbo.tjdjb(yybh)
select yybh
from mycmd.dbo.tjdjb where djrq='2009-10-15' and yybh = '11'
select a,c into table2 from table1。
sql全稱是「結構化查詢語言(structured query language)」,最早的是ibm的聖約瑟研究實驗室為其關聯式資料庫管理系統system r開發的一種查詢語言,它的前身是square語言。sql語言結構簡潔,功能強大,簡單易學,所以自從ibm公司2023年推出以來,sql語言,得到了廣泛的應用。如今無論是像oracle ,sybase,informix,sql server這些大型的資料庫管理系統,還是像visual foxporo,powerbuilder這些微機上常用的資料庫開發系統,都支援sql語言作為查詢語言。
15樓:發生等將發生
另一種事務還是什麼,忘記啦,很多種方式的,網上找找,給你一個我收集的關於連結伺服器的
16樓:匿名使用者
insert into test2.card select * from test1.card where 條件
17樓:匿名使用者
1、可以匯出到excel 然後在匯入到另外一個資料庫
2、可以和另外一個資料庫建立遠端連結,然後直接進行關聯操作
18樓:匿名使用者
insert into test2..table2(欄位1, 欄位2, ……) select 欄位1,欄位2,…… from test1..table1
前後兩個欄位列表所列出的欄位名,必須嚴格匹配
mysql 如何用一條sql將一張表裡的資料插入到另一張表。
19樓:匿名使用者
1. 表結構完全bai
一樣du
insert into 表1
select * from 表2
2. 表結構不一樣zhi(這種情況
下得指dao定列專
名)屬insert into 表1 (列名1,列名2,列名3)select 列1,列2,列3 from 表2
20樓:匿名使用者
insert into table_a(需要的欄位)
select 需要的欄位 from table_b
Mysql中查詢表,把結果中的NULL替換成0,請寫出s
可以用case when解決 select case when 欄位 is null then 0 else 欄位 end from 表名 好像是夢 1 mssql isnull 語法isnull check expression replacement value 引數check expressi...
能使用「查詢我的iphone」,找到沒有插sim卡的ipho
能使用 查詢我的iphone 找到未插卡的蘋果手機啟動 查詢我的iphone 應用程式後會自動開始追蹤檢測,所有用同一蘋果賬號登陸的蘋果裝置都會被檢測出來,並會有地圖示識。點選蘋果手機裝置名進入,軟體會詳細標示出當前手機所處的位置 再點下方的 操作 按鈕,即會出現幾個非常 危險 的操作選項,比如 抹...
sql如何把查詢到的NULL替換成空值
妞兒媽媽 1 這要看你如何儲存你查詢的結果。只能是你把你查詢的結果儲存為0,查詢不會改變原本存在的值。表名test,欄位a null.int型 欄位b 1,欄位c 2 select from test into tabel test1 update set a 0 where a null。2 用 ...