This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
begin { | |
$SqlInstance = Connect-DbaInstance -SqlInstance "MyServer"; | |
} | |
process { | |
$SqlInstance = "MyServer"; | |
$SourceDb = "MySourceDb"; | |
$TargetDb = "MyTargetTb"; | |
$TableList = @("Table1","Table2","Table3","Table4"); | |
foreach ($Table in $TableList) { | |
Start-ThreadJob -ThrottleLimit 2 -ArgumentList $SqlInstance, $SourceDb, $TargetDb, $Table -ScriptBlock { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
process { | |
$SqlInstance = "MyServer"; | |
$SourceDb = "MySourceDb"; | |
$TargetDb = "MyTargetTb"; | |
$TableList = @("Table1","Table2","Table3","Table4"); | |
foreach ($Table in $TableList) { | |
Start-ThreadJob -ThrottleLimit 4 -ArgumentList $SqlInstance, $SourceDb, $TargetDb, $Table -ScriptBlock { | |
param($SqlInstance, | |
$Source | |
$Destination |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Invoke-DbaQuery -SqlInstance $DstInstance -Database $DBName -file $DstUserScriptPath; | |
Write-Output "Users in $DstInstance.$DBName after correcting" | |
Get-DbaDbUser -sqlinstance $DstInstance -Database $DBName | format-table -autosize -Property SqlInstance, Database, Name, Login; | |
Write-Output "Orphan users in $DstInstance.$DBName after correcting"; | |
Get-DbaDbOrphanUser -sqlinstance $DstInstance -Database $DBName | format-table -autosize -property SqlInstance, DatabaseName, User; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$RestoreResult = Restore-DbaDatabase -SqlInstance $DstInstance -Database $DBName -Path $Sql17Backup.FullName -WithReplace; | |
Write-Output "Users in $DstInstance.$DBName before correcting"; | |
Get-DbaDbUser -sqlinstance $DstInstance -Database $DBName | format-table -autosize -Property SqlInstance, Database, Name, Login; | |
Write-Output "Orphan users in $DstInstance.$DBName before correcting"; | |
Get-DbaDbOrphanUser -sqlinstance $DstInstance -Database $DBName | format-table -autosize -property SqlInstance, DatabaseName, User; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import-module dbatools; | |
$SrcInstance = "flexo\sql17"; | |
$DstInstance = "flexo\sql19"; | |
$UserPassword = 'P@$$w0rd' | ConvertTo-SecureString -AsPlainText -Force; | |
$DBName = "UserPermTest"; | |
$DstUserScriptPath = "C:\sql\Backup\Sql19Users.sql"; | |
# Backup the databases | |
$Sql17Backup = Backup-DbaDatabase -SqlInstance $SrcInstance -Database $DBName -Path 'C:\sql\Backup\FLEXO$SQL17'; | |
$Sql19Backup = Backup-DbaDatabase -SqlInstance $DstInstance -Database $DBName -Path 'C:\sql\Backup\FLEXO$SQL19'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import-module dbatools; | |
$SrcInstance = "flexo\sql17"; | |
$DstInstance = "flexo\sql19"; | |
$UserPassword = 'P@$$w0rd' | ConvertTo-SecureString -AsPlainText -Force; | |
$DBName = "UserPermTest"; | |
$DstUserScriptPath = "C:\sql\Backup\Sql19Users.sql"; | |
# Create database & users on each | |
Remove-DbaDatabase -SqlInstance $SrcInstance, $DstInstance -Database $DBName -Confirm:$false | Out-Null; | |
New-DbaDatabase -SqlInstance $SrcInstance, $DstInstance -Name $DBName -Confirm:$false | Out-Null; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create table #StringTemp3 | |
( | |
TempMyString testing.dbo.MyStringType not null | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use testing; | |
go | |
create table #StringTemp2 | |
( | |
TempMyString MyStringType not null | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use tempdb; | |
go | |
-- Get the full name of the table | |
select * | |
from tempdb.sys.tables | |
GO | |
-- Now get the definition | |
sp_help #StringTemp_________________________________________________________________________________________________________00000000081A | |
go | |
drop table #StringTemp; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
insert into TestMyString | |
(ThisIsMyString) | |
values | |
('Hello there'); | |
go | |
select * | |
into #StringTemp | |
from TestMyString; | |
go | |
select * |
NewerOlder