I have a database with a table Customers that have some data
I have another database in the office that everything is the same, but my table Customers is empty
How can I create a sql file in SQL Server 2005 (T-SQL) that takes everything on the table Customers from the first database, creates a, let's say, buildcustomers.sql, I zip that file, copy it across the network, execute it in my SQL Server and voila! my table Customers is full
How can I do the same for a whole database?
-
You could always export the data from the Customers table to an Excel file and import that data into your Customers table.
To import/export data:
- Right click on database
- Go to Tasks
- Go to Import Data or Export Data
- Change the data source to Microsoft Excel
- Follow the wizard
From Bryan Roth -
There was a question about this yesterday, and the best solution was the Database Publishing Wizard.
From Forgotten Semicolon -
If you're using Visual Studio 2008 Team Edition for Database Professionals, this can be done with a simple wizard:
http://msdn.microsoft.com/en-us/library/aa833411(VS.80).aspx
From Slavo -
Backup and Restore work well for this, as well as detach and attach database.
From JasonS -
If both databases resides in the same instance of SQL Server, ie use same connection, this SQL might be helpful:
INSERT INTO [DestinationDB].[schema].[table] ([column]) SELECT [column] FROM [OriginDB].[schema].[table] GO
From Nordin -
bcp (from the command line) to a networked file and then restore it.
e.g.
bcp "SELECT * FROM CustomerTable" queryout "c:\temp\CustomerTable.bcp" -N -S SOURCESERVERNAME -T bcp TargetDatabaseTable in "c:\temp\CustomerTable.bcp" -N -S TARGETSERVERNAME -T
- -N use native types
- -T use the trusted connection
- -S ServerName
Very quick and easy to embed within code. (I've built a database backup(restore) system around this very command.
qntmfred : oh this is perfect. scriptable, flexible, well-supported and very fast. thanks!From Unsliced -
Another way would be to use Redgate's excellent SqlCompare tool
From edosoft -
This functionality is already built in to Sql Server Management Studio 2008.
Just download the trial and only install the client tools (which shouldn't expire). Use Management Studio 2008 to connect to your 2005 database (its backwards compatible).
- Right click your database
- Choose Tasks > Generate Scripts
- Press Next, select your database again
On the 'Choose Script Options' screen, there is an option called Script Data which will generate SQL insert statements for all your data.
Alan : great answer - thanksqntmfred : is this functionality available via command line?From The Matt
0 comments:
Post a Comment