Insert Script for all the tables in a database

  • Please help me get the insert scripts for all the user tables in a database.

    "More Green More Oxygen !! Plant a tree today"

  • To do that automatically you can either buy a tool like Embarcadero Rapid SQL that will do it for you, write a program using SMO to walk each table generating the script, or try writing a series of cursors in TSQL to generate the scripts. There are a bunch of scripts already built in the Scripts section of this site (see the "Scripts" on the left) that do this. Here's one example[/url] (first one I saw, there are others).

    For one-off scripts, simply right click the table when in SSMS and select "Script Table as" then "INSERT To" to generate a script.

    ----------------------------------------------------The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood... Theodore RooseveltThe Scary DBAAuthor of: SQL Server 2017 Query Performance Tuning, 5th Edition and SQL Server Execution Plans, 3rd EditionProduct Evangelist for Red Gate Software

  • SQL Scripter is a free tool to dynamically create INSERT scripts. It works fast and well.

    http://www.sqlscripter.com/

  • you can get SSMS to script them all by using the Generate scripts option under "all tasks". Simply right-click on the DB name to get started.

    ----------------------------------------------------------------------------------
    Your lack of planning does not constitute an emergency on my part...unless you're my manager...or a director and above...or a really loud-spoken end-user..All right - what was my emergency again?

  • Thanks to all of you. I got the script from SQL Servercentral scripts and it worked perfectly.

    😀

    "More Green More Oxygen !! Plant a tree today"

  • Hi,

    Check out the belwo link

    http://mallier.blogspot.com/2006/10/generate-insert-statement-in-sql-server.html

    Thanks -- Vj

  • Is there a way to generate select, insert, drop, update scripts in SMO ?. I know that "create script" can be generated in couple lines ..

    Dim tr As Table = server.Databases("db").Tables("tbl", "dbo")

    For Each st As String In tr.Script()

    File.AppendAllText("C:\auto.txt", st & ControlChars.NewLine)

    Next

Viewing 7 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic. Login to reply