Converts a CSV file into a set of SQL insert statements and executes them against a database as follows:
- The table name will be the file name, excluding the CSV extension. If the table is in a non-default schema, add the schema name to the file name, like this:
- The column names will be drawn from the first row of the CSV file. Column names will be enclosed in square brackets in the rendered SQL, so odd column names are still valid.
- All values will be inserted as text, with any single quotes escaped. The system relies on implicit conversion to the table column’s native type.
- The system performs no checking around nonexistent column names, invalid types, primary key collisions, etc. Any of these will produce a SQL error. Caveat emptor.
This cmdlet was written to facilitate the insertion of setup data using the
-SetupSql parameter of cmdlet
Test-MedmComponent. If a CSV file is properly named and articulated as described above, simply reference it in the
-SetupSql parameter and it will be loaded.
Combined with the test data generation offered in cmdlet
Export-CsvTestData, this is a far more efficient method of creating and maintaining test data than as a set of actual SQL insert statements.
Import-CsvTable ` [-DbServer <string>] ` [-DbName <string>] ` -CsvPath <string>
|The target SQL Server database server address.
|The target SQL Server database name.
|*||The path to the CSV file to be loaded. Relative paths will be resolved relative to the script execution path.