Dev Environment creation from Prod for Azure SQL - sql

I have a production server in Azure SQL. I have created a another empty server(dev) for development purpose. I need a copy of the tables, views, stored procedure in the dev server as well. Please suggest some way to transfer the data to dev server database

#John11 : You can take a backup of your Production Database and then simply restore on your Dev server
Ideally Production data restore to Dev is not advisable if it is a highly confidential data
If you just need to move the schema without data then you can use DevOps / CI-CD to deploy the artifacts to Dev

Related

How to replicate snapshot of Azure SQL from Dev subscription to Test subscription?

I have Dev Azure SQL server in Dev subscription and Test Azure SQL Server in Test subscription.
I would like to copy snaphot of Azure SQL database from "dev" to "test" with script and eventually automated with Azure DevOps pipeline.
I have successfully replicated database inside "Dev" subscription with New-AzSqlDatabaseCopy.
However it does not have source and destination subscription parameter.
What is best method to replicate snapshot of database from subscription to another?
This could be done by T-SQL. If the login is member of the dbmanager role or a server administrator, on both source and target servers/subscriptions, then below command copies Database1 on server1 to a new database named Database2 on server2. Depending on the size of your database, the copying operation might take some time to complete.
Execute on the master database of the target server (server2) to start copying from Server1 to Server2
CREATE DATABASE Database2 AS COPY OF server1.Database1;
Note: The Azure portal, PowerShell, and the Azure CLI do not support database copy to a different subscription.
Reference Link for more details: https://learn.microsoft.com/en-us/azure/azure-sql/database/database-copy?view=azuresql&tabs=azure-powershell#copy-to-a-different-subscription

SSDT How to deal with LinkedServer variable within SQL scripts

I am using SQL Server Database Project inside Visual Studio.
I have three databases. Database P (production), Database T (test) and a database D which P and T has a dependency on.
Database P and D are in the same server/instance (production server). Database T is on a different server (test server) and there is linked server which points to the production server.
The database D is setup as a variable in publish profile.
The D tables are registered as synonyms and SQL script use these synonyms.
When I deploy into production it works.
How can I setup, that when I am publishing into test environment, I would like to use the LinkedServer? (In production it is not needed, but in the test I need it)
I can use something like this
CREATE SYNONYM [foo].[Bar]
FOR [$(LinkedServerToDatabase_D)].[$(D)].[foo].[Bar]
And I am able to deploy to production and also test, but this solution has a downside. In this case I have to put ##servername result into the publish profile variable. If database will migrate to different server I will have to redeploy the database.
Is it possible to deploy this to production
CREATE SYNONYM [foo].[Bar]
FOR [$(D)].[foo].[Bar]
and this to test?
CREATE SYNONYM [foo].[Bar]
FOR [$(LinkedServerToDatabase_D)].[$(D)].[foo].[Bar]
So I don't need to worry about production server name?

How to apply migrations to production server

Using Code First and Entity Framework, I have created my web application on my dev machine, used migrations and published to my beta application to my production server and database.
Then on my dev system I’ve done lots of changes created several migrations and applied them to my local dev database. When I use update-database this updates my local dev database, but how then do I apply the migrations to my production server database?
I've been using update-database -script to get the SQL to manually apply to my production server. Is there a better way?
You should ideally employ some kind of actual database deployment system like ReadyRoll. Short of that, you should generate SQL scripts that you can commit and deploy manually, preferably via a DBA role in your organization. Code-based migrations can do all sorts of potentially bad things to your database with no notice, but in a SQL script, you can easily see that a table is about to be dropped or a column with lots of irreplaceable data is about to be removed.
Your in Web.config is what establishes which database the application is pointing to. When you point it to production and run the same EF commands (dotnet ef migrations add migrationName, and dotnet ef database update) it should update your production environment.
For my setup I just don't deploy my web.config so in production it always points to production database. When I run the EF update scripts in production it updates production and I'm good to go.

I want to make staging database the same as production on Azure

My production and staging databases are on Azure and I want to make staging the same as production. I have no idea what to do, I have never worked with databases. I use SQL Server 2014.
There are a few ways to do this, but the quickest way would probably be to replace your staging database when you want the updated data by Creating a new database as a copy. Now, this would wipe out any changes to your staging database, but would be the fastest way.
More complicated, but probably a bit more about what you're actually thinking of, would be setting up azure data sync from Prod -> Staging.
Staging Azure web app has different configuration with production Azure web app. We can configure the same connection string at Azure portal to achieve this requirement. Refer to this article for more information about how to configure connection string in Azure portal. At runtime, Azure Web App will automatically retrieves values in Azure portal and makes them available to code running in your website. If the same connection string configured in Azure portal, the staging and production will use the same database.

Strategy to sync 2 Microsoft SQL Server databases

I've gotta admit that I'm a Microsoft .NET developer, and I'm not an expert in SQL Server.
I have developed a Windows app, with data stored in my local SQL Server (Express version). I recently purchase a shared hosting service, including a SQL Server. I thought about backing up my local data to remote server: about 5-6 tables from my local SQL Server to remote server, and 1-2 tables from remote to local
What's the best way to do this? DB size is limited to about 5-10MB. The structure of 2 DBs are different, synced tables have same structures. Is there an automatic script I can run from SQL Server Express to do this task every 15 minutes or so?
For initial publishing I’d just go with restoring a backup in the hosting environment. For further synchronization you can try some of the 3rd party tools such as ApexSQL Data Diff or SQL Data Compare or basically any other tool in this category…