Laravel query builder gives unvalid error while copying table
09:36 02 Feb 2026

I am trying to run a small SQL query in Laravel without the querybuilder.

$DB = DB::connection('localhost');
$query = 'select * into newtable from oldtable';
$DB->statement($query);
DB::purge('localhost');

But running this code results in the following error. Which is weird, because the account that I use is the db-owner. And in a other part in laravel I run a select query without any problems.

SQLSTATE[42000]: [Microsoft][ODBC Driver 18 for SQL Server][SQL Server]CREATE TABLE permission denied in database

I setup a separate PHP file doing exactly the same with the same credentials:

getMessage() . "\n";
    exit;
}
$sth = $mssql->query("select * into newtable from oldtable" );
$result = $sth->fetchAll();
print_r($result);

This piece of code runs without any issue and copies the oldtable to the newtable.

The only differences I can think of is the laravel layer and the pdo driver ( dblib vs sqlsrv ).
But whatever I try, I can't find a solution to making my laravel code work. (404 solution not found).

Anyone got any ideas?

php sql-server laravel sqlsrv