Skip to content

Instantly share code, notes, and snippets.

@swaters86
Created October 16, 2014 13:47
Show Gist options
  • Save swaters86/20082be3c75d13f2d51a to your computer and use it in GitHub Desktop.
Save swaters86/20082be3c75d13f2d51a to your computer and use it in GitHub Desktop.
Drops custom tables and back ups up metadata for LANG/MNG/MN1 ZZ Site
/*
RUN FIRST On MN1oDBS001
#1 - Backup profiles to MN1_.sql
making backup of meta data to custom fake tables
*/
use custom
go
if @@SERVERNAME = 'MN1ODBS001'
begin
drop table MN1_profile
drop table MN1_profile_group
drop table MN1_profile_word
drop table MN1_Profile_ExtraFields
drop table MN1_Profile_Default_Taxonomy_Keys
drop table MN1_Kategorier
drop table MN1_Underkategorier
drop table MN1_taxonomy
drop table MN1_cachecontrol
set nocount on
select *
into custom.dbo.MN1_profile
from web.dbo.profile (nolock)
where Avis='ZZ'
select *
into custom.dbo.MN1_profile_group
from web.dbo.profile_group (nolock)
where Avis='ZZ'
select *
into custom.dbo.MN1_profile_word
from web.dbo.profile_word (nolock)
where Avis='ZZ'
select *
into custom.dbo.MN1_Profile_ExtraFields
from webextras.dbo.Profile_ExtraFields (nolock)
where Avis='ZZ'
select *
into custom.dbo.MN1_Profile_Default_Taxonomy_Keys
from webextras.dbo.Profile_Default_Taxonomy_Keys (nolock)
where Site='ZZ'
select *
into custom.dbo.MN1_Kategorier
from web.dbo.Kategorier (nolock)
where Avis='ZZ'
select *
into custom.dbo.MN1_Underkategorier
from web.dbo.Underkategorier (nolock)
where Avis='ZZ'
select *
into custom.dbo.MN1_taxonomy
from web.dbo.taxonomy (nolock)
where Avis='ZZ'
select *
into custom.dbo.MN1_cachecontrol
from web.dbo.cachecontrol (nolock)
where Site='ZZ' and [Type]=6 and SubType=1
declare @Acounter int
select @Acounter=COUNT(*)
from web.dbo.profile (nolock) aa
left join custom.dbo.MN1_profile (nolock) bb
on (bb.avis=aa.Avis and bb.profile_id = aa.profile_id)
where aa.avis='ZZ' and bb.profile_id is null
if @Acounter > 0
print 'missing profiles in custom.dbo.MN1_profile'
select @Acounter=COUNT(*)
from web.dbo.profile_group (nolock) aa
left join custom.dbo.MN1_profile_group (nolock) bb
on (bb.avis=aa.Avis and bb.profile = aa.profile)
where aa.avis='ZZ' and bb.profile is null
if @Acounter > 0
print 'missing profiles in custom.dbo.MN1_profile_group'
select @Acounter=COUNT(*)
from web.dbo.profile_word (nolock) aa
left join custom.dbo.MN1_profile_word (nolock) bb
on (bb.avis=aa.Avis and bb.profile = aa.profile)
where aa.avis='ZZ' and bb.profile is null
if @Acounter > 0
print 'missing profiles in custom.dbo.MN1_profile_word'
select @Acounter=COUNT(*)
from web.dbo.Profile_Default_Taxonomy_Keys (nolock) aa
left join custom.dbo.MN1_Profile_Default_Taxonomy_Keys (nolock) bb
on (bb.site=aa.site and bb.profile_id = aa.profile_id)
where aa.site='ZZ' and bb.profile_id is null
if @Acounter > 0
print 'missing profiles in custom.dbo.MN1_Profile_Default_Taxonomy_Keys'
select @Acounter=COUNT(*)
from webextras.dbo.Profile_ExtraFields (nolock) aa
left join custom.dbo.MN1_Profile_ExtraFields (nolock) bb
on (bb.avis=aa.avis and bb.profileid = aa.profileid)
where aa.avis='ZZ' and bb.profileid is null
if @Acounter > 0
print 'missing profiles in custom.dbo.MN1_Profile_Default_Taxonomy_Keys'
print 'Task completed'
set nocount off
select COUNT(*)
from web.dbo.profile (nolock)
where avis='ZZ'
select COUNT(*)
from custom.dbo.mn1_profile (nolock)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment