The SET Language is one of the SQL Server SET Statement that change the default language for the session. The session language determines the datetime formats and system messages.
SYNTAX
SET LANGUAGE [ N ] 'language'
Lets look at an example of using SET Language in SQL Server.
First we check the name of the language currently being used using @@Language function.
SELECT @@LANGUAGE AS 'Language Name'
As you can see, currently the default language ‘US English’ is being used by SQL Server.
Change the default Language using SET Language
Lets use the SET Language Statement to change the default language from US English to Spanish, and select a Month Name from current date.
SET LANGUAGE Spanish; SELECT @@LANGUAGE AS 'Language Name', DATENAME(month, GETDATE()) AS 'Month Name';
You can see, Now current language is set to Spanish and also Month Name is returned by Function is in Spanish Language.
You can also see, now system messages is also changed to Spanish language.
Lets produce an error case, where SQL Server will return an error message, in following statement we purposely try to convert non convertible string into Date format and that returns an error in Spanish language.
SELECT CAST('Hello world' AS DATE) ;
Lets change the default language back to US English, and then execute all above scripts again.
Following statement returns, current language being used by SQL Server, and month name in English.
SET LANGUAGE us_english; SELECT @@Language AS 'Language Name', DATENAME(month, GETDATE()) AS 'Month Name' ;
SELECT CAST('Hello world' AS DATE) ;
