SQL Script for SQL Azure - azure-sql-database

I'm developing an app that uses SQL Azure. I don't have an account to access Windows Azure and I want to start writing SQL script.
Can I use my SQL Server 2008 to test my SQL Azure script?

I would also recommend a SQL Azure account. However, if you dont have access to one, you can create the DB in SQL 2008, then export a SQL Azure compatable script. Then use that script for testing purposes.
Here is a link: http://blogs.msdn.com/b/cesardelatorre/archive/2010/06/04/importing-exporting-data-to-sql-azure-databases-using-bcp-and-sql-scripts.aspx
One thing you should accomodate for when coding for SQL Azure is a failover or retry policy per this article: http://blogs.msdn.com/b/appfabriccat/archive/2010/12/11/sql-azure-and-entity-framework-connection-fault-handling.aspx#comments

Not really, because certain SQL statements are not supported, or partially supported. So unless you are already very familiar with the differences between SQL Azure and SQL Server the general recommendation is to create your scripts against a SQL Azure database.
Opening an Account is really simple. Remember that when you create a SQL Azure database your charges are pro-rated daily. So if you create a development database of 1GB is size (the minimum) you will pay $9.99 per month (plus a really low transfer cost), or "roughly" 33 cents per day. If you create a 1GB database on a Monday and drop it the following Wednesday, you will pay roughly a buck. There are no charges for the master database.

I would agree with Herve. It would likely be best if you actually use SQL Azure as there are some differences between SQL Sever and SQL Azure. You can get a free 30 day account (with no credit card) using the following:
Use this link: http://www.windowsazurepass.com/?campid=9FE3DB53-E4F0-DF11-B2EA-001F29C6FB82
Use this passcode: promo code = DPEWE01

What you want to do is actually the right way, you can create a database in you local SQL Server 2008 instance, I would recommend using latest community edition for this purpose.
Create database, tables.. work on it, then generate a script to later export to SQL Azure.
Make sure to see documentation for pressing changes or things not to use while doing your job that might not be working on SQL Azure.

Related

Migrate on-prem SQL Server database to Azure SQL database

We're in the process of a server migration from an on-prem server (Win2008R2) to Azure PaaS.
To move the DBs, we used the Microsoft Data Migration Assistant (DMA) tool, which worked great and we can connect to the migrated Azure DB via SQL Server Management Studio.
Considering:
Made quite a few changes to the migrated Azure DB (tables, stored procedures, indexes) to work with the apps in Azure
Combined multiple on-prem DBs into one DB in Azure via DMA to save costs
On-prem DB is continually being modified by insert/update operations (multiple tables) during the migration process
Question: what is the best and fastest way to migrate data (all vs missing/updated) considering the above?
I would recommend you to migrate first only the schema of your on-premises databases to Azure SQL Databases and then let Azure SQL Data Sync to migrate the data to Azure and keep it updated on Azure SQL Database.
My suggestion to start with an empty schema on the Azure SQL Database side is because when SQL data Sync finds data on-premises and on Azure it start comparing both databases and that consumes a lot of resources.
On the initial sync SQL Data Sync may consume a lot of resources on the on-premises database server even when having an empty schema on the Azure side, for that you can use SQL Server Resource Governor to cap the CPU used by the data sync sessions in your on premises SQL Server, and this way avoid big performance impact possibly affecting database users.
When you are ready, you can switch your users (gradually or not if SQL Data Sync is on bi-directional mode) to Azure. Once your users have been migrated, you can then remove the member database (the on-premises database) from the SQL Data Sync configuration and stop SQL Data Sync operation.
I disagree with all the answers here.
If you are running on Win2008R2 there is a high chance that you are on an old SQL Server (2008? 2012?) which are both deprecated and unsuitable for Azure SQL Database. And probably the application is also old and not suitable for the Cloud in general. I suggest you a good testing phase.
Here my to do list:
Upgrade SQL Server to SQL Server 2016 on-prem and test if all your queries are still running correctly
Test how ready is your SQL Server to go to Azure SQL Database through Microsoft Data Migration Assistant (DMA) tool or the new Azure SQL Migration extension for Azure Data Studio (came out his month).
Don even think for a second that merging databases will reduce your overall costs. Decide if going multi-tenant or single-tanant not because of the price of the database.
Plan for hours of downtime based on the size of the migration. Don't migrate while your database is modified. Expect downtime. The best way is to take a backup of the day before and then resume the logs.
and test like crazy. This is not gonna be easy because the app is old.
Good luck.
Visual Studio also has a great tool for comparing both schema and data between two databases on different servers.
It can then update the target database with any changes after which you can switch over to use the Azure DB.
This method would require downtime of around 5-30 minutes depending on amount of data, but that might be acceptible depending on your requirements.

