Home Forums SQL Server 2008 T-SQL (SS2K8) How to script table data with either TSQL or Powershell? RE: How to script table data with either TSQL or Powershell?

  • Hi There,

    I usually do not promote products; However, red gates source control software plug in allows you to save data into SVN. This data then can be restored with the schema to another database.

    http://www.red-gate.com/products/sql-development/sql-source-control/entrypage/5-minutes?utm_source=google&utm_medium=cpc&utm_content=unmet_need&utm_campaign=sqlsourcecontrol&gclid=CLja-ZvqxbYCFcXe4AodyHEAAg

    If you do not have the money to spend, BCP the data out/in using your favorite text format. Check out my blog showing how to do this.

    http://craftydba.com/?p=1584

    Microsoft even does this with the Adventure Works install script using a CSV format. I like a tilda ~ or fixed format since tabs do occur in unclean data.

    BULK INSERT [Person].[ContactType] FROM '$(SqlSamplesSourceDataPath)ContactType.csv'

    WITH (

    CHECK_CONSTRAINTS,

    CODEPAGE='ACP',

    DATAFILETYPE='char',

    FIELDTERMINATOR='\t',

    ROWTERMINATOR='',

    KEEPIDENTITY,

    TABLOCK

    );

    Good luck

    John

    John Miner
    Crafty DBA
    www.craftydba.com