# \[v1.9.3\] Not detecting existing DATABASECHANGELOG table in MS SQLServer database

**URL:** <https://forum.liquibase.org/t/v1-9-3-not-detecting-existing-databasechangelog-table-in-ms-sqlserver-database/445>\
**Category:** General Discussion\
**Created:** [February 4, 2010, 9:17pm UTC](https://forum.liquibase.org/t/v1-9-3-not-detecting-existing-databasechangelog-table-in-ms-sqlserver-database/445 "2010-02-04T21:17:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![evan.leonard](https://avatars.discourse-cdn.com/v4/letter/e/6a8cbe/32.png) [@evan.leonard](https://forum.liquibase.org/u/evan.leonard)\
**Post date:** [February 4, 2010, 9:17pm UTC](https://forum.liquibase.org/t/v1-9-3-not-detecting-existing-databasechangelog-table-in-ms-sqlserver-database/445/1 "2010-02-04T21:17:00Z")

</div>

Hi all,

I’m running into a situation where liquibase is not detecting that a certain MS SQL Server db already has the DATABASECHANGELOG and LOCK tables it in, and as a result is trying to create them and then run ALL of the migrations again.

I think it may have something to do with the user account. When I look at the database in SQLServer Management Studio it shows all the tables prefixed with the username. This is the same username that I am using to establish the connection to the database, so it _shouldn’t_ be an issue. But may still be.

Any help would be appreciated.

Thank you,  
Evan

---

<div class="post-metadata">

**Author:** ![karl\_puperze](https://avatars.discourse-cdn.com/v4/letter/k/b487fb/32.png) [@karl\_puperze](https://forum.liquibase.org/u/karl_puperze)\
**Post date:** [February 4, 2010, 9:17pm UTC](https://forum.liquibase.org/t/v1-9-3-not-detecting-existing-databasechangelog-table-in-ms-sqlserver-database/445/2 "2010-02-04T21:17:00Z")

</div>

I had the same problem, but I only fixed it for 2.0RC1. LiquiBase is looking to databasechangelog in the meta data instead of DATABASECHANGELOG. My solution was to override MSSQLDatabaseSnapshotGenerator#convertTableNameToDatabaseTableName and not to lower case the table name.

public class MSSQLDatabaseSnapshotGenerator extends liquibase.snapshot.core.MSSQLDatabaseSnapshotGenerator {

&nbsp; @Override  
&nbsp; public int getPriority(Database database) {  
&nbsp; &nbsp; return database instanceof MSSQLDatabase ? PRIORITY\_DATABASE + 1 : PRIORITY\_DATABASE;  
&nbsp; }  
&nbsp;  
&nbsp; @Override  
&nbsp; protected String convertTableNameToDatabaseTableName(String tableName) {  
&nbsp; &nbsp; &nbsp; return tableName;  
&nbsp; }  
&nbsp;  
}

When you place this class in liquibase.ext.snapshot it will be loaded in 2.0.

---

<div class="post-metadata">

**Author:** ![evan.leonard](https://avatars.discourse-cdn.com/v4/letter/e/6a8cbe/32.png) [@evan.leonard](https://forum.liquibase.org/u/evan.leonard)\
**Post date:** [February 4, 2010, 9:17pm UTC](https://forum.liquibase.org/t/v1-9-3-not-detecting-existing-databasechangelog-table-in-ms-sqlserver-database/445/3 "2010-02-04T21:17:00Z")

</div>

Thanks for the reply.&nbsp; I got a little further with this problem.&nbsp; It seems that the database I was connecting to had a “schema” with a different name than the database or catalogname.&nbsp; I guess in SQL Server 2005 and later the notion of a “schema” became just a namespace within a database. So the hierarchy is like this:&nbsp; A Db server has many catalogs which have many schemas.

The solution was to set the defaultSchemaName on the Database object.&nbsp; The funny thing is that it turned out to be relatively easy to get the schema in the current database:

“SELECT DISTINCT SCHEMA\_NAME(schema\_id) FROM sys.tables”

So I basically took the return from that query and set the defaultSchemaName to that value.&nbsp; It is possible that this query might return multiple results if you have multiple schemas in your db/catalog, but that is never the case for our product.

Evan
