Why my tables are empty after importing the BACPAC file ????

Published 03-01-2021 01:25 AM 800 Views

 

I worked on a service request that our customer reported that some tables are empty after importing the database using BACPAC file . in this article i would like to share with you my findings and the troubleshooting steps :

 

 

1-Compare the number of rows for each table on the source and destination database using the following T-SQL to identify which tables that don't contain data :

 

 

 

 

 

SELECT
    t.NAME AS TableName,
    s.Name AS SchemaName,
    p.rows AS RowCounts,
    SUM(a.total_pages) * 8 AS TotalSpaceKB,
    SUM(a.used_pages) * 8 AS UsedSpaceKB,
    (SUM(a.total_pages) - SUM(a.used_pages)) * 8 AS UnusedSpaceKB
FROM
    sys.tables t
INNER JOIN      
    sys.indexes i ON t.OBJECT_ID = i.object_id
INNER JOIN
    sys.partitions p ON i.object_id = p.OBJECT_ID AND i.index_id = p.index_id
INNER JOIN
    sys.allocation_units a ON p.partition_id = a.container_id
LEFT OUTER JOIN
    sys.schemas s ON t.schema_id = s.schema_id
WHERE t.is_ms_shipped = 0
    AND i.OBJECT_ID > 255
GROUP BY
    t.Name, s.Name, p.Rows
ORDER BY
    t.Name

 

 

 

 

 

2-After confirming that the tables don't have data ,we need to check if the exported BACPAC file have data on those tables and this done using the following steps:

  • Change the extension for the backup file from BACPAC to .zip .
  • Open the zip file and you should have a data folder that contains a folder for each tables exported with data.
  • if you find a folder for the tables that means that the BACPAC file contains the data for the tables

3-Connect with the same user that has exported the database and select the data from the tables that have the issue to be sure that the user has permission to view the data on those tables.

 

As a result, when you are using Row level security and want to export the database please be sure that the user who export the database has  permission to view the data on the database tables otherwise this will only export the tables with the data that the user has permission to view .

%3CLINGO-SUB%20id%3D%22lingo-sub-1652979%22%20slang%3D%22en-US%22%3EWhy%20my%20tables%20are%20empty%20after%20importing%20the%20BACPAC%20file%20%3F%3F%3F%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1652979%22%20slang%3D%22en-US%22%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%3EI%20worked%20on%20a%20service%20request%20that%20our%20customer%20reported%3C%2FSPAN%3E%26nbsp%3Bthat%20some%20tables%20are%20empty%20after%20importing%20the%20database%20using%20BACPAC%20file%20.%20in%20this%20article%20i%20would%20like%20to%20share%20with%20you%20my%20findings%20and%20the%20troubleshooting%20steps%20%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E1-Compare%20the%20number%20of%20rows%20for%20each%20table%20on%20the%20source%20and%20destination%20database%20using%20the%20following%20T-SQL%20to%20identify%20which%20tables%20that%20don't%20contain%20data%20%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-sql%22%3E%3CCODE%3ESELECT%0A%20%20%20%20t.NAME%20AS%20TableName%2C%0A%20%20%20%20s.Name%20AS%20SchemaName%2C%0A%20%20%20%20p.rows%20AS%20RowCounts%2C%0A%20%20%20%20SUM(a.total_pages)%20*%208%20AS%20TotalSpaceKB%2C%0A%20%20%20%20SUM(a.used_pages)%20*%208%20AS%20UsedSpaceKB%2C%0A%20%20%20%20(SUM(a.total_pages)%20-%20SUM(a.used_pages))%20*%208%20AS%20UnusedSpaceKB%0AFROM%0A%20%20%20%20sys.tables%20t%0AINNER%20JOIN%20%20%20%20%20%20%0A%20%20%20%20sys.indexes%20i%20ON%20t.OBJECT_ID%20%3D%20i.object_id%0AINNER%20JOIN%0A%20%20%20%20sys.partitions%20p%20ON%20i.object_id%20%3D%20p.OBJECT_ID%20AND%20i.index_id%20%3D%20p.index_id%0AINNER%20JOIN%0A%20%20%20%20sys.allocation_units%20a%20ON%20p.partition_id%20%3D%20a.container_id%0ALEFT%20OUTER%20JOIN%0A%20%20%20%20sys.schemas%20s%20ON%20t.schema_id%20%3D%20s.schema_id%0AWHERE%20t.is_ms_shipped%20%3D%200%0A%20%20%20%20AND%20i.OBJECT_ID%20%26gt%3B%20255%0AGROUP%20BY%0A%20%20%20%20t.Name%2C%20s.Name%2C%20p.Rows%0AORDER%20BY%0A%20%20%20%20t.Name%0A%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E2-After%20confirming%20that%20the%20tables%20don't%20have%20data%20%2Cwe%20need%20to%20check%20if%20the%20exported%20BACPAC%20file%20have%20data%20on%20those%20tables%20and%20this%20done%20using%20the%20following%20steps%3A%3C%2FP%3E%0A%3CUL%3E%0A%3CLI%3EChange%20the%20extension%20for%20the%20backup%20file%20from%20BACPAC%20to%20.zip%20.%3C%2FLI%3E%0A%3CLI%3EOpen%20the%20zip%20file%20and%20you%20should%20have%20a%20data%20folder%20that%20contains%20a%20folder%20for%20each%20tables%20exported%20with%20data.%3C%2FLI%3E%0A%3CLI%3Eif%20you%20find%20a%20folder%20for%20the%20tables%20that%20means%20that%20the%20BACPAC%20file%20contains%20the%20data%20for%20the%20tables%3C%2FLI%3E%0A%3C%2FUL%3E%0A%3CP%3E3-Connect%20with%20the%20same%20user%20that%20has%20exported%20the%20database%20and%20select%20the%20data%20from%20the%20tables%20that%20have%20the%20issue%20to%20be%20sure%20that%20the%20user%20has%20permission%20to%20view%20the%20data%20on%20those%20tables.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAs%20a%20result%2C%20when%20you%20are%20using%20Row%20level%20security%20and%20want%20to%20export%20the%20database%20please%20be%20sure%20that%20the%20user%20who%20export%20the%20database%20has%26nbsp%3B%20permission%20to%20view%20the%20data%20on%20the%20database%20tables%20otherwise%20this%20will%20only%20export%20the%20tables%20with%20the%20data%20that%20the%20user%20has%20permission%20to%20view%20.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-1652979%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSPAN%3EI%20worked%20on%20a%20service%20request%20that%20our%20customer%20reported%3C%2FSPAN%3E%26nbsp%3Bthat%20some%20tables%20are%20empty%20after%20importing%20the%20database%20using%20BACPAC%20file%20.%20in%20this%20article%20i%20would%20like%20to%20share%20with%20you%20my%20findings%20and%20the%20troubleshooting%20steps%20%3A%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-TEASER%3E
Co-Authors
Version history
Last update:
‎Mar 01 2021 03:09 AM
Updated by: