I have text file with 2,000,000 line and want to insert each line in a database row so, inserting 2,000,000 record into sql server using php file. What is the fastest way to do that?
For testing I am using this code:
for ( $i=1 ; $i<=2000000 ; $i++)
{
$sql = "INSERT INTO BlastSequenceDim (Seq_id) VALUES ('$i')";
$stmt = sqlsrv_query( $conn, $sql);
if( $stmt === false )
{
die( print_r( sqlsrv_errors(), true));
}
}
But, it takes a lot of time. Can this query executes in seconds?
Thanks,
Please use Bulk insert this will significantly improve the performance and save time .
learn more about Bulk insert query in SQL
You can also save time by cutting out PHP and directly accessing the SQL database, this would be common practice to initially populate a db.
Another link
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With