How to find Schema name for Tables and Columns in Microsoft SQLServer

Still need help?

The Atlassian Community is here for you.

Ask the community

Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.

Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.

*Except Fisheye and Crucible

Summary

This document will help to identify all schemas from the underlying MSSQL database. This will even help to capture the DB schema of all tables and associated columns. This will help us to investigate the issue where some tables are not accessible due to the "Could not read fields for table" error and eventually the transaction fails in Confluence upgrade or other processes. 

Environment

Microsoft SQL Server 

Solution

The below  SQL query will help us to know the Schema name for tables and even for columns as well. 

select SCHEMA_NAME();

SELECT * FROM INFORMATION_SCHEMA.TABLES;

SELECT	* FROM INFORMATION_SCHEMA.COLUMNS;

Confluence only supports the dbo schema. As outlined in this KB article, we can follow the following steps for changing the schema from another owner ( e.g. db_owner) to dbo. 

  • Roll back Confluence to a pre-upgrade state, confirm Confluence is running without issues in the pre-upgrade state, and then stop Confluence.
  • Backup the deployment, also backup the Confluence database (since the schema will be altered), and then execute the following SQL:

Below SQL is constructed using the schema name "db_owner" logged in the error (comments included for clarity)

declare @sql varchar(8000), @table varchar(1000), @oldschema varchar(1000), @newschema varchar(1000)

set @oldschema = 'db_owner' -- here is the existing schema name
set @newschema = 'dbo' -- here is the one that is supported

while exists(select * from sys.tables where schema_name(schema_id) = @oldschema)
 begin
 select @table = name from sys.tables
 where object_id in(select min(object_id) from sys.tables where schema_name(schema_id) = @oldschema)
 set @sql = 'alter schema ' + @newschema + ' transfer ' + @oldschema + '.' + @table
 exec(@sql)
 end

Last modified on May 2, 2023

Was this helpful?

Yes
No
Provide feedback about this article
Powered by Confluence and Scroll Viewport.