Export tables in SQL Server 2005 - database

In SQL Server 2000 you had DTS where you had the option to choose to export table structure along with data and also to choose specific tables only. Is there a similar option in SQé Server 2005 version.
I would like to export just 5 tables along structure and data from an existing database to another database. The data is required as it contains auto increment id fields that are maintained as foreign keys.

Use right mouse click on your database >> tasks >> generate scripts
After a few times 'next', you can select the tables from which you want to export the structure.
To export the data, you can:
Right mouse click on your database >> tasks >> export data
or copy/paste from/to table data view

Yes, of course - the DTS-equivalent in SQL Server 2005 and up is SQL Server Integration Services (SSIS).
You'll find that in your start menu under the SQL Server tab called Import and Export Data.
If you need to do this operation often, you might also want to look at the bcp (bulk copy) command line tool for doing this kind of thing. This allows you to wrap the operation into a batch file and execute it regularly or on demand.

SSMS has a facility to do this available from the object explorer (somewhat counter-intuitively this is not available within BIDS). This invokes a wizard that generates an SSIS package that can export one or more tables to another database.
Right click on the node in the SSMS object explorer, select Tasks->Export Data and this will invoke the export data wizard. The rest it pretty self-explanatory.

Related

How to export result of SQL server - "New Data Comparison" to an Excel file?

I am using Visual Studio 2017.
Functionality - Open Visual Studio - Go to Tools - Click SQL Server -
New Data Comparison
After mentioning source and target database and running the tool, I get results -
(Different Records, Identical Records)
Is there a way to export this data result to Excel?
Harshit Virdi has noted he has access to Microsoft SQL Management Studio. There are two easy ways I know of to export results into Excel:
Option 1 the "right click on your results" option:
Run your query like normal in Microsoft SQL Management Studio. Then right click on the results like this:
.
Choose "Save Results As..." and if you pick CSV (comma separated value) you'll be able to open that in Excel.
Option 2 would be to Export from a table or view directly. Right click on the database (not the table) you want to export from, choose tasks, and Export Data...:
A wizard will appear (ha!)
Choose your Data Source (SQL Native Client)
Pick your server and database
Choose your Destination
Select Excel, and pick a path. I keep it at Excel Version 97-2003 but you can try different ones
Now you can choose to either write a query or pick a table, the choice is yours!
Hit next and finish it up and boom, you have your data in Excel.
The export data wizard is rather powerful, you can also transfer data between servers very fast and easily. It's a tool worth learning more about. You may have noticed on the last steps of the wizard you can save your 'code' as an SSIS package. That way you could run the same export again, or automate it. However that goes beyond the scope of this question. Good luck!

Equivalent of Oracle export for SQL Server and/or db2

Can SQL Server or db2 do entire database exports like oracle (using exp command)?
I've searched the internets and found bcp for SQL Server. But it seems I would have to iterate over all the tables to get what I want.
For db2 it looks to be roughly the same. Is there something I'm missing? Anyone have any suggestions and/or any opinions? Thanks ahead of time.
This is for SQL SERVER
Backup & Restore
To take an entire database with SQL Server, you can do a BACKUP and RESTORE
BACKUP: http://msdn.microsoft.com/en-us/library/ms186865.aspx
RESTORE: http://msdn.microsoft.com/en-us/library/ms186858.aspx
Export and Import
You can right click a database in SQL Server Management Studio, and under TASKS, click on EXPORT DATA. Follow the Wizard to choose the objects you want to export and put them into the appropriate location.
Custom SSIS for Raw format
Build a SSIS package that will read data from source table and put it into a RAW file on disk for later use. Raw files holds the structure of the table and the data.
DB2 for Linux, UNIX, and Windows has a utility called db2move, which generates the DDL to rebuild the database from scratch, and iterates through all the tables to dump their contents to flatfiles via the EXPORT command.

SQL dump of users tables Gmed emr

