Groups | Blog | Home
all groups > sql server (alternate) > march 2006 >

sql server (alternate) : speeding up inserts



zelnaga NO[at]SPAM gmail.com
3/29/2006 7:25:25 AM
according to the mysql manual, multiple inserts can be sped up by
locking the table before doing them and unlocking the table afterwards.

is the same true of multiple inserts in mysql? if so, how would the
table be locked?

any insights would be appreciated - thanks!
zelnaga NO[at]SPAM gmail.com
3/29/2006 1:48:27 PM

[quoted text, click to view]

err... sorry. I should have said mssql in the second paragraph. i'm
more familiar with mysql, hence my example in the first paragraph.
unfortunately, i'm not sure how to translate this to mssql, hence the
second paragraph.

also, why would i quote the manual of some dbms and then ask if "the
same" is true of that dbms?

bleh.
Robert Klemme
3/29/2006 7:24:18 PM
[quoted text, click to view]

Um, this is a newsgroup dedicated to Microsoft SQL Server. You're
probably better off checking in news:comp.databases.mysql .

Cheers

robert
Erland Sommarskog
3/29/2006 9:45:17 PM
(zelnaga@gmail.com) writes:
[quoted text, click to view]

In case "mysql" in the second paragraph is a type for MS SQL Server, the
answer is that you cannot really lock a table as such in MS SQL Server,
and definitely not unlock it. You can specify a locking hint to get a
table lock when you insert the first row. Note that you need to have a
user-defined transaction in progress, or else the lock will be released
since statements auto-commit in SQL Server. To "unlock" you simply commit
the transaction.

However, normally you don't play these games for insert statments. It's
better to let SQL Srever choose the locking mode.

If you need to load lots of data, you use BCP (a command-line tool) or
BULK INSERT (an SQL Statement). With these you can specify table lock to
speed up the operation.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
AddThis Social Bookmark Button