當前位置:首頁 » 操作系統 » c資料庫批量更新資料庫

c資料庫批量更新資料庫

發布時間: 2022-11-26 16:10:46

❶ postgresql 如何批量更新資料庫,有這么難嗎

更改擁有者:
usage()
{
cat << EOF
usage: $0 options
This script set ownership for all table, sequence and views for a given database
Credit: Based on http://stackoverflow.com/a/2686185/305019 by Alex Soto
Also merged changes from @sharoonthomas

OPTIONS:
-h Show this message
-d Database name
-o Owner
EOF
}

DB_NAME=
NEW_OWNER=
PGSQL_USER=postgres

while getopts "hd:o:" OPTION
do
case $OPTION in
h)
usage
exit 1
;;
d)
DB_NAME=$OPTARG
;;
o)
NEW_OWNER=$OPTARG
;;
esac
done

if [[ -z $DB_NAME ]] || [[ -z $NEW_OWNER ]]
then
usage
exit 1
fi
for tbl in `psql -U $PGSQL_USER -qAt -c "select tablename from pg_tables where schemaname = 'public';" ${DB_NAME}` \
`psql -U $PGSQL_USER -qAt -c "select sequence_name from information_schema.sequences where sequence_schema = 'public';" ${DB_NAME}` \
`psql -U $PGSQL_USER -qAt -c "select table_name from information_schema.views where table_schema = 'public';" ${DB_NAME}` ;
do
psql -U $PGSQL_USER -c "alter table \"$tbl\" owner to ${NEW_OWNER}" ${DB_NAME} ;
done

❷ 如何在sql server 2008中 批量地更新數據,就是一次性更新多個欄位的同一行數據

你好!你寫的「」update ['+@tablename+'] set ('+@updatesp+')=(select ('+@Csql+')) where 學號='''+@sno+''''」,就好比是set a,b,c,d,e=(f,g,h,i,j),這樣肯定不能建立對應關系。我提供個思路給你:將傳進來的列名分開,用循環去更新,一次只更新一列。希望能幫到你~

❸ C#winform三層架構中如何實現將gridcontrol批量插入數據到資料庫

//將dgvStudent數據操作更新到資料庫
private Boolean dbUpdate()
{
string strSql = "select ID as 學號,name as 姓名, class as 班級 from tbl_Student";
//新建一個用於將dgvStudent數據操作更新到資料庫的內存表
DataTable dtUpdate= new DataTable();
//新建一個用於更新dgvStudent數據操作的內存表
//利用da初始化dtUpdate的表結構(和數據)
SqlDataAdapter da = new SqlDataAdapter(strSql, sqlCon);
da.Fill(dtUpdate);
//初始化的數據需清除,以存放更新後的dgvStudent數據
dtUpdate.Rows.Clear();
//再建一個內存表,用於將更新後的dgvStudent數據逐條讀取出來存入更新內存表中
DataTable dtShow = new DataTable();
//逐條讀取出來存入更新內存表中
dtShow = (DataTable) dgvStudent.DataSource;
for (int i = 0; i < dtShow.Rows.Count; i++)
{
dtUpdate.ImportRow(dtShow.Rows[i]);
}
try
{
this.sqlCon.Open();
//使對DataSet所做的更改與關聯的SQL Server資料庫相協調
SqlCommandBuilder sqlCbld;
sqlCbld = new SqlCommandBuilder(da);
//通過該da將更新後的dgvStudent數據(即已復制的dtUpdate)更新到資料庫
da.Update(dtUpdate);
sqlCon.Close();
}
catch(Exception ex)
{
MessageBox.Show("資料庫操作失敗:" + ex.Message.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
return false;
}
dtUpdate.AcceptChanges();
return true;
}

❹ sql 批量修改數據

使用update 更新修改資料庫數據,更改的結果集是多條數據則為批量修改。
語法格式如:
update 表格 set 列 = 更改值 where 篩選條件
例:
update table set a=1 --將table 中所以a列的值改為 1
update table set a=1 where b=2 --將table 中列b=2的記錄中a列的值改為 1

❺ 如何批量更新access資料庫

更新查詢,查詢語句:
update 表1 set 表1.a=表2.a,表1.b=表2.b,表1.d=表2.d
from 表1,表2 where 表1.c=表2.c

祝你成功!

❻ sql在update更新時如何快速且大批量的更新數據(C#中寫的)

這不是才1000個數據嗎, 循環起來不會很慢, 而且也用不上case when啊親
SQL:
UPDATE tableA
SET colB=@colB, colC=@colC
WHERE colA=@colA

循環
for(var i=0; i<1000; i++)
{
colA.Value=A[i]; colB.Value=B[i]; colC.Value=C[i];

cmd.ExecuteNonQuery();

}

❼ 有關資料庫更新

最好寫個存儲過程,因為是批量更新,所以存儲過程參數用XML格式的。
存儲過程裡面邏輯這樣:
insert table(欄位)
SELECT 欄位
FROM OPENXML (@handle, '/ArrayOfT_ZZ_EquipmentPointEntities2/T_ZZ_EquipmentPointEntities2',2)
WITH (
欄位
)
where 欄位 not in (select 欄位 from table)

update table set 欄位=''
where 欄位 in SELECT 欄位
FROM OPENXML (@handle, '/ArrayOfT_ZZ_EquipmentPointEntities2/T_ZZ_EquipmentPointEntities2',2)
WITH (
欄位
)

❽ C#.net里如何實現數據批量傳入SQL資料庫

用bulkinsert導入一個文件夾下的所有指定條件的文件
(實現批量上傳)
在某個文件夾下有很多文件,要將該文件夾下的
snd*.txt
文件,插入
snd_info

rcv*.txt
文件,插入
rcv_info

其他
.txt
文件和其他類型的文件不處理
--示例處理過程
--處理參數
declare
@path
nvarchar(266)
set
@path='c:\'
--要導入的文件所在的目錄
--導入處理
--得到該目錄下的所有文件
if
right(@path,1)<>'\'
set
@path=@path+'\'
create
table
#t(fn
nvarchar(1000),depth
int,isfile
int)
insert
#t
exec
master..xp_dirtree
@path=@path,@depth=1,@file=1
--定義游標,逐個導入文件
declare
@s
varchar(8000)
declare
tb
cursor
local
for
select
'bulk
insert
'
+case
when
fn
like
'snd%.txt'
then
'snd_info
from
'''+@path+fn
+'''
with
(formatfile='''+@path+'snd_bcp.txt'
else
'rcv_info
from
'''+@path+fn
+'''
with
(formatfile='''+@path+'rcv_bcp.txt'
end+''')'
from
#t
where
isfile=1
and
fn
not
in('snd_bcp.txt','rcv_bcp.txt')
and
(fn
like
'snd%.txt'
or
fn
like
'rcv%.txt')
open
tb
fetch
tb
into
@s
while
@@fetch_status=0
begin
exec(@s)
fetch
tb
into
@s
end
close
tb
deallocate
tb
drop
table
#t

❾ 批量更新資料庫中一個欄位的值(在欄位值前加字元串"00")

實現語句改成: Update [member] Set card='00' || card

PostgreSQL 8.1 中文文檔:http://www.pgsqldb.org/pgsqldoc-8.1c/

❿ sql在update更新時如何快速且大批量的更新數據

使用merge語句吧
語法:
MERGE INTO 目標表 AS A

USING 源表 AS B

ON (A.COL = B.COL) --匹配條件

WHEN MATCHED THEN --當匹配上就用B表的欄位更新A表的欄位

UPDATE SET
A.COL1 = B.COL1,
...
A.COLn = B.COLn

WHEN NOT MATCHED THEN INSERT(A.COL1,...,A.COLn) --下面這句是不匹配就插入數據

VALUES (B.COL1,...,B.COLn);

熱點內容
功能點估演算法是 發布:2024-05-02 16:24:38 瀏覽:165
b站非法訪問 發布:2024-05-02 16:09:59 瀏覽:456
寶馬523壓縮機 發布:2024-05-02 16:00:40 瀏覽:611
冒險島m韓服安卓漢化包哪裡搞 發布:2024-05-02 16:00:24 瀏覽:955
雲伺服器託管平台 發布:2024-05-02 15:55:16 瀏覽:860
linux查看服務狀態 發布:2024-05-02 15:55:15 瀏覽:933
phpfirebird 發布:2024-05-02 15:45:55 瀏覽:125
思科伺服器怎麼修改imc地址 發布:2024-05-02 15:35:27 瀏覽:770
強制刪除文件夾的工具 發布:2024-05-02 15:34:34 瀏覽:770
sql存儲過程調用存儲過程 發布:2024-05-02 15:34:33 瀏覽:897