Select existing data from database to create test data - sql-server

I have a SqlServer database that I've manually filled with some test data. Now I'd like to extract this test data as insert statements and check it in to source control. The idea is that other team members should be able to create the same database, run the created insert scripts and have the same data to test and develop on.
Is there a good tool out there to do this? I'm not looking for a tool to generate data as discussed here.

If you want a light-weight solution, I would recommend sp_generate_inserts. It is a store procedure you can create on your DB and pass in a variety of arguments to generate insert statements of all the data in the target table.

EMS DB Extract for SQL Server (http://www.sqlmanager.net/en/products/mssql/extract) seems to do what you want, and it seems to be free.
Hope this helps,
Robin

Red-Gate SQL Data Compare will do this. Just create a blank data base with the same schema, and run a compare against the original and the blank database. It will generate scripts to insert all of your test data.

This works http://www.sqlscripter.com/
New version of SQL Scripter (V2.1) was released last month.

Related

SQL Server stored procedure script

I am wondering if I can modify a generated script to copy data from 1 database to another. I used the "Generate scripts" tool and can I then take the latest run each time and create a stored procedure to then take latest tables and insert that into new database?
Source tables have an extension of _dateinfo. So table called ABC_05162016 would be on next run table ABC_06162016. Is there a way to take the original generated script and then update that last part 1 time instead of constantly selecting all the tables every time this is needed to be done?
Thanks for the help. Yes I have looked around for an answer to this but have not come across something like this. All deal with importing/exporting data or using Generated Script part. Thanks for the help.
If there is a better way then those 3 ways. I would appreciate knowing that as well.
Using SQL Server 2008.

Create a Trigger to output/append mssql results to a file

I'm using mssql and I want to create a trigger to append any added data from a table to a file. I'm using express so using the wizard is not an option since it does not save in express edition. The table is small and does not receive data often. The table essentially is used to log notes on a products life test. More or less I want the results in a file for our team and or customers. Thanks in advance for any help on the matter.

Reverse Engineer Access DB

I was wondering if anyone knew how to reverse engineer an Access Database. I would like to be able to generate the SQL code that is used to create the database tables and to insert all the records in the table. In other words, I would like to create whats is similar to a MySQL dump file.
Any ideas would be great
thanks
jason
There's nothing built into Access that will generate the DDL for your tables.
There are many third party tools however (ERWin, ERStudio, Visio, etc) that can generate the DDL for you.
I don't know anything that will generate the Insert scripts for you. Access does however have plenty of export/import options if you just want to create a copy of your data and then use that as an import source.
It should be pointed out that there's nothing stopping you from writing some VBA code to loop through the TableDefs and creating the DDL and insert scripts yourself.
One possible approach that may work, is to upsize your tables to SQL server, and then have SQL server generate scripts for you.
Unfortunately the resulting scripts would probably be only compatible with SQL server. So then you would have to run them on SQL server and then pull the data in tables down to access.
Access does support DDL, but unfortunately it does not have any tools are facilities built in to generate the scripts.

Script data in one table on one server and insert into the same table in another server

I have a table on my QA Environment. I want to copy the data from that table to the same table in another environment. How can I do this??
The best way would be to use a tool specifically designed for this - Red-Gate SQL Data Compare.
It costs a little bit - but it's worth every penny ! It will save you loads of grief and time - it can easily compare two existing database tables, and copy only those rows that are new (or have changed). You can work from a SQL backup file, too - excellent stuff. Check it out!
I assuming you want two table with same data. You can use SSMS Import Data function.
http://msdn.microsoft.com/en-us/library/ms140052.aspx
The easiest method is to use an SSIS package.

How to export tables from sql server to ms access on the fly?

I would like to publish some data of a sql server 2k to msaccess databases.
I'd like to do that given a table supplying datatransformation info, for example :
tablenameOnServer | pathToPub
------------------------------------------------------
Clients | D:\Data\Pub1\ClientData1.mdb
Orders | D:\OtherData\Pub\Sales.mdb
The given mdb file should be created (or an empty one copied of course) and the table should be created each time the script runs.
I of course don't need a full blown solution, but some pointers as where to start are very welcome. I thought I'd use SSIS for this, but am new to it and I like to know where I start best in order to avoid too much loss of time :
Do I use SSIS with BIDS (vs2008), can I read data in a package and create tables on the fly?
Do I use C# and manipulate and create packages in code?
Or what do I do best? Is SSIS the obvious solotion anyway?
In any case : some pointers to get me started would be very welcome...
UPDATE : This question is about publishing data, so it can be shipped on CD for example. It's not about linking to an sql server.
The simplest solution is to simply link the sql server table in access. Then you can see the data in realtime.
You can create an Access database to do this fairly easily.
Here is a basic algorithm
Within access, create a linked table pointing to your table.
create an Access query to filter data according to your criteria called NewQuery
Use VBA to create new database NewDB
export your NewQuery with structure and columns to the NewDB
If you want to keep the SSIS packages, I would make a template SSIS package and then using the SSIS objects from C# create the packages. I've done this to start off packages which are later customized.
Alternatively, if you aren't going to keep the packages after they are generated and aren't going to use a lot of SSIS features (logging etc.), I would consider doing the whole thing from C# (or other language), because SSIS isn't a great tool for connection managers (source or destination) which change.
From C#, you can simply read the schema, create the table in Access with matching types and columns and populate it.

Resources