How to run a T-SQL query daily on an Azure database

I am trying to migrate a database from a sql server into Azure. This database have 2 rather simple TSQL script that inserts data. Since the SQL Agent does not exist on Azure, I am trying to find an alternative.
I see the Automation thing, but it seems really complex for something as simple as running SQL scripts. Is there any better or at least easier way to do this ?
I was under the impression that there was a scheduller for that for I can't find it.
Thanks
There are several ways to run a scheduled Task/job on the azure sql database for your use case -
If you are comfortable using the existing on-premise sql sever agent you can connect to your azure sql db(using linked servers) and execute jobs the same way we used to on on-premise sql server.
Use Automation Account/Runbooks to create sql jobs. If you see marketplace you can find several examples on azure sql db(backup,restore,indexing jobs..). I guess you already tried it and does not seem a feasible solution to you.
Another not very famous way could be to use the webjobs(under app service web app) to schedule tasks(can use powershell scripts here). The disadvantage of this is you cannot change anything once you create a webjob
As #jayendran suggested Azure functions is definitely an option to achieve this use case.
If some how out of these if you do not have options to work with the sql directly , there is also "Scheduler Job Collection" available in azure to schedule invocation of HTTP endpoints, and the sql operation could be abstracted/implemented in that endpoint. This would be only useful for less heavy sql operations else if the operation takes longer chances are it might time out.
You can use Azure Functions to Run the T-SQL Queries for Schedule use Timely Trigger.
You can use Microsoft Flow (https://flow.microsoft.com) in order to create a programmed flow with an SQL Server connector. Then in the connector you set the SQL Azure server, database name, username and password.
SQL Server connector
There are many options but the ones that you can use to run a T-SQL query daily are these:
SQL Connector options
Execute a SQL Query
Execute stored procedure
You can also edit your connection info in Data --> Connections menu.

How can I schedule a SQL job in Microsoft Azure SQL Database?

I have one SQL Agent maintenance job which checks the index fragmentation within a database and rebuilds indexes if required.
This is running well in my test server (Microsoft Sql Server 2012). But my production server is in Azure. Now I want to schedule that job to Azure.
SQL Agent does not exist in Azure SQL Database so how can I schedule a SQL job in Azure DB?
Since this question was first asked, there is now another alternative to handle this problem:
Azure Functions
Here are a couple of examples that could easily be modified to call a stored procedure that rebuilds your indexes
Create a function in Azure that is triggered by a timer
Use Azure Functions to connect to an Azure SQL Database
Also see
How to maintain Azure SQL Indexes and Statistics - this page has an example stored procedure for rebuilding your indexes that you can download.
Reorganize and Rebuild Indexes
A few things to keep in mind with Azure functions
They are built on top of Azure Web Jobs SDK and offer additional functionality
There are two different pricing models:
App Service plan (attach it to an existing plan)
Predictable cost model
It puts extra load on the same VM used by your web site
Consumption plan
You get some free processing every month
The default maximum run time is 5 minutes to prevent billing problems, but it can be changed via the host.json file.
Edit September 5, 2021 to add additional information
It should be noted that if you need SQL Agent, you have another option now. I would suggest reading up on Azure SQL Managed Instances. You can see a comparison of Azure SQL to Azure SQL Managed instance here in the Microsoft Documentation. With Azure SQL Managed Instances, your transition to the cloud could be a lot simpler since a lot of the on-premise features you are used to are already there (including SQL Server Agent, DB Mail, etc.).
This feature has been rejected by Microsoft (link no longer available).
To quote their response:
Today in Azure there are several alternatives,
SQL Database Elastic Jobs
https://learn.microsoft.com/en-us/azure/azure-sql/database/elastic-jobs-overview
The Azure job scheduler
http://www.windowsazure.com/en-us/services/scheduler/
The new
preview of Azure Automation
http://azure.microsoft.com/en-us/services/automation/.
SQL Server
in a VM
Option 1 requires an additional dedicated cloud service, which increases cost. Option 2 is free (I think) as long as you don't run more than once per hour.
Azure SQL does not support sql jobs. From documentation:
Microsoft Azure SQL Database does not support SQL Server Agent or
jobs. You can, however, run SQL Server Agent on your on-premise SQL
Server and connect to Microsoft Azure SQL Database.
WebJobs: If you have a website you can create webjob and run it on schedule. See more here
Other alternatives - Scheduling job on SQL Azure
Another option is rovergo, a service that allows you to schedule sql jobs with a cron expression. This is nice because you don't have to create a web job or azure function. You can simply schedule a sql script.
(I'm a developer on rovergo)
You can use Azure automation to schedule jobs on an Azure-DB like the on premise SQL Agent.
See https://azure.microsoft.com/nl-nl/blog/azure-automation-your-sql-agent-in-the-cloud/ for more information.
Available for a couple of years now, Elastic Jobs for azure db...
docs:
https://learn.microsoft.com/en-us/azure/azure-sql/database/job-automation-overview?view=azuresql
tutorial:
https://www.youtube.com/watch?v=JIMgqkXZFOQ
Currently seems to use the 2017 version of the sqlagent sp (or a close approximation), but elastic links are now already pointing to SQL2022 preview which contains a newer version of the agent sps

Sync between Sql Server and Mysql Server

I have 2 big tables in sql server that i need to sync to mysql.
now, i need that as an ongoing process.
the tables are 1 GB each and getting new/update/delete row every 0.1 second.
Can you recommend me a tool that can do it that is not resource expensive.
you can offer OPEN SOURCE and commercial as well
Thanks
You could create a linked server instance in SQL Server, pointing to the MySQL instance. This article gives the step-by-step process. Once that is in place, providing you grant the MySQL user you connect on behalf of proper permissions, you can write to the MySQL instance as you like. So you could easily update stored procedures to do an additional step to insert records into MySQL.

How to Convert SQL server to Oracle?

I have a SQL server database (Tables, Views, SP...). I need to convert this database to Oracle 10g. How can I do it?
Transferring the data will be easy; SQL Server integration services can do that, or Oracle's SQL Developer.
However, views and stored procedures are different between Oracle and SQL Server. SQL Server uses T-SQL, Oracle uses PL/SQL. These are not very compatible and I don't know a tool can automatically convert between the two. If your database relies on specific T-SQL features, you will need a developer to do the conversion.
Get the jTDS jdbc driver from sourceforge.
Add it to Oracle SQL Developer.
Tools > Migration > Migrate
Create a migration repository in your new Oracle database.
Create a new migration project.
Point it to your SQL Server database.
Convert it - mind the data types.
Migrate the data:
online row-by-row inserts over JDBC. Fine for SMALL/test boxes.
offline - use micrsosoft's unload utility to pull the sql server down to flat files. SQL Developer will create SQL*Loader scripts to put them over into Oracle.
If you have GoldenGate licensed, use that to move the data over and to synch changes from one system to the other in case you need to keep both up and going.
Start looking at the migrated T-SQL procs and functions. SQL Developer will leave comments for code blocks it wasn't able to translate...but you will need to TEST and VERIFY every single translation. Customers can see upwards to 80-90% translation rates for their T-SQL, but it could be as low as 50%...it just depends on the nature of your code.
The entire process is described here.
I wrote a white paper, with Sybase ASE as the example source platform, here. The process is identical for SQL Server. It has step-by-step guidance with screenshots.
If you have an Oracle account manager, reach out for help. We have specialists that deal exclusively with migrations such as yours. They have lots of practical advice and can recommend 3rd party partners if you lack the expertise.
sql developer can help. You can download it here , it is free. http://www.oracle.com/technology/software/products/sql/index.html
There is step by step documentation including videos on how to migrate SQL Server to Oracle DB. You find it here:
Migrating from Microsoft SQL Server to Oracle
Or you can use a tool to do the job for you like Ispirer - Migrate Microsoft SQL Server to Oracle
You basicaly setup an Oracle Server, once its ready you migrate your tables using a software made for that. I guess this script can do the job:
m2o