Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select From a table that is constantly being inserted into

How would I go about grabbing data from a table that is CONSTANTLY being inserted into (and needs to be) without causing any locking so that the inserts will continue unheeded.

I've looked around and found select with nolock option but, if I'm understanding correctly, this does not stop the lock creation, rather goes around current locks and grabs everything?

Thanks.

EDIT: This table will never be UPDATED, only INSERTS and SELECTS

like image 976
Antares Avatar asked Oct 25 '11 19:10

Antares


People also ask

How do I insert a SELECT query result into a table?

From the Query Designer menu, point to Change Type, and then click Insert Results. In the Choose Target Table for Insert Results Dialog Box, select the table to copy rows to (the destination table).

Why is SELECT into faster than insert into?

INTO' creates the destination table, it exclusively owns that table and is quicker compared to the 'INSERT … SELECT'. Because the 'INSERT … SELECT' inserts data into an existing table, it is slower and requires more resources due to the higher number of logical reads and greater transaction log usage.

Can SELECT be used with insert statement?

You can use a select-statement within an INSERT statement to insert zero, one, or more rows into a table from the result table of the select-statement. The select-statement embedded in the INSERT statement is no different from the select-statement you use to retrieve data.

What does insert into SELECT statement do?

The INSERT INTO SELECT statement copies data from one table and inserts it into another table.


1 Answers

As long as you don't mind getting dirty reads from your table this shouldn't be a problem for you. Make sure that the translation isolation level is set appropriately and that your calling code (if applicable) isn't using implicit transactions and you should be fine.

Microsoft's Transaction Isolation Docs: http://msdn.microsoft.com/en-us/library/ms173763.aspx

NOLOCK is a common, and in my opinion, abused option when running into situations like this. Although it can help you overcome problems in high contention situations it can also cause difficult to track down bugs. Although this is something of an ongoing argument check out http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx for an idea of some of the risks with using hints like this.

like image 98
Carth Avatar answered Nov 03 '22 01:11

Carth