In SQL Server, you can find out the default language for a given user by querying the sys.server_principals
system catalog view.
This view contains a row for every server-level principal. It contains information such as the principal’s name, type, create/modify date, default database, default language, etc. A principal is an entity that can request SQL Server resources.
A principal could be any of the following:
Windows-level principals
- Windows Domain Login
- Windows Local Login
SQL Server-level principal
- SQL Server Login
Database-level principals
- Database User
- Database Role
- Application Role
Example of Returning the Default Language of a Principal
To get the default language for a given principal, you can query the sys.server_principals
view and use a WHERE
clause for the principal name that you’re interested in.
Like this:
SELECT type_desc, default_database_name, default_language_name FROM master.sys.server_principals WHERE name = 'sa';
Result:
+-------------+-------------------------+-------------------------+ | type_desc | default_database_name | default_language_name | |-------------+-------------------------+-------------------------| | SQL_LOGIN | master | us_english | +-------------+-------------------------+-------------------------+
This example gets the default language for the sa
principal. The principal name is unique within a server. This example also returns the default database as well as the principal type. In this case the principal is a SQL Server Login.
Here’s another example using a different user:
SELECT type_desc, default_database_name, default_language_name FROM master.sys.server_principals WHERE name = 'Bach';
Result:
+-------------+-------------------------+-------------------------+ | type_desc | default_database_name | default_language_name | |-------------+-------------------------+-------------------------| | SQL_LOGIN | Music | German | +-------------+-------------------------+-------------------------+
In this case, the login has a different default database and language.
Of course, you can always use an asterisk to return all columns if required.
Note that any login can see their own login name, the system logins, and the fixed server roles. To see other logins, requires ALTER ANY LOGIN
, or a permission on the login. To see user-defined server roles, requires ALTER ANY SERVER ROLE
, or membership in the role.
Default Language vs Current Language
In most cases, a user’s current language for their session will be their default language. But this isn’t always necessarily the case, because a user can change the current language by using the SET LANGUAGE
statement. This will change the language for the current session, but their default language will remain at whatever it is.
To find out more, see How to Set the Current Language in SQL Server (T-SQL) and 3 Ways to Get the Language of the Current Session in SQL Server (T-SQL).