mysqldump equivalent for SQL Server - sql-server

Is there an equivalent schema & data export/dumping tool for SQL Server as there is for MySQL with mysqldump. Trying to relocate a legacy ASP site and I am way out of happy place with working on a windows server.
Note: The DTS export utility own seems to export data, without table defs.
Using the Enterprise Manager and exporting the db gets closer with exporting the schema & data... but still misses stored procedures.
Basically looking for a one does it all solution that grabs everything I need at once.

To do this really easily with SQL Server 2008 Management Studio:
1.) Right click on the database (not the table) and select Tasks -> Generate Scripts
2.) Click Next on the first page
3.) If you want to copy the whole database, just click next. If you want to copy specific tables, click on "Select Specific Database Objects", select the tables you want, and then click next.
4.) "Save to File" should be selected. IMPORTANT: Click the Advanced button next to "Save to File", find "Types of data to script", and change "Schema only" to "Schema and data" (if you want to create the table) or "Data only" (if you're copying data to an existing table).
5.) Click through the rest and you're done! It will save as a .sql file.

The easiest way is the sql server database publishing wizard.
Open source
Free
Does exactly what you want
Developed by microsoft
It does not have all the features of mysqldump but it is close enough.
http://www.codeplex.com/sqlhost/wiki/view.aspx?title=database%20publishing%20wizard

The easiest way to move a Database would be to use SQL Server Management Studio to Export the database to another server, or if that doesn't work, make a backup like other's had suggested and restore it elsewhere.
If you are looking for a way to dump the table structure to SQL as well as create insert scripts for the data a good free option would be to use amScript and amInsert from http://www.asql.biz/en/Download2005.aspx.
If you want a good pay version I would check out Red-Gate SQL Compare and Red-Gate SQL-Data Compare. These tools are probably overkill though and probably a bit pricey if you don't intend to use them a lot. I would think it would mostly be relegated to DBAs. You can look at the Red-Gate tools at http://www.red-gate.com/.

Not finding the right tool, I decided to create my own: a sqlserverdump command line utility. Check it out on github.

Even easier is to use the SMO API. It lets you do exactly like mysqldump, and even better. Here is a code example:
http://samyem.blogspot.com/2010/01/automate-sql-dumps-for-sqlserver.html

easiest would be a backup and restore or detach and attach
or script out all the tables and BCP out the data then BCP in the data on the new server
or use DTS/SSIS to do this

SQL Enterprise manager or SQL Server Management studio have wizard based approaches, and the latter will generate the scripts so you can see how its done.
You could also use the BACKUP and RESTORE commands. More detail here: http://msdn.microsoft.com/en-us/library/ms189826.aspx

If you can get DTS or Integration Services to connect to both servers, you can use the wizards to 'copy objects' from one server to another. 'Copy Database' requires that the two servers can authenticate with each other, which typically means being on the same domain and that the service runs under a domain logon.
Otherwise, you can generate a script for the schema, and you can use an Integration Services/DTS package to export data to a file, then import it on the other.
We now generally use SQL Compare and SQL Data Compare. Red Gate's SQL Packager might also be an option.

