Download Steps to restore partition SQL 2005 Ent database

Survey
yes no Was this document useful for you?
   Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Transcript
Requirement:
I got the requirement to restore/Migrate partition database from SQL 2005 Enterprise Edition to
SQL2005/2008/2008R2 Standard edition to avoid the Enterprise edition license.
But we have 10 tables with partition in that Enterprise database and standard Edition won’t support the
Partition function. Hence we have followed the below steps to achieve this task which is suitable to our
requirement.
Note:


If I have a database running on a (SQL Server 2008 R2 Developer Edition-Enterprise Edition) that has no
enterprise features and take a backup of that database, I can restore it to a SQL Server 2008 R2 Standard
edition instance.
If I have a database that has enterprise features (data compression, transparent data encryption,
partition, change data capture) and try to restore it to an SQL Server 2008 R2 Standard Edition instance I
will fail.
Steps Followed:
S.No Activity
1 Stopped the application
Backup PartitionDB database and restore on Ent server with
2 other name(PartitionDB_Temp)
3 Identified the Partion tables
Dropped the partition tables from PartitionDB_Temp
Note: We had three tables with Foreign Key relationship with
other table hence we followed the below steps to drop those
4 tables.
Identified the Partition tables Foreign Keys relationship for that
5
three tables
6 Dropped that Foreign Keys
Now we dropped that 3 tables after removing the Foreign Keys
7
relation ship
Script out all that 10 tables from PartitionDB database with
constraints and related triggers
8
9 Remove the Partition Scheme from all the table scripts
Comment
Script Attached
Script Attached
Script Attached
Script Attached
Script Attached
You can use generate
script option with
Script triggers true
and script index True
option
You can use control
find to identify the
scheme name
Created these tables in PartitionDB_Temp database without
10 referring the partition scheme
Script out all the Foreign Keys constraints form PartitionDB which
11
we deleted in step 6
Created the dropped Foreign Keys constraints in
12 PartitionDB_Temp database
Exported the data of these 10 tables from PartitionDB database
13
to PartitionDB_Temp database
14 Drop the partition Scheme from PartitionDB_Temp database
15 Drop the partition Function from PartitionDB_Temp database
Check & ensure the data should be available only in primary file
16 group on PartitionDB_Temp database for all tables
17
You can use
Import/Export Wizard
Script Attached
Script Attached
Script Attached
Drop all file groups except Primary from PartitionDB_Temp
database
Script Attached
Compared & ensured the dependent objects for 10 tables in
between PartitionDB and PartitionDB_Temp database are in sync
Script Attached
18
19 Took the backup of PartitionDB_Temp on Ent DB server
20 Copied the backup to New SQL 2008 R2 standard edition server
Restored the PartitionDB_Temp database backup on New SQL
21
2008 R2 Standard Edition
Compare the data between old PartitionDB DB and New
22 PartitionDB DB
Identified the Partition tables:
select distinct
p.[object_id],
TbName = OBJECT_NAME(p.[object_id]),
index_name = i.[name],
index_type_desc = i.type_desc,
partition_scheme = ps.[name],
data_space_id = ps.data_space_id,
function_name = pf.[name],
function_id = ps.function_id
from sys.partitions p
inner join sys.indexes i
on p.[object_id] = i.[object_id]
and p.index_id = i.index_id
inner join sys.data_spaces ds
on i.data_space_id = ds.data_space_id
inner join sys.partition_schemes ps
on ds.data_space_id = ps.data_space_id
inner JOIN sys.partition_functions pf
on ps.function_id = pf.function_id
Script Attached
-- WHERE p.[object_id] = object_id('JBMTest')
order by
TbName, index_name ;
GO
To Drop the Partition Tables from database:
Drop table dbo.Tablename1
Drop table dbo.Tablename2
Identified Foreign Keys relationship in tables:
SELECT *
FROM sys.foreign_keys
WHERE referenced_object_id = object_id('Tablename’)
Generate script to drop Foreign Keys relationship for tables:
SELECT
'ALTER TABLE ' + OBJECT_NAME(parent_object_id) +
' DROP CONSTRAINT ' + name
FROM sys.foreign_keys
WHERE referenced_object_id = object_id('TM_TransactionMaster')
Drop the partition Scheme:
DROP PARTITION SCHEME [SchemaName]
GO
Drop the partition Function:
DROP PARTITION FUNCTION [FunctionName]
GO
Check & ensure the data should be available only in primary file group on
PartitionDB_Temp database for all tables List all Objects and Indexes per
Filegroup / Partition
------------------------------------------------------------------SELECT DS.name AS DataSpaceName
,AU.type_desc AS AllocationDesc
,AU.total_pages / 128 AS TotalSizeMB
,AU.used_pages / 128 AS UsedSizeMB
,AU.data_pages / 128 AS DataSizeMB
,SCH.name AS SchemaName
,OBJ.type_desc AS ObjectType
,OBJ.name AS ObjectName
,IDX.type_desc AS IndexType
,IDX.name AS IndexName
FROM sys.data_spaces AS DS
INNER JOIN sys.allocation_units AS AU
ON DS.data_space_id = AU.data_space_id
INNER JOIN sys.partitions AS PA
ON (AU.type IN (1, 3)
AND AU.container_id = PA.hobt_id)
OR
(AU.type = 2
AND AU.container_id = PA.partition_id)
INNER JOIN sys.objects AS OBJ
ON PA.object_id = OBJ.object_id
INNER JOIN sys.schemas AS SCH
ON OBJ.schema_id = SCH.schema_id
LEFT JOIN sys.indexes AS IDX
ON PA.object_id = IDX.object_id
AND PA.index_id = IDX.index_id
ORDER BY DS.name
,SCH.name
,OBJ.name
,IDX.name
Drop file groups:
USE [DBName]
GO
ALTER DATABASE [DBName]
GO
REMOVE FILE [Filegroupname]
Compare the data between old PartitionDB DB and New PartitionDB DB:
Execute the below script in both the old and new database and copy the output to Excel sheet and
compare the row count and it will be same. Don’t compare the size as it may be differ for
partition tables as we created them again in destination.
SELECT SCHEMA_NAME(tbl.schema_id) as [Schema]
, tbl.Name
, Coalesce((Select pr.name
From sys.database_principals pr
Where pr.principal_id = tbl.principal_id)
, SCHEMA_NAME(tbl.schema_id)) as [Owner]
, tbl.max_column_id_used as [Columns]
, CAST(CASE idx.index_id WHEN 1 THEN 1 ELSE 0 END AS bit) AS [HasClusIdx]
, Coalesce( (Select sum (spart.rows) from sys.partitions spart
Where spart.object_id = tbl.object_id and spart.index_id < 2), 0) AS
[RowCount]
, Coalesce( (Select Cast(v.low/1024.0 as float)
* SUM(a.used_pages - CASE WHEN a.type <> 1 THEN a.used_pages WHEN
p.index_id < 2 THEN a.data_pages ELSE 0 END)
FROM sys.indexes as i
JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id
= i.index_id
JOIN sys.allocation_units as a ON a.container_id = p.partition_id
Where i.object_id = tbl.object_id )
, 0.0) AS [IndexKB]
, Coalesce( (Select Cast(v.low/1024.0 as float)
* SUM(CASE WHEN a.type <> 1 THEN a.used_pages WHEN p.index_id < 2 THEN
a.data_pages ELSE 0 END)
FROM sys.indexes as i
JOIN sys.partitions as p ON p.object_id = i.object_id and p.index_id
= i.index_id
JOIN sys.allocation_units as a ON a.container_id = p.partition_id
Where i.object_id = tbl.object_id)
, 0.0) AS [DataKB]
, tbl.create_date, tbl.modify_date
FROM sys.tables AS tbl
INNER JOIN sys.indexes AS idx ON (idx.object_id = tbl.object_id and
idx.index_id < 2)
INNER JOIN master.dbo.spt_values v ON (v.number=1 and v.type='E') order by
name
Similar