Move data between two Azure SQL databases without using elastic query - azure-sql-database

I am in need of suggestion to move data from a particular table in one azure sql database to the other azure sql database which has the same table structure without using elastic query

Using SQL Server Management Studio to connect to SQL azure database, right click the source database and select generate scripts.
During the wizard, after have select the tables that you want to output to a query window, then click advanced. About half way down the properties window there is an option for "type of data to script". Select that and change it to "data only", then finish the wizard.
The heck the script, rearrange the inserts for constraints, and change the using at the top to run it against my target DB.
Then right click on the target database and select new query, copy the script into it, and run it.
This will migrate the data.

Please consider using the "Transfer SQL Server Objects task" in SSIS. You can learn all the advantages it provides on this article.

You can use PowerShell to query each database and move data between them as needed. Here's an example article on how to get this done.
Using PowerShell when working with Azure has a number of other benefits in what you can do and can control as well. It's a good choice to spend time learning.

In the source database I created SPs to select the data from the tables.
In the target database I created table types (which would be available in programmability) for the tables with the same structure as in the source.
I used Azure function to move the data into table type from source.
In the target database I created SPs to insert data into the tables from their respective table types.
After ensuring the transfer of data, I would be deleting those records moved to the target in the source database and for this I created SPs.

Related

Easier way of Doing SQL Data Export - Azure

I have two tables Table A and B that is present in a Azure SQL Database. I have the same database clone running in my local, but I want to populate the data that is present in Azure by using SSMS Export Data option. While using that option I specify the source and destination and then choose the option of "Write a query to specify the data to transfer"
And then I add the query "Select * from A where Condition1" and select the destination table here:
The issue is if I have 5 tables to export data from, I have to do this whole process 5 times, only difference is the queries and destination tables. Anyone has any idea how can I do this whole thing faster by some other means? I just need to copy data using some select statements with where clauses.
As per the Official Documentation
When you select  Write a query to specify the data to transfer, you can only copy the results of one query to one destination table.
So, you have to repeat the entire process for multiple times if you want to export data like that.
You can use the following ways for importing and exporting data:
Use Transact-SQL statements.
Use BCP (Bulk Copy Program) from the command prompt.
If you want to design a custom data import, you can use SQL Server Integration Services.
Use Azure Data factory.
Use BACPAC file. Refer this material by accu web hosting to know about it. Rather than querying before exporting the data, instead you can delete the unwanted data in destination database after exporting using delete statement.
REFERENCE:
Import & export data from SQL Server & Azure SQL Database - SQL Server | Microsoft Docs

Copy Database from server to local DB (I need copy only structure, without data)

I have a one problem. I have a database(MSSQL) on some server. I need copy this DB on my local DB. But! This DB is huge 7gb. I don't need data from this DB. I need just copy structure of this DB (What I mean about structure - all DB, all tables, connections, etc. (!!!But I don't need a data from this tables)). How I understand it - It will clean DB with the same structure.
I have no idea how implement it. I read what I can do it using PowerShell, Git and SQL manager. But i didn't find example. Could you tell me something about it?
Right click on your Database => Tasks => Generate Scripts
Screenshots shows this on a System Database. Don't do this on system databases.
Select the Tables / Views / Stored Procedures you want.
Change the scripting options depending on your preferences/requirements.
Generate the script
If you use MS SQL Server Management Studio, you can right-click on the tables you want to have in your other db -> Generate Script for -> Create -> and then choose one opion.
Only drawback is, that you have to do that for every table individually.

How to backup Sql Server to sql file?

In "Back UP" I only get a bak file, but I would like to create .sql file
Use SQL Server's Generate Scripts commend
right click on the database; Tasks -> Generate Scripts
select your tables, click Next
click the Advanced button
find Types of data to script - choose Schema and Data.
you can then choose to save to file, or put in new query window.
results in CREATE and INSERT statements for all table data selected in bullet 2.
This is a possible duplicate of: SQL script to get table content as "SELECT * FROM tblname"
To do a full database backup to File/Query you can use the 'Generate Scripts...' option on the Database.
Open SQL Server Management studio, right click on the database and choose 'Tasks->Generate Scripts...'
Then use the wizard to backup the database. You can script the whole database or parts of it. Two important options: In the 'Advanced' section, you will probably want to ensure 'Type of backup = 'Schema and Data' and the 'Script Statistics' is on.
This will produce a *.sql file that you can use as a backup that includes the schema and table data.
Ok, I read through most of these, but I had no "advanced button". But, there is still a way to do it, it's just a little hard to find, so here you go:
You can generate a script from a database, see http://msdn.microsoft.com/en-us/library/ms178078.aspx
If you want to create a script of your database you right-click on the databases and Generate Scripts (it's in different sub-menus depending on what version of SQL and Enterprise Manager / SQL Server Management studio you're using).
That will, however, only get you the database objects. It will not generate scripts for data. Backing up a database will give you all of the database objects as well as the data, depending on what recovery model your database is set to.
This fellow may have achieved what you are trying to do by creating the backup, and then restoring it and giving it a new name.
This approach copies the data along with all of the database objects.
If you want a file with insert statements for your data have a look here:
This procedure generates INSERT statements using existing data from the given tables and views. Later, you can use these INSERT statements to generate the data. It's very useful when you have to ship or package a database application. This procedure also comes in handy when you have to send sample data to your vendor or technical support provider for troubleshooting purposes.
http://vyaskn.tripod.com/code.htm#inserts

Copy all data from one SQLServer database to another on same machine

I want to copy all data from one database to another which has the same structure. The databases reside on the same machine & on same sql server.
I have googled a bit & have found solutions like this
INSERT states (statecode, statename)
SELECT statecode, statename
FROM server1.database1.dbo.states
But the problem is they are copying table by table & I have like more then 100 tables. I was thinking that is there a way to copy all of the data at once.
Views & stored procedures all should be copied.
Or should I be looking in some other direction to achieve this ...?
If this is a one-time need, use the (Database) > Tasks > Generate Scripts menu option in SQL Server Management Studio.
Some options:
Use the DB back up and restore tools to just move a big backup file. This is the simplest option.
Slave the 2nd instance off of the 1st. It'll keep it up to date, but can be a pain.
Use import export wizard to transfer the data from one DB to another DB and use Generate script for the Transfer the Procedure and views.
Check out tools like Red-Gate SQL Compare (for structural comparison) and SQL Data Compare (for data content compare). With Data Compare, you can also easily update one database from another (or a database backup, even).
They're not free - but if you have to do this several times over and over, just the time (not to speak of the hassle) you save yourself will easily outweigh the cost of purchasing these tools. Excellent stuff - highly recommended!

Move selected data from one server to another sql server 2008

I need to move selected data from 800+ tables in one database to the same 800+ tables in another database in another server. The data I select is based on date fields of every table. So, if I say table 1 date from 01/01/10 to 01/15/10, then only that data I want to be copied into the other server's database table specified.
I hope I am not confusing anyone. What is easiest way to do this?
Look into SSIS. What you're talking about is very easy using it. Here is a page that talks about using variables in SSIS.
If this is a one time solution and the destination database is going to be a brand new one. I would restore a backup from the source database and then delete all the records outside of the date range I want in the new database.
If this is a one time solution and you need to move the data to an existing database you can use the export/import wizard in SQL Server Management Studio (This is not in Express edition). Right click on the database go to task and select export data. Then you can use a query to select the data based on the date range from the source table.
You can also link the servers and just run an insert into Server1.database.dbo.table1 to Server2.database.dbo.Table2.
If you will be moving data everyday I would recommend you to create an SSIS package. You can use the Export Wizard and save the SSIS package at the end. Then you can modify the SSIS package using Visual Studio.