Generating INSERT statement from SELECT using SQuirreL SQL

There are often time during development where you would want to test your application with various type of sample data, and you would want those data to be share with other team member as well.

The scenario that I ran into recently is we have some sample data that was enter to a system through a web interface, and for reports developments purposes we need those data to be shared among the team members, so we start to look into exporting those data out using SQL SELECT statements (with the correct WHERE clause) then converting them to equivalent INSERT statement; there are of cause several ways to do this, but I prefer the easy way, using SQuirreL SQL. The insert script can them be shared among the team members.

Following is the steps for completing this

  1. Install SQuirreL SQL
    • Make sure you have JRE7 installed on your machine
  2. Create connection to you database
    • Depending on your database type you need to use different drivers
    • Create the Alias to your database and enter the right connection strings (this can be tricky sometime)
  3. Start the connection session to you database
    • Select your alias and hit the Connect icon 
  4. Write you select statement and run it (CTRL+ENTER)
  5. Bring up the Tools dialog box (CTRL+T)
  6. Look for sql2ins and hit Enter
  7. Done. You will see INSERT statement will be generated right after your SELECT statements.
You can customize what columns you want on the generated INSERT statement by only specifying them in the SELECT statements, and don't forget you can also limit the records by specifying the where clause in your SELECT statements.

There you go, another magic trick.

Comments

Post a Comment

Popular posts from this blog

OneNote: We need the password to sync this notebook (Error code: 0xE4010643)

Fixing the AKE BC398 USB3.0 sluggish performance