Best way of selecting 8k+ rows from a table

Maxsteel

I have an excel sheet that contains more than 8k IDs. I have a table in SQL server that contains those IDs and related entries. What would be the best way to get those rows? The way I am doing right now is to use export data function from for the specific table using query:

select * from table_name where uID in (ALL 8K IDs)

Zohar Peled

Since this has to be done multiple times I suggest using bulk insert from the csv file to a temporary sql table and then use inner join with this table.
Assuming your csv file contains the ids in a single row, (i.e 1,34,345,....), something like this should do the trick:

-- create the temporary table
CREATE TABLE #CSVData 
(
    IdValue int
)
-- create a clustered index for this table (Note: this doesn't need to be unique)
CREATE CLUSTERED INDEX IX_CSVData on #CSVData (IdValue ) 

-- insert the csv data to the table
BULK INSERT #CSVData
FROM 'c:\csvData.txt'
WITH
(
    ROWTERMINATOR = ','
)

-- select the data 
SELECT T.* 
FROM table_name T
INNER JOIN #CSVData ON(T.uId = IdValue)

-- cleanup (the index will be dropped with the table)
DROP TABLE #CSVData

One more link to look at is This article by Pinal dave on sqlauthority.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

What is the best way for selecting 2 row from table in one row?

From Dev

Selecting specific rows from table

From Dev

What is the best way in Android to delete all rows from a table

From Dev

What is the best way in Android to delete all rows from a table

From Java

Selecting rows from sqlite table with three criterions

From Dev

Selecting changed rows from an audit table

From Dev

Selecting rows from a table depending on a column

From Dev

Selecting only maxdate rows from particular table

From Dev

Selecting rows that are included in a set from another table

From Dev

Selecting distincts rows from a table with several similar rows

From Dev

Selecting corresponding k rows from matrix and vector

From Dev

Selecting rows from a table depending on keywords in another table

From Dev

selecting unique rows from one table according to another table and then sorting it

From Dev

Best way to append additional result columns from joined table several rows in SQL

From Dev

Selecting data from multiple rows from a temporary table create by SELECT

From Dev

Selecting rows using multiple LIKE conditions from a table field

From Dev

Selecting the top 5 rows from a joined table, into the result of a larger query?

From Dev

Selecting all rows from Informix table containing some null columns

From Dev

Selecting only rows with certain number from data table

From Dev

Selecting specific rows based on data from other table

From Dev

Selecting rows absent from one table against two other tables?

From Dev

Selecting multiple rows from a table and applying a function on a button click

From Dev

Selecting the top 5 rows from a joined table, into the result of a larger query?

From Dev

MYSQL:: Selecting rows from table without the most recent ones

From Dev

Selecting two rows from another table using one row

From Dev

Selecting rows from data table with filter option:RShiny

From Dev

Selecting next N rows from table with left join

From Dev

Best way for bidirectional referenced table rows for double-entry booking

From Dev

what is the best way to check that there are no rows in a table in entity framework?

Related Related

  1. 1

    What is the best way for selecting 2 row from table in one row?

  2. 2

    Selecting specific rows from table

  3. 3

    What is the best way in Android to delete all rows from a table

  4. 4

    What is the best way in Android to delete all rows from a table

  5. 5

    Selecting rows from sqlite table with three criterions

  6. 6

    Selecting changed rows from an audit table

  7. 7

    Selecting rows from a table depending on a column

  8. 8

    Selecting only maxdate rows from particular table

  9. 9

    Selecting rows that are included in a set from another table

  10. 10

    Selecting distincts rows from a table with several similar rows

  11. 11

    Selecting corresponding k rows from matrix and vector

  12. 12

    Selecting rows from a table depending on keywords in another table

  13. 13

    selecting unique rows from one table according to another table and then sorting it

  14. 14

    Best way to append additional result columns from joined table several rows in SQL

  15. 15

    Selecting data from multiple rows from a temporary table create by SELECT

  16. 16

    Selecting rows using multiple LIKE conditions from a table field

  17. 17

    Selecting the top 5 rows from a joined table, into the result of a larger query?

  18. 18

    Selecting all rows from Informix table containing some null columns

  19. 19

    Selecting only rows with certain number from data table

  20. 20

    Selecting specific rows based on data from other table

  21. 21

    Selecting rows absent from one table against two other tables?

  22. 22

    Selecting multiple rows from a table and applying a function on a button click

  23. 23

    Selecting the top 5 rows from a joined table, into the result of a larger query?

  24. 24

    MYSQL:: Selecting rows from table without the most recent ones

  25. 25

    Selecting two rows from another table using one row

  26. 26

    Selecting rows from data table with filter option:RShiny

  27. 27

    Selecting next N rows from table with left join

  28. 28

    Best way for bidirectional referenced table rows for double-entry booking

  29. 29

    what is the best way to check that there are no rows in a table in entity framework?

HotTag

Archive