When loading an R dataframe into SQL Server using
write_dataframe_to_db()
, the following steps are used:
The R dataframe is loaded into a staging table in the database in batches of n rows at a time.
-
Create target table in the database and load from staging to target.
-
If table of the specified name does NOT already exist in the database schema:
- Create target table in the database.
- Insert all rows from staging table to target table.
- Create target table in the database.
-
If table of same name does already exist in the database schema:
- If argument
append_to_existing = FALSE
(this will result in an overwrite):- Drop the existing copy of the target table and create a new one.
- Insert all rows from staging table into target table.
- If argument
append_to_existing = TRUE
:- Check that staging table columns and existing target table columns
are the same. If not, add any extra columns to existing SQL Server
table.
- Insert all rows from staging table into target table.
- Check that staging table columns and existing target table columns
are the same. If not, add any extra columns to existing SQL Server
table.
- If argument
-
Delete the staging table.