Bulk Insert without specifying column names

Posted 1 year ago by JohnnyW2001

A simple request, but I have to pre-populate a database with hundreds of entries. I've created a custom command to handle everything and it's working great, except for the largest bulk insert (hundreds of entries in its own right).

I'd much prefer it if I could simply use the following:

    DB::table('pupils')->insert([
        ['Katy', 'Walker', 'female', '1'],
        ['Nancy','Jones','female','32'],
        ['Natalie','Smith','female','974'],
        ['Pamela','James','female','9'],
        ...

Which is possible in SQL, but instead it seems I have to:

    DB::table('pupils')->insert([
        [
            'first_name' => 'Katy',
            'last_name' => 'Walker',
            'gender' => 'female',
            'student_loan_id' => '1'
        ],
        [
            'first_name' => 'Nancy',
            'last_name' => 'Jones',
            'gender' => 'female',
            'student_loan_id' => '32'
        ],
        ...

I know it's dirty, but it's only happening once and it would save me a lot of work.

Is it possible at all to bulk insert without having to specify the column names?

Please sign in or create an account to participate in this conversation.