将默认值传递给批量插入中的列 [英] Passing default values to a column in Bulk insert

查看:31
本文介绍了将默认值传递给批量插入中的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从包含以下数据的 csv 文件中获取数据.

I am trying to get data from a csv file with the following data.

Station code;Priority vehicle;DateBegin;DateEnd
01;y;20100214;20100214
02;n;20100214;20100214
03;;20100214;20100214

现在,当没有为 csv 文件中的优先车辆"列提供数据时,我想要表中的值n".我将查询写为

Now I want a value 'n' in the table when no data is provided for the column 'Priority vehicle' in csv file. I am writing the query as

BULK INSERT dbo.#tmp_station_details  
    FROM 'C:\station.csv'  
    WITH (  
         FIELDTERMINATOR ='';'',  
         FIRSTROW = 2,
         ROWTERMINATOR = ''\n'' 
        )  

推荐答案

在此处查看完整说明:http://msdn.microsoft.com/en-us/library/ms187887.aspx

"默认情况下,将数据导入表时,bcp 命令和BULK INSERT 语句会观察为表中的列定义的任何默认值.例如,如果有是数据文件中的空字段,则加载该列的默认值. "

"By default, when data is imported into a table, the bcp command and BULK INSERT statement observe any defaults that are defined for the columns in the table. For example, if there is a null field in a data file, the default value for the column is loaded instead. "

我的建议是为 Priority Vehicle 列指定一个默认值,csv 文件中的 Null 值将使用表设计中指定的默认值覆盖到您的 SQL 表中.

My suggestion is to specify a default value for the Priority vehicle column and the Null value from the csv file will be overwritten to your SQL table with the default value specified in the table design.

这篇关于将默认值传递给批量插入中的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