Automate SQL Server Database Migration To Azure With PowerShell | SQL Server Database to Azure

preview_player
Показать описание
In this video, you will learn how to migrate SQL Databases to Azure SQL Server in a few steps.

*** Advance your career or learn some new skills with one of these courses ***

==========Powershell Script===============

#Source SQL Server
$SourceUser = "yourdb_dev"
$SourcePassword = "******"
$SourceServer = "testsvr"
$BackupDirectory ="D:\data\MSSQL\BACKUP"
$DatabaseName ="RDSTest"
$SqlPackageLocation = "C:\Program Files\Microsoft SQL Server\160\DAC\bin"

#Destination SQL Server
$TargetPassword = "********"
$TargetDBname = $DatabaseName+"_n"
$targetUser = "youruser"

$ext = "bacpac"
#target filepath is a combination of the directory and filename appended with year month and day hour minutes and seconds
$TargetFilePath = "$BackupDirectory\$DatabaseName-$(get-date -f yyyy-MM-dd).$ext"
#print the full path of the target file path
$TargetFilePath

try
{
# This is a simple user/pass connection string.
# Feel free to substitute "Integrated Security=True" for system logins.
$connString = "Data Source=$SourceServer; Database=$DatabaseName;User ID=$User;Password=$Password"

#Create a SQL connection object
$conn = New-Object System.Data.SqlClient.SqlConnection $connString

#Attempt to open the connection
$conn.Open()

if($conn.State -eq "Open")
{
#excute SQL Script on database
#exports source database
Invoke-Expression $cmd

$conn.Close()

#imports database to target host
Invoke-Expression $cmd
}

}
catch
{
Write-Host($error)
}
Рекомендации по теме
Комментарии
Автор

Hey there, god bless your efforts in this channel.
As a newbie sql learner i have general enquiry.
Where should a database optimally be stored inside a company?
Is it convenient to traffic all raw data to a central pc on which i would work on the database software from there(sql server),
or is the database optimally to be located on a separate machine.
Looking forward to learn from you.

hasanmougharbel
Автор

Excellent video
I have a question, what is exactly in "D:\Google and "D:\...create table" do I need an extra file or script?
thanks

mm
Автор

I donot understand the logic of dropping the table and recreate it...also what is the content of the .SQL scripts? Kindly elaborate sir...

ssabyasachi