# How to use defaultschema in MSSQL

**URL:** <https://forum.liquibase.org/t/how-to-use-defaultschema-in-mssql/5680>\
**Category:** General Discussion\
**Created:** [July 7, 2021, 3:35pm UTC](https://forum.liquibase.org/t/how-to-use-defaultschema-in-mssql/5680 "2021-07-07T15:35:20Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![twleo](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@twleo](https://forum.liquibase.org/u/twleo)\
**Post date:** [July 7, 2021, 3:35pm UTC](https://forum.liquibase.org/t/how-to-use-defaultschema-in-mssql/5680/1 "2021-07-07T15:35:21Z")

</div>

I am new to Liquibase and I have a MSSQL database with multiple schemas and I set the defaultSchemaName in my property file but when I run an liquibase update I am getting the following error. Is defaultSchemaName supported for MSSQL? If yes, how can I resolve this issue? Thanks

Caused by: liquibase.exception.DatabaseException: java.lang.RuntimeException: Cannot use default schema name user on Microsoft SQL Server because the login schema of the current user (dbo) is different and MSSQL does not support setting the default schema per session.  
at liquibase.integration.commandline.CommandLineUtils.createDatabaseObject(CommandLineUtils.java:125)  
at liquibase.integration.commandline.Main.doMigration(Main.java:1520)  
at liquibase.integration.commandline.Main$1.lambda$run$0(Main.java:399)  
at liquibase.Scope.lambda$child$0(Scope.java:166)  
at liquibase.Scope.child(Scope.java:175)  
at liquibase.Scope.child(Scope.java:165)  
at liquibase.Scope.child(Scope.java:144)  
at liquibase.integration.commandline.Main$1.run(Main.java:398)

---

<div class="post-metadata">

**Author:** ![ahmedabdeljelil](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/ahmedabdeljelil/32/397_2.png) [@ahmedabdeljelil](https://forum.liquibase.org/u/ahmedabdeljelil)\
**Post date:** [July 8, 2021, 1:05pm UTC](https://forum.liquibase.org/t/how-to-use-defaultschema-in-mssql/5680/2 "2021-07-08T13:05:38Z")

</div>

Try to create a property file like this one:

changeLogFile: …/path/to/file/dbchangelog.xml  
driver: oracle.jdbc.OracleDriver  
url: jdbc:oracle:thin:@192.168.0.22:1521/orcl  
username: PRO  
password: password  
classpath: …/path/to/file/ojdbc6-11.2.0.3.0.jar  
defaultSchemaName: your schema name

---

<div class="post-metadata">

**Author:** ![twleo](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@twleo](https://forum.liquibase.org/u/twleo)\
**Post date:** [July 8, 2021, 1:20pm UTC](https://forum.liquibase.org/t/how-to-use-defaultschema-in-mssql/5680/3 "2021-07-08T13:20:56Z")

</div>

Thanks for your response. I am using SQL Server but I do have the defaultSchemaName in my property file and the error posted was what I got when I run the update.

---

<div class="post-metadata">

**Author:** ![rakhi](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.liquibase.org/rakhi/32/288_2.png) [@rakhi](https://forum.liquibase.org/u/rakhi)\
**Post date:** [July 9, 2021, 5:06am UTC](https://forum.liquibase.org/t/how-to-use-defaultschema-in-mssql/5680/4 "2021-07-09T05:06:53Z")

</div>

Hi @twleo

Could you please share below details:

1. Your liquibase.properties file
2. Liquibase version you are using

Thanks,  
Rakhi Agrawal

---

<div class="post-metadata">

**Author:** ![twleo](https://avatars.discourse-cdn.com/v4/letter/t/c0e974/32.png) [@twleo](https://forum.liquibase.org/u/twleo)\
**Post date:** [July 12, 2021, 1:00pm UTC](https://forum.liquibase.org/t/how-to-use-defaultschema-in-mssql/5680/5 "2021-07-12T13:00:37Z")

</div>

Below is my property file. Liquibase version is 4.4.0. Thanks

classpath=C:\Program Files\liquibase\lib\sqljdbc\_9.2\enu\mssql-jdbc-9.2.1.jre15.jar  
driver=com.microsoft.sqlserver.jdbc.SQLServerDriver  
url=jdbc:sqlserver://localhost:61466;instance=SQLEXPRESS;databaseName=License  
username=username  
password=pswd  
changeLogFile=MasterChangeLog.xml  
log-level=info

defaultSchemaName=user  
liquibase.hub.mode=off

---

<div class="post-metadata">

**Author:** ![tedk](https://avatars.discourse-cdn.com/v4/letter/t/b19c9b/32.png) [@tedk](https://forum.liquibase.org/u/tedk)\
**Post date:** [October 31, 2023, 5:26pm UTC](https://forum.liquibase.org/t/how-to-use-defaultschema-in-mssql/5680/6 "2023-10-31T17:26:20Z")

</div>

Twleo, MS defaults the schema at the user level so you need to set the schema of the user you are using on the database side.

ALTER USER [userName] WITH DEFAULT\_SCHEMA=[targetDB]  
GO

After you run the extraction remember to set the schema back to the previous default (often dbo)

ALTER USER [userName] WITH DEFAULT\_SCHEMA=[dbo]  
GO

Check the extracted files to make sure they are specifying the schema if you want to preserve it.

The other caveat is that you can only pull objects from a single schema at a time.
