Search code examples
pythonsql-serverbcp

how to avoid dbo in bcpy(bulk copy python) while pushing the data into sql server from python


I am trying to push the data from pandas dataframe into a sql server table using bcpy in python script.

database : db_name
table : schema_name.table_name

but by default It creates the dbo schema while running and throw an error like below:

A valid table name is required for in, out, or format options. 
db_name.dbo.schema_name.table_name

actually, I gave the schema name as schema_name.

how to avoid the default schema name dbo?

If i gave the schema name,

database : database_name
schema : schema_name
table : table_name

It creates the database_name.schema_name.table_name. but still its showing

A valid table name is required for in, out, or format options.
failed : Bcp command failed

Solution

    1. BCP(Bulk Copy Program) utility for SQL Server should be installed in your machine.

    2. database details should be in a dictionary form

      sql_config = {database : database_name schema : schema_name table : table_name}

    If there is no schema name specified, by default dbo would be the schema name.

    while fitting all the inputs into bcp command, the sql table name would be database_name.schema_name.table_name