由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Database版 - INSERT or UPDATE, which is faster?
相关主题
什么时候不用索引a simple question about T-SQL
which one is faster? truncate or delete?Problem when using SQL " Insert...." to AutoNumber.
deletehow to include record deleted date into trigger?
SQL Server stupid questionsHelp on Sql server huge table performance
怎么学SQL SERVER谁能帮我看看这个sql query的优化
Re: Is there any easy way to truncate the LDF file of SQL SERVER?Oracle Group and Index question
Truncation error import csv file to SQL tableSQL Server query 一问
trigger vs. log ?SQL 2008 Create Index vs Rebuild Index (Alter Index)
相关话题的讨论汇总
话题: update话题: insert话题: delete话题: sql话题: faster
进入Database版参与讨论
1 (共1页)
n****u
发帖数: 229
1
I am writing C# with SQL statement to update a record which has four text
fields (Introduction, What am I looking for, etc)
When a user, first time, inputs texts into these fields, Of course use
INSERT.
But when the user decides to modify one of these, use UPDATE or INSERT?
If I choose INSERT, I need to delete old record, INSERT a new one.
If I choose UPDATE, I could just UPDATE record, but I am afraid the text
field may take longer time to update.
I feel like INSERT is always faster than UPDATE
t*********i
发帖数: 217
2
do insert when you have a new row; do update when you need to modify a row.
delete + insert is for sure more expensive than a update.
n****u
发帖数: 229
3
Thanks!

【在 t*********i 的大作中提到】
: do insert when you have a new row; do update when you need to modify a row.
: delete + insert is for sure more expensive than a update.

c*****d
发帖数: 6045
4
嗯,如果要操作的数据量小,update要比delete+insert快
如果要操作的数据量大,update要比truncate+insert慢

【在 t*********i 的大作中提到】
: do insert when you have a new row; do update when you need to modify a row.
: delete + insert is for sure more expensive than a update.

x***e
发帖数: 2449
5
I have to say, this is very misleading.
It really depends on what database you are talking about and the design.

【在 t*********i 的大作中提到】
: do insert when you have a new row; do update when you need to modify a row.
: delete + insert is for sure more expensive than a update.

B*****g
发帖数: 34098
6
砸变truncate了?

【在 c*****d 的大作中提到】
: 嗯,如果要操作的数据量小,update要比delete+insert快
: 如果要操作的数据量大,update要比truncate+insert慢

c*****d
发帖数: 6045
7
大数据量的时候用truncate+insert比Update快
陈述一个事实,哈哈

【在 B*****g 的大作中提到】
: 砸变truncate了?
n****u
发帖数: 229
8
I agree.
Last time it would took 3 days to update 320,000 records (just update MSN
etc.)
But I truncated table first, INSERT... SELECT..., 30 seconds, done.

【在 c*****d 的大作中提到】
: 大数据量的时候用truncate+insert比Update快
: 陈述一个事实,哈哈

S*********t
发帖数: 78
9
truncate is different from delete

【在 n****u 的大作中提到】
: I agree.
: Last time it would took 3 days to update 320,000 records (just update MSN
: etc.)
: But I truncated table first, INSERT... SELECT..., 30 seconds, done.

n****u
发帖数: 229
10
Yes, I talked to my colleague this morning. He thinks DELETE might take long
time. So his suggestion is UPDATE.
Well I will look at the original PHP code to find out how that team did.Then
I would write similar one in C#.
Thanks all!

【在 S*********t 的大作中提到】
: truncate is different from delete
相关主题
Re: Is there any easy way to truncate the LDF file of SQL SERVER?a simple question about T-SQL
Truncation error import csv file to SQL tableProblem when using SQL " Insert...." to AutoNumber.
trigger vs. log ?how to include record deleted date into trigger?
进入Database版参与讨论
B*****g
发帖数: 34098
11
read coolbid's post again.

long
Then

【在 n****u 的大作中提到】
: Yes, I talked to my colleague this morning. He thinks DELETE might take long
: time. So his suggestion is UPDATE.
: Well I will look at the original PHP code to find out how that team did.Then
: I would write similar one in C#.
: Thanks all!

n****u
发帖数: 229
12
Never mind, just got fired half hour ago. hehe

【在 B*****g 的大作中提到】
: read coolbid's post again.
:
: long
: Then

c*******e
发帖数: 8624
13
not necessarily

【在 t*********i 的大作中提到】
: do insert when you have a new row; do update when you need to modify a row.
: delete + insert is for sure more expensive than a update.

c*******e
发帖数: 8624
14
what?

【在 n****u 的大作中提到】
: Never mind, just got fired half hour ago. hehe
n****u
发帖数: 229
15
A senior guy was fired two hours before I got fired.
Not sure what happened in big boss's mind.

【在 c*******e 的大作中提到】
: what?
n********6
发帖数: 1511
16
What happends when you need the log file?
Truncate does not generate the log, does not fire the trigger.

【在 c*****d 的大作中提到】
: 大数据量的时候用truncate+insert比Update快
: 陈述一个事实,哈哈

c*****d
发帖数: 6045
17
我ft
为什么呀?

【在 n****u 的大作中提到】
: Never mind, just got fired half hour ago. hehe
a*******t
发帖数: 891
18
if the updated columns are not indexed, update is faster

【在 n****u 的大作中提到】
: I am writing C# with SQL statement to update a record which has four text
: fields (Introduction, What am I looking for, etc)
: When a user, first time, inputs texts into these fields, Of course use
: INSERT.
: But when the user decides to modify one of these, use UPDATE or INSERT?
: If I choose INSERT, I need to delete old record, INSERT a new one.
: If I choose UPDATE, I could just UPDATE record, but I am afraid the text
: field may take longer time to update.
: I feel like INSERT is always faster than UPDATE

c*******e
发帖数: 8624
19
comfort

【在 n****u 的大作中提到】
: A senior guy was fired two hours before I got fired.
: Not sure what happened in big boss's mind.

c*****d
发帖数: 6045
20
不乖,发几个包子安慰一下吧

【在 c*******e 的大作中提到】
: comfort
相关主题
Help on Sql server huge table performanceSQL Server query 一问
谁能帮我看看这个sql query的优化SQL 2008 Create Index vs Rebuild Index (Alter Index)
Oracle Group and Index questionSQL 2000 create index 問題
进入Database版参与讨论
c*******e
发帖数: 8624
21
嗯,本版很穷,才66.8个伪币,都发了

【在 c*****d 的大作中提到】
: 不乖,发几个包子安慰一下吧
n****u
发帖数: 229
22
多谢老大啦

【在 c*******e 的大作中提到】
: 嗯,本版很穷,才66.8个伪币,都发了
n********6
发帖数: 1511
23
how to make/create bao zi?

【在 c*******e 的大作中提到】
: 嗯,本版很穷,才66.8个伪币,都发了
w*******e
发帖数: 1622
24
多灌水

【在 n********6 的大作中提到】
: how to make/create bao zi?
B*****g
发帖数: 34098
25
此处不留爷,自有留爷处。

【在 n****u 的大作中提到】
: A senior guy was fired two hours before I got fired.
: Not sure what happened in big boss's mind.

k********e
发帖数: 702
26
Hence truncate doesn't work with replication and logshipping

【在 n********6 的大作中提到】
: What happends when you need the log file?
: Truncate does not generate the log, does not fire the trigger.

j*****n
发帖数: 1781
27
truncate vs. delete
http://www.mssqltips.com/tip.asp?tip=1080

【在 k********e 的大作中提到】
: Hence truncate doesn't work with replication and logshipping
t*********i
发帖数: 217
28
My gosh!
Just read this...Hope you feel better now.

【在 n****u 的大作中提到】
: Never mind, just got fired half hour ago. hehe
t*********i
发帖数: 217
29
I am curious...can you give a example (or document) that a update would be
more expensive than a delete+insert.
I kind of think all relational DBs have similar structures...

【在 x***e 的大作中提到】
: I have to say, this is very misleading.
: It really depends on what database you are talking about and the design.

x***e
发帖数: 2449
30
the different between structures, you should be able to get some reference
online.
One example here
one of the big difference between SQL server and Oracle is the transaction
log.
SQL use single log process, while Oracle is is multi.
Based on that, lots of code need to be re-writen.
So you can not just say it is universal for all DBs.
They could be the same in the future, but not now.
Give you one example for update could be much more expensive.
You have an update trigger for the table.
Generall

【在 t*********i 的大作中提到】
: I am curious...can you give a example (or document) that a update would be
: more expensive than a delete+insert.
: I kind of think all relational DBs have similar structures...

相关主题
MS T-SQL 问题which one is faster? truncate or delete?
帮忙解释下这个查询,有关NULL的delete
什么时候不用索引SQL Server stupid questions
进入Database版参与讨论
t*********i
发帖数: 217
31
I don't know much about Sql server, here is what I found:
http://www.windowsitlibrary.com/Content/77/21/1.html
A direct, same-page Update occurs when a record is deleted from a page and
inserted onto that same page, usually because of increasing row length.
Because the record does not move to a new page, none of the indexes needs to
be updated, unless, of course, an indexed field is updated. This type of
Update gets two records, an op code of 5 (Delete), followed by an op code of
6 (Indirect Ins
m*****8
发帖数: 292
32
in MS SQL,internally, an update = delete + insert
so u figure the rest.
x***e
发帖数: 2449
33
I do not know about that.
I only know it is case by case.
And I am not work for MS either....
I can not image in the following case the update >= insert + delete
in any of the SQL env.
you have a table
Id1, id2, text
while ID1 is unique index, id2 is an int none indexed column and text is a
text column.
and you want to update the id2 column....based on id1....

to
of

【在 t*********i 的大作中提到】
: I don't know much about Sql server, here is what I found:
: http://www.windowsitlibrary.com/Content/77/21/1.html
: A direct, same-page Update occurs when a record is deleted from a page and
: inserted onto that same page, usually because of increasing row length.
: Because the record does not move to a new page, none of the indexes needs to
: be updated, unless, of course, an indexed field is updated. This type of
: Update gets two records, an op code of 5 (Delete), followed by an op code of
: 6 (Indirect Ins

t*********i
发帖数: 217
34
Just see your reply :)
for the case you mentioned.
**************************************************
you have a table
Id1, id2, text
while ID1 is unique index, id2 is an int none indexed column and text is a
text column.
and you want to update the id2 column....based on id1....
****************************************************
I still think in Oracle, Update is quicker than delete+insert
in SQL server (and all other DB system that one update = one delete + one
insert), that should be no much
L*********d
发帖数: 1019
35
Another example is, if you try to update a blob or update a big chunk of
data that could cause chains.
//i am not a dba
1 (共1页)
进入Database版参与讨论
相关主题
SQL 2008 Create Index vs Rebuild Index (Alter Index)怎么学SQL SERVER
SQL 2000 create index 問題Re: Is there any easy way to truncate the LDF file of SQL SERVER?
MS T-SQL 问题Truncation error import csv file to SQL table
帮忙解释下这个查询,有关NULL的trigger vs. log ?
什么时候不用索引a simple question about T-SQL
which one is faster? truncate or delete?Problem when using SQL " Insert...." to AutoNumber.
deletehow to include record deleted date into trigger?
SQL Server stupid questionsHelp on Sql server huge table performance
相关话题的讨论汇总
话题: update话题: insert话题: delete话题: sql话题: faster