Well, Mysqldump is a series of SQL statements. You can do this with DTS, but why not just create a backup and restore it on your new machine?
If you want to do it via SQL:
http://msdn.microsoft.com/en-us/library/aa225964(SQL.80).aspx
Or just right click the DB and hit Tasks -> Backup (http://msdn.microsoft.com/en-us/library/ms187510.aspx)

Two things a backup/restore won't do:
Get off of a Microsoft server, which
was part of the original question
Help quickly find a structural difference
between two DBs that are supposed to
have the same structure when one of
them is running slowly. Unix diff,
or sdiff, ignoring white space but
need a way to make input files.

If you need equivalent SQL statements like CREATE TABLE... & INSERT INTO..., then I recommend you try HeidiSQL. It's a fantastic and free utility that can access Microsoft SQL Server, MySQL and PostgreSQL. It enables you to browse and edit data, create and edit tables, views, procedures, triggers and scheduled events. Also, you can export structure and data to SQL file.
http://www.heidisql.com
Go to Tools / Export database as SQL and select the schema.
Check the box to create the tables and “Insert” data. That’s it.
I prefer HeidiSQL to "Microsoft SQL Server Management Studio" or phpMyAdmin... etc.

Related

Duplicate localDB under SQL Servers on my laptop

I've been running into an issue recently when I attempt any tutorials that involve using a SQL database, entity framework, dapper, etc.
When it comes time to publish a database, or utilize an ORM, I'm given duplicate options for the same localdb under SQL Servers. Furthermore, then I attempt to publish, the database doesn't show up under the localdb that I've chosen.
I'm wondering how I go about removing the other SQL Servers and just having the one available.
If you look at the image below, the Browse option gives me two of the same LocalDbs. Plus I also get a 3rd one under \ProjectModels. I'm wondering what's causing this and how it can be fixed since no matter which one I choose, the sql database I attempt to publish doesn't show up within any of them.
My advice is not to use this method to publish the database. (right click to delete)
Please refer to this official documentation.
File-based databases like SQLite or SQL Server Express are designed to store their data in easily transferable files that can be served with your application/site.
"Copy to Output Directory" Property of the database file to "Copy if newer". Just point the address to it.
If you are using a server-based database like SQL Server, MySQL, etc., you need to make sure that the target machine/environment has the same database server installed, and you need to write a deployment script to append the pre-populated data files to the server. This might be troublesome for you.
You can also refer to these links. 1,2,3

How do I convert Microsoft Access file into SQL Server database?

I want to know how to convert an Access database file into a SQL Server (.mdf file) database?
The MS Access "Upsize Wizard" was discontinued with Access 2012. SQL Server Migration Assistant (SSMA) is now recommended. Reference: https://accessexperts.com/blog/2013/01/30/access-2013-is-here-but-wheres-the-sql-server-upsizing-wizard/
However, as Johnny Bones noted, I found it relatively easy to create a new empty SQL Server (2012) database and then import:
SQL Server Management Studio, R-click on the newly created Database | Tasks | Import Data -> SQL Server Import Wizard
I used "Access Database Engine" instead of "Jet Database Engine" for
no reason other than I GUESSED Jet was older. Mine is a throw-away
project you may want to research the difference.
I 'weeded out' the
Access queries (views) and just imported the tables.
So far it looks
like everything was imported OK.
The simple answer is; you can not "convert" an Access database to a SQL database. You can, however, import the Access database (tables only) into SQL. Remember that SQL is a true database, and, as such, contains no front end or GUI creation mechanisms. You will still need Access (or C# or VB or another front-end builder) to create the interface.
You may already know this, but in SQL Server a Query is called a View, and Modules are called Stored Procedures. You will need to convert your Access queries and modules accordingly if you're planning on having that all reside server-side.
It's actually pretty easy to import Access tables into SQL Server, you would just create a database on a server, right-click on the database name and choose Tasks --> Import Data. There you will choose Microsoft Access as your Data Source. The rest should be pretty self-explanatory.
JonnyBones wrote a good full answer. Other have made suggestions for tools which may work. However, the SSMA (SQL Server Migration Assistant) is likely to be the best option now. (See this youtube video for help with understanding some of the issues to overcome and an explaination of how to use SSMA.
Befre you consider using other tools, which may do more, you should find out why to use them instead of SSMA. Check out the youtube video as a starting point.
Be aware that the MS Access Upsizing wizard was great but is now discontinued, and there was a bit of a gap before MS created a decent version of SSMA, which is when&why these other tools came into existence.
SSMA should do what you need.
There are some access things that do not get moved to SQLServer and some that do.
eg Access triggers do not. Access tables constraints do, Access boolean datatypes so - of sorts - but you need to do some work. The video will explain most issues well.
Harvey
You can try with the Upsize Wizard or copy content of the table from SHOW TABLE DATA and paste to the target table with the same structure as the source.

How to copy data and database tables from one database to another

Is there any way that I can copy all the data and database tables (and other objects) from one server table to other server?
To make those things as automated. so that every time we used to get that production data to my local database.
Thanks
You could also try out ApexSQL Script, a database migration tool, to script objects and data from one instance and execute it on another instance.
Also you can use ApexSQL Diff and ApexSQL Data Diff, SQL schema and data compare tools, to copy structure and data from a source to destination.
Disclaimer: I work for ApexSQL
Hope this helps
You could:
backup and restore the database
detach and re-attach the database
use tools like Red-Gate SQL Compare for structural and Red-Gate SQL Data Compare for data comparison and syncing
you could roll your own, using SQL statements and/or SMO (SQL Server Management Objects)
probably a gazillion other ways to do this.....
You can use SSIS import and export to do that.
It asks for the source server name, source dbName and Destination server name, destination dbName.
OR
you can use the back-up and restore process.
But I always prefer SSIS.
Alright, I found it, completely in visual studio. This can be from local (.mdf) files to server files and visa versa.
Go to Sql Server Object Explorer and find your source database. Or in Server Explorer, right click on your source database and click on Browse in Sql Server Object Explorer
When in Sql Server Object Explorer, right click on your source database and click on Data Comparison
A dialog will popup, showing you a Source Database and Target Database. Your Source Database should already be selected. Now select your Target Database, you probably have to add a new connection, just do it like you would usually do in Server Explorer. If you want the target database to be a local (.mdf) file and you cannot click on Change, than add it first to the server explorer and it will popup in the combobox.
Choose what you want to compare by checking the checkboxes and click next.
It will connect to the servers and show you another dialog what to compare, check the checkboxes and click on Next.
Here you will have an overview of your changes from source to target.
At this point, you will be able to kind of 'mirror' the source database with the target database. For instance: If you have added more records to the Target database then there are in the source database, then these records will be deleted once you click Update Target Take a close look at what will happen when you hit that button!
If you are satisfied with the result, click Update Target. If you are not satisfied, next to the button there is a little icon to export it to a .sql file, so you can modify what will happen to the target database.
Unfortunately, after writing this, I found out that this is only available in VS Ultimate and Premium, that is what they say on the following link about visual studio 2010, I have tested this in Visual Studio 2015 Enterprise.
MSDN: https://msdn.microsoft.com/en-us/library/aa833428(v=vs.100).aspx
I suggest you to take a look at "Visual Studio 2010 SQL Server Database Project". It provides you with great features to manage database team work. It allows you to create a local database and import the production database into the local database. From now on, you and your team can work on local database and when you are ready to deploy your changes to production database, Visual Studio 2010 synchronizes the local database with production database, So the production database will get the latest changes.
you can create a DTS job to copy database and its contents on timely basis.
http://msdn.microsoft.com/en-us/library/cc917688.aspx

Tool to copy SQL Server 2008 db to SQL Server 2008 Express?

I have a typical dev scenario: I have a SQL 2008 database that I want to copy every so often to my local instance of 2008 Express so that I can do dev, make changes, etc. to the local copy. I have some constraints though: the source db is part of a live e-commerce site in shared hosting so I can't detach it and the hosting service wants me to pay $5 for each ad hoc back up I invoke.
What I'd like is some tool that I can invoke ad hoc to take a snapshot (complete, not incremental) of the live db that I can then import in my local one. I've tried the SSMS 2008 Copy Database Wizard but it gives me an error saying I can't do that with Express. I tried the Generate Scripts tool and thought that was going to make it - the export to my local disk worked but when I went to import using SQLCMD (the script was 1GB so SSMS errored when I tried to open it there), it told me there was a syntax error a few thousand lines in.
Coming from the MySQL world, this process is trivial. All I want is an analog of mysqldump and then a command-line way to import that file into a db. Surely there's an easy way to do this in the SQL Server world? This seems like the most basic use-case for developers.
[ Yes, I've seen a few other questions here that seem similar but I didn't think they had the same constraints. ]
Best answer: full backup, restore, pay $5. Anything else seems to me like it'd waste a lot more than $5 worth of time.
If they don't charge you to run queries against the database these tools may help. Granted these are not free tools, but are handy on so many fronts it would be worth buying one. These tools can diff your source db and target db both data and structure or just one or the other, and optionally sync the target database to be just like the source.
http://www.innovartis.co.uk/
http://www.red-gate.com/products/sql%5Fdata%5Fcompare/index.htm
Try SQL Dumper.
SQL Server Dumper enables you to dump selected SQL Server database tables into SQL INSERT statements, that are saved as local .sql files and contain all the data required to create a duplicate table, or to be used for backup purposes. You can choose to create an individual .sql file for each table, or combine all selected tables into a single file.
SQL Server Database Publishing Wizard and osql usually do the trick for me with large databases.

Restore SQL Server 2008 database to SQL Server 2000

I have to move an entire database from a SQL Server 2008 machine to a SQL Server 2000 machine.
I created a backup using Management Studio 2008, copied it to the hard drive of the 2000 box, and from withing Management Studio 2008, I choose Restore Database to the 2000 box.
I get an error message stating, "The media family on device ... is incorrectly formed. SQL Server cannot restore this media family".
If I use Enterprise Manager 2000 I get the same error.
Is there a way to move a whole database from the newer SQL server to the older?
The only thing I can think of is to recreate the whole structure and then copy data from a live database. So, create scripts that will create the tables, views, and sp's, and then create scripts to copy the data from the existing database.
As others already said there is no default way to do this. It’s just not supported. Here are more extensive details on how to do this properly and avoid any migration issues.
You need to generate scripts for structure and data and then execute these on SQL 2000 (like others already said) but there are couple things to take into account.
Generate scripts in SSMS
Make sure to check option for scripting data for SQL 2000 to avoid issues when trying to create something like geography type column on SQL 2000.
Make sure to review execution order of scripts to avoid dependency based errors
This is a great option for small to medium size databases and requires some knowledge of SQL Server (dependencies, differences between versions and such)
Third party tools
Idea is to use third party database comparison tools such as ApexSQL Diff or Data Diff
Good side is that these will take care of script execution and differences between versions
Not so good is the fact that you’ll need to pay for these after trial ends
I’ve used these two tools successfully but you can’t go wrong with any other tool on the market. Here is a list of other tools in this category.
you can't move backups from a newer version to an older, in that case you can script your database, execute it in the 2000 box, then you can use the standard data transfer to transfer any data you want
Provided you have a network connection between the machines use SSIS. Much easier and a lot less messing around.
You can use Script Generator for your database and then select in the properties form : General-> Script for server version : SQL Server 2000.
The script generator will show you things which not compatible with your server version.
I've heard you can only do it by generating the SQL statement dump from the DB administrator tool and re-running those queries on the target older database.
You can generate a script that will recreate all the objects and transfer all the data...as long as everything in the db is valid in SQL 2000. So no ROW_NUMBER(), no PARTITION, no CTEs, no datetime2, hierarchy or several other field types, no EXECUTE AS, and lots of other goodness. Basically, there's a pretty good chance it's not possible unless your db is pretty basic.
We got a similar situation. A very low-tech but handy solution is:
backup and truncate the tables in SQL 2000.
create a LINKED server in SQL 2008, pointing to SQL 2000
run a select query at sysobjects to generate a query script for insert into LINKED SERVER.table select * from table
execute query script.

Resources