Why is dbo the default defaultSchemaName for Sql Server?

I’ve got a question about the way the MSSQLDatabase is implemented. I was reading along with this post to try and figure out my default-schema-based woes:

And I don’t understand why Liquibase sets “dbo” as the default schema for MSSQL.  If you don’t specify a schema at all, MSSQL will perform the action on your default schema.  I have a class overriding MSSQLDatabase, replacing #getDefaultSchemaName, #getLiquibaseSchemaName, and #convertRequestedSchemaToSchema so that they don’t return “dbo” anymore-- and everything works fine.

I can’t set the schema name for this particular problem.  It stems from a problem with the Jtds driver – if you have a backslash in your schema name it doesn’t escape the schema name correctly and therefore can’t query the tables correctly – but I’m wondering why this particular decision was made.  If I don’t specify anything, and don’t need to specify anything, why is the code doing it?  Is this a leftover MSSQL 2000 thing? Would it be appropriate to split the classes so the code knows whether it’s running 2000 or 2005/2008 so this isn’t surprising behavior?

Actually, it turns out that the problem with the backslash isn’t a problem with the driver – it’s a problem with Liquibase’s usage of Jdbc drivers.  The Jdbc spec says that for #getTables and many other methods, you’re passing a schema name pattern, not a schema name.  Liquibase needs to be aware of this and turn the String into an actual pattern so that the driver escapes it properly using whatever method it uses (in our case, it’s Sql Server, so \ would turn into [], which is handled correctly by the proc).

I’m patching Liquibase locally so we can move forward with our Sql Server integration and I’ll propose a solution for the next release. 

Glad you found the problem. If you could send what you did to fix it, that would be great.


I want this patch too.