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
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
- Install SQuirreL SQL
- Make sure you have JRE7 installed on your machine
- 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)
- Start the connection session to you database
- Select your alias and hit the Connect icon
- Write you select statement and run it (CTRL+ENTER)
- Bring up the Tools dialog box (CTRL+T)
- Look for sql2ins and hit Enter
- 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.
Thank you!
ReplyDelete