I am working for a company that uses Gmed EMR. Gmed lacks some features that my client requires and I have had to build an external secure web based application to fill in. Gmed runs on Microsoft SQL server. I have access to the server, but I've never used Microsoft SQL server before. How can I safety SQL dump the users tables? Should I even try this?
To get a dump, do the following (OTTOMH):
Open SQL Server Management Studio
Right click on your database
On the menu go to TASKS and then GENERATE SCRIPTS then click NEXT
Choose "Specific Objects"
Choose the tables that you want
In the options make sure you choose the option for SCRIPT DATA
Choose to put it into a script or a window and click FINISH
This will give you a script to create the table, as well as the INSERT statements for data.
If you want just the data dump, you can right click a database and choose to EXPORT data.
It depends on the format you want them in. It's pretty easy to export to a text file. Open SQL Server Management Studio (the GUI), right-click the database you want to export from, then click Export Data. It's a straightforward wizard that lets you select what tables or other objects you want to export, and in what format or to what file.

How can i export table data with column name in text file in sql server 2005?

How can i export table data with column name in text file in sql server 2005?
safest way to do that is to backup data and then restore it on other server!
right click on database in ms sql management studio>tasks>backup , choose directory to backup the file. Zip it ( saves a lot of space) move to other location, create database with the same name right click on database>tasks>restore.
In backup and restore always choose overwrite in options menu otherwise it will be appended to existing dataset.
Other way to do that is right click on database, tasks, export data and move it to another location. more advanced though, backup works faster and you supposed to use it unless you want partial move, like some tables and some stored procedures.
If it's a small amount of data, you can upgrade your Management Studio to SSMS 2008 (you do not need to upgrade your server). The Results tab has the ability to copy data with headers, so you can cut and paste into Excel.
A larger amount of data can be extracted in several ways such as an SSIS package, the Import/Export wizard, or doing a pull through ODBC from Excel.
You can do this using an SSIS package.

Copy table to a different database on a different SQL Server

I would like to copy a table from one database to another. I know you can easily do the following if the databases are on the same SQL Server.
SELECT * INTO NewTable FROM existingdb.dbo.existingtable;
Is there any easy way to do this if the databases are on two different SQL Servers, without having to loop through every record in the original table and insert it into the new table?
Also, this needs to be done in code, outside of SQL Server Management Studio.
Yes. add a linked server entry, and use select into using the four part db object naming convention.
Example:
SELECT * INTO targetTable
FROM [sourceserver].[sourcedatabase].[dbo].[sourceTable]
If it’s only copying tables then linked servers will work fine or creating scripts but if secondary table already contains some data then I’d suggest using some third party comparison tool.
I’m using Apex Diff but there are also a lot of other tools out there such as those from Red Gate or Dev Art...
Third party tools are not necessary of course and you can do everything natively it’s just more convenient. Even if you’re on a tight budget you can use these in trial mode to get things done….
Here is a good thread on similar topic with a lot more examples on how to do this in pure sql.
SQL Server(2012) provides another way to generate script for the SQL Server databases with its objects and data. This script can be used to copy the tables’ schema and data from the source database to the destination one in our case.
Using the SQL Server Management Studio, right-click on the source database from the object explorer, then from Tasks choose Generate Scripts.
In the Choose objects window, choose Select Specific Database Objects to specify the tables that you will generate script for, then choose the tables by ticking beside each one of it. Click Next.
In the Set Scripting Options window, specify the path where you will save the generated script file, and click Advanced.
From the appeared Advanced Scripting Options window, specify Schema and Data as Types of Data to Script. You can decide from here if you want to script the indexes and keys in your tables. Click OK.
Getting back to the Advanced Scripting Options window, click Next.
Review the Summary window and click Next.
You can monitor the progress from the Save or Publish Scripts window. If there is no error click Finish and you will find the script file in the specified path.
SQL Scripting method is useful to generate one single script for the tables’ schema and data, including the indexes and keys. But again this method doesn’t generate the tables’ creation script in the correct order if there are relations between the tables.
Microsoft SQL Server Database Publishing Wizard will generate all the necessary insert statements, and optionally schema information as well if you need that:
http://www.microsoft.com/downloads/details.aspx?familyid=56E5B1C5-BF17-42E0-A410-371A838E570A
Generate the scripts?
Generate a script to create the table then generate a script to insert the data.
check-out SP_ Genereate_Inserts for generating the data insert script.
Create the database, with Script Database as... CREATE To
Within SSMS on the source server, use the export wizard with the destination server database as the destination.
Source instance > YourDatabase > Tasks > Export data
Data Soure = SQL Server Native Client
Validate/enter Server & Database
Destination = SQL Server Native Client
Validate/enter Server & Database
Follow through wizard

Resources