I was wondering if there is a safe/clean and efficient way to transfer data from one MSSQL DB to another on following terms:
both DB's have exactly the same structure.
I need to be able to choose from which tables I'll export data, and then drop the data from new new table.
So it would look like this:
drop data from beta DB
insert data into DB from old DB
Does MSSQL has some sort of import/export wizard or some sort of tool which could help me with this ?
There is a built-in wizard for data import/export in Sql Server Management Studio:
right click on you DB
click "Tasks"
select "Import data..." or "Export data..."
here you can select a source and a destination for you data transfer operations (for example you can chose SQL Server DBs as source and destination and transfer data from tables in the old DB to the same tables in the new DB), but I think that you'll need to write your own script to drop old data
Here is a screenshot that shows how to open this wizard:
Related
I want to transfer multiple tables and their data from one SQL Server to another SQL Server on the local network automatically every 1 hour.
There is a tool built-in tool in SSMS to do this.
In SSMS, right click on the database name. Select Data > Import on the destination database. You will be prompted to provide connection information for the source database. This is internally using SSIS integration tool.
Create a SSIS Package USE Type two SCD if you want insert and
updates. you can use staging table from source to
destination is a good practice and it is industry standard. if you
are not having staging environment. You can use temp tables within
ssis package to achieve the same.
Schedule a job and run that ssis package in the job for every half an hour
i have next query
select no,
item
from myTable
and I get next table
no item
1 a
2 b
3 c
4 d
I use tsql, Microsoft SQL Server Management Studio.
Is there any way to write here some code to export table from my select in excel...
I am not aware of any way to write a query in SSMS and then export the results to excel, but you can connect an excel sheet to SQL Server and run queries into an data table from there using the From Other Sources - From SQL Server menu in the Data tab on the ribbon:
This is good if you want to build on that data within Excel and you need to refresh the data but don't want to update your formulas. There are obviously security implications with this as users of the Worksheet may be able to access other data on your server.
If you want to simply export an Excel file with data in to a file store, you would need to use SSRS and a report subscription. Alternatively, if you simply want to save the results of your query to a file, you can either copy and paste manually or choose to Save Your Results To Text in SSMS:
from your excel sheet you can create a dynamic connection between a SQL Server database and your Excel workbook.
Follow the steps in below link.
Steps to Connect a SQL Server database to your workbook
I have two different databases in two different SQL Servers. The databases are identical in schema but contain different data in one of the tables.
I want to copy all the data from one table in one database to the same table in the other database so that I can get rid of the database from which I am copying the data.
The data is too large so I cannot create data scripts and run it onto other database.
How can I achieve this?
There are many ways like ssis transfer,select * into ,but i prefer below way if you are just transferring data
create a linked server on source server for destination server,then you could refer destination server with four part name
Assuming linked server of source is A and destination server is B,data moving is as simple as
insert into B.databasename.Schema.Table
select * from table---this is in source server and db
if data is huge and you may worry about time outs,you can write a simple script which can do in batches like
While (1=1)
begin
insert into B.databasename.Schema.Table
select top 10000* from table---this is in source server and db
if (##rowcount=0)
break
end
Creating linked server ,you can follow this
You have the following options available to you. Not all of these will work, depending on your exact requirements and the networking arrangements between the servers.
SQL Server Management Studio - Import & Export Wizard: this is accessed from the right-click menu for a database > Tasks > Import Data (or Export Data).
SQL query using a Linked Server: a Linked Server configured between the two servers allows you to reference databases on one from the other, in much the same way as if they were on the same server. Any valid SQL query approach for transferring data between two tables within one database will then work, provided you fully-qualify the table names as Server.Database.Schema.Table.
SSIS: create an SSIS package with both servers as connections, and a simple workflow to move the data from one to the other. There is plenty of information available online on how to use SSIS.
Export to flat-file format then import: this could be done using the Import/Export Wizard above or SSIS, but instead of piping the data directly between the two servers, you would output the data from the source table into a suitable flat-file format on the filesystem. CSV is the most commonly used format for this. This file can then be moved to the destination server using any file transfer approach (compressed e.g. to a Zip file if desired), and imported into the destination table.
Database backup and restore: Similar to (4), but instead of using a flat file, you could create a backup of the source database via Tasks > Back Up... You then move that backup as a file (just like the CSV approach), and restore it onto the destination server. Now you have two databases on the destination server, and can move data from one to the other locally.
I hope, this query helps you!!!
INSERT INTO [dbo].[tablename] (Column1, Column2,Column3)
(select Column1, Column2,Column3, from [Database1].[dbo].[tablename]
Thanks!!!
Working on a data data accuracy project. I have to find a way to compare data from a query from a SQL Server db with the data from a query from a MS Access db. The data on both db's should be identical, but sometimes there are errors. I have looked at data comparison tools but these seem to only be able to compare data from identical db vendors.
Is there a process that someone has used in the past to do this or an idea on how I might best approach this?
You can look at both data sets in Access, SQL, or Excel:
If the data set is small enough, I recommend Excel.
If you know SQL, you can export your Access data to text files, then do a Bulk Insert and get everything into SQL Server.
If you want to look at both data sets in Access, try this:
Go to your ODBC Data Source Administrator (searching for 'ODBC' from your Start menu should be sufficient)
Create a new System DSN connecting to your SQL Server db
Open your Access db (I'm using 2010, your version may be different)
Go to External Data->ODBC Database->Machine Data Source
Link to your tables of choice from your SQL Server
Query away!
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.