MM们
如果您不想使用 bcp cammand 导入 csv 文件,则可以使用 Python 库。pandas下面是我将计算机上的无标头“test9.csv”文件导入 Azure SQL 数据库的示例。csv 文件:Python 代码示例:import pandas as pdimport sqlalchemyimport urllibimport pyodbc# set up connection to database (with username/pw if needed)params = urllib.parse.quote_plus("Driver={ODBC Driver 17 for SQL Server};Server=tcp:***.database.windows.net,1433;Database=Mydatabase;Uid=***@***;Pwd=***;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;")engine = sqlalchemy.create_engine("mssql+pyodbc:///?odbc_connect=%s" % params)# read csv data to dataframe with pandas# datatypes will be assumed# pandas is smart but you can specify datatypes with the `dtype` parameterdf = pd.read_csv (r'C:\Users\leony\Desktop\test9.csv',header=None,names = ['id', 'name', 'age'])# write to sql table... pandas will use default column names and dtypesdf.to_sql('test9',engine,if_exists='append',index=False)# add 'dtype' parameter to specify datatypes if needed; dtype={'column1':VARCHAR(255), 'column2':DateTime})通知:在门户上获取连接字符串。UID格式就像 .[username]@[servername]运行此脚本,它的工作原理是: