Skip to content
Advertisement

Repeat insert statement without GO

Is there a “nicer” way to achieve the same results as this SQL query:

Which is to insert 300 default all NULL (except PK Id col) new lines into an empty table? It seems to take a while!

Also, the value 300 could be completely variable e.g. something like

but that obviously doesn’t work:

Advertisement

Answer

You can use a recursive CTE:

Inserting rows where all values are NULL seems to be not very useful. But, here is a db<>fiddle with an identity id column.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement