0
私はcsvファイルを持っていますので、SQLデータベーステーブルのデータを更新する必要があります。これを行う最善の方法は何ですか?私は一括インポートを考えていた、それは私がすべての列を使用せずにこれを行うことはできません。私はフォーマットファイルを使用することを考えていましたが、これが最も効率的な方法かどうかを知りたかったのです。ここでcsvファイルからテーブル内の特定の列を更新する必要があります
は、私は私のC#クラスからそれをしようとしていた方法です。
/// <summary>
/// Update all of the PropertyDefinitions
/// </summary>
internal static void InsertPropertyDefinitions()
{
//
// Define the connection
//
SqlConnection insertConnection = null;
try
{
RetryStrategy retryStrategy = new Incremental(5, TimeSpan.FromMilliseconds(500), TimeSpan.FromMilliseconds(3000));
RetryPolicy retryPolicy = new RetryPolicy<SqlDatabaseTransientErrorDetectionStrategy>(retryStrategy);
retryPolicy.ExecuteAction(() =>
{
//
// Try to connect to the database
//
using (insertConnection = new SqlConnection(m_ConnectionString))
{
//
// Open the connection
//
insertConnection.Open();
//
// Get the insert command ready
//
using (SqlCommand insertRecordCmd = insertConnection.CreateCommand())
{
//
// Define the Insert command
//
insertRecordCmd.CommandText = @"
BULK INSERT dbo.[PropertyDefinition]
FROM '//my file path'
WITH(
FIRSTROW = 2,
FIELDTERMINATOR = ',',
ROWTERMINATOR = '\n'
)
";
// Execute the INSERT command
insertRecordCmd.ExecuteNonQuery();
}
insertConnection.Close();
}
});
}
catch (Exception ex)
{
//
// This is unexpected so display full exception information
//
m_Log.WriteLine("Exception while creating table");
m_Log.WriteLine(ex.Message.ToString());
throw;
}
}
バルク一時テーブルにインポートし、あなたがあなた自身のテーブルを更新するために、そのテーブルから必要なだけの列を使用しています。 –
それは一つの選択肢です。これでは難しいかもしれないのは、データベースを再公開して新しいテナントを作成することによって、このテーブルを継続的に更新しようとしている場合だけです。 – Tim
私は基本的に、私たちの会社の別のチームにcsvファイルを送ります。彼らはいくつかのデータを更新し、ファイルを私に送り返して、そのデータを現在のテーブルに単純にインポートできるようにしたいと考えています。 – Tim