Does Compatibility Level allow unsupported functions?
I've got a SQL Server 2016 instance with a database on it, running with a compatibility level of 2008. However, the following dummy proc creates, and executes just fine.
CREATE PROC usp_TestFormat
AS
BEGIN
SELECT FORMAT(CAST('10/25/2018' AS DATE), 'MMM') AS Month;
END;
However FORMAT() is a 2012+ function, so when I tried to take a stored proc I'd written in above database, or the test proc above even, and deploy it to our production database, that is running on a 2008r2 box, it fails, as it doesn't recognize the function. It was my understanding that compatibility levels would prevent this type of behavior, as I'm now having to go through and re-work the code that uses the format function. Is this a bug, or am I not understanding Compatibility levels as much as I thought?
sql-server sql-server-2008-r2
New contributor
add a comment |
I've got a SQL Server 2016 instance with a database on it, running with a compatibility level of 2008. However, the following dummy proc creates, and executes just fine.
CREATE PROC usp_TestFormat
AS
BEGIN
SELECT FORMAT(CAST('10/25/2018' AS DATE), 'MMM') AS Month;
END;
However FORMAT() is a 2012+ function, so when I tried to take a stored proc I'd written in above database, or the test proc above even, and deploy it to our production database, that is running on a 2008r2 box, it fails, as it doesn't recognize the function. It was my understanding that compatibility levels would prevent this type of behavior, as I'm now having to go through and re-work the code that uses the format function. Is this a bug, or am I not understanding Compatibility levels as much as I thought?
sql-server sql-server-2008-r2
New contributor
add a comment |
I've got a SQL Server 2016 instance with a database on it, running with a compatibility level of 2008. However, the following dummy proc creates, and executes just fine.
CREATE PROC usp_TestFormat
AS
BEGIN
SELECT FORMAT(CAST('10/25/2018' AS DATE), 'MMM') AS Month;
END;
However FORMAT() is a 2012+ function, so when I tried to take a stored proc I'd written in above database, or the test proc above even, and deploy it to our production database, that is running on a 2008r2 box, it fails, as it doesn't recognize the function. It was my understanding that compatibility levels would prevent this type of behavior, as I'm now having to go through and re-work the code that uses the format function. Is this a bug, or am I not understanding Compatibility levels as much as I thought?
sql-server sql-server-2008-r2
New contributor
I've got a SQL Server 2016 instance with a database on it, running with a compatibility level of 2008. However, the following dummy proc creates, and executes just fine.
CREATE PROC usp_TestFormat
AS
BEGIN
SELECT FORMAT(CAST('10/25/2018' AS DATE), 'MMM') AS Month;
END;
However FORMAT() is a 2012+ function, so when I tried to take a stored proc I'd written in above database, or the test proc above even, and deploy it to our production database, that is running on a 2008r2 box, it fails, as it doesn't recognize the function. It was my understanding that compatibility levels would prevent this type of behavior, as I'm now having to go through and re-work the code that uses the format function. Is this a bug, or am I not understanding Compatibility levels as much as I thought?
sql-server sql-server-2008-r2
sql-server sql-server-2008-r2
New contributor
New contributor
New contributor
asked Dec 17 at 15:02
BeardOfTriumph
555
555
New contributor
New contributor
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
Is this a bug, or am I not understanding Compatibility levels as much as I thought?
Not a bug. The Compatibility Levels are intended solely to make upgrading easier. IE to prevent errors or changes in behavior when you upgrade to a newer version of SQL Server.
After you upgrade to a new version of SQL Server, you might want to take advantage of new features and capabilities without changing the Database Compatibility Level, so where possible, new TSQL language features are not blocked by your lower Compatibility Level.
Thank you. Sounds like I had a misunderstanding of what it should be used for.
– BeardOfTriumph
Dec 17 at 15:18
add a comment |
This is not a bug, you just misunderstand the compatibility level
.
You cannot use features of 2012
such as lead()
, lag()
, format()
in 2008 because they only appeared in 2012
.
But you are permitted to use them as you are on 2012
, even if database has lower compatibility level
.
Here is a BOL article ALTER DATABASE (Transact-SQL) Compatibility Level that states:
Database compatibility level provides only partial backward
compatibility with earlier versions of SQL Server.
The classic scenario for why you might want to use an older database compatibility level is an upgrade to a newer version of SQL Server.
For example, your query plans
might change because of use of newer cardinality estimatior
, so the execution becomes slower and you want to generate similar plans as you had on the older version. When these queries are not numerous, you can use query hints to use the old estimator at query level
, but if these are almost all your procs you want to change your db compatibility level
to older one to preserve good (old) plans.
add a comment |
In addition to the other posts: It seems like MS tries to, where possible, add new language elements without making them keywords. If a new language element is a keyword, then you can have objects with the same name, and that will cause confusion. In general, when that happens, the new language element is only available in newer compatibility level (since it requires you to encapsulate the object name in [square brakets] or "double quotes" if you had such. But by not making the new language elements keywords, then can allow for them in lower compatibility level. In general. So, in short, where it doesn't "break" anything and it seems safe, then the language element will be available in lower compatibility levels as well.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "182"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
BeardOfTriumph is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f225171%2fdoes-compatibility-level-allow-unsupported-functions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
Is this a bug, or am I not understanding Compatibility levels as much as I thought?
Not a bug. The Compatibility Levels are intended solely to make upgrading easier. IE to prevent errors or changes in behavior when you upgrade to a newer version of SQL Server.
After you upgrade to a new version of SQL Server, you might want to take advantage of new features and capabilities without changing the Database Compatibility Level, so where possible, new TSQL language features are not blocked by your lower Compatibility Level.
Thank you. Sounds like I had a misunderstanding of what it should be used for.
– BeardOfTriumph
Dec 17 at 15:18
add a comment |
Is this a bug, or am I not understanding Compatibility levels as much as I thought?
Not a bug. The Compatibility Levels are intended solely to make upgrading easier. IE to prevent errors or changes in behavior when you upgrade to a newer version of SQL Server.
After you upgrade to a new version of SQL Server, you might want to take advantage of new features and capabilities without changing the Database Compatibility Level, so where possible, new TSQL language features are not blocked by your lower Compatibility Level.
Thank you. Sounds like I had a misunderstanding of what it should be used for.
– BeardOfTriumph
Dec 17 at 15:18
add a comment |
Is this a bug, or am I not understanding Compatibility levels as much as I thought?
Not a bug. The Compatibility Levels are intended solely to make upgrading easier. IE to prevent errors or changes in behavior when you upgrade to a newer version of SQL Server.
After you upgrade to a new version of SQL Server, you might want to take advantage of new features and capabilities without changing the Database Compatibility Level, so where possible, new TSQL language features are not blocked by your lower Compatibility Level.
Is this a bug, or am I not understanding Compatibility levels as much as I thought?
Not a bug. The Compatibility Levels are intended solely to make upgrading easier. IE to prevent errors or changes in behavior when you upgrade to a newer version of SQL Server.
After you upgrade to a new version of SQL Server, you might want to take advantage of new features and capabilities without changing the Database Compatibility Level, so where possible, new TSQL language features are not blocked by your lower Compatibility Level.
edited Dec 17 at 15:18
answered Dec 17 at 15:14
David Browne - Microsoft
10.4k725
10.4k725
Thank you. Sounds like I had a misunderstanding of what it should be used for.
– BeardOfTriumph
Dec 17 at 15:18
add a comment |
Thank you. Sounds like I had a misunderstanding of what it should be used for.
– BeardOfTriumph
Dec 17 at 15:18
Thank you. Sounds like I had a misunderstanding of what it should be used for.
– BeardOfTriumph
Dec 17 at 15:18
Thank you. Sounds like I had a misunderstanding of what it should be used for.
– BeardOfTriumph
Dec 17 at 15:18
add a comment |
This is not a bug, you just misunderstand the compatibility level
.
You cannot use features of 2012
such as lead()
, lag()
, format()
in 2008 because they only appeared in 2012
.
But you are permitted to use them as you are on 2012
, even if database has lower compatibility level
.
Here is a BOL article ALTER DATABASE (Transact-SQL) Compatibility Level that states:
Database compatibility level provides only partial backward
compatibility with earlier versions of SQL Server.
The classic scenario for why you might want to use an older database compatibility level is an upgrade to a newer version of SQL Server.
For example, your query plans
might change because of use of newer cardinality estimatior
, so the execution becomes slower and you want to generate similar plans as you had on the older version. When these queries are not numerous, you can use query hints to use the old estimator at query level
, but if these are almost all your procs you want to change your db compatibility level
to older one to preserve good (old) plans.
add a comment |
This is not a bug, you just misunderstand the compatibility level
.
You cannot use features of 2012
such as lead()
, lag()
, format()
in 2008 because they only appeared in 2012
.
But you are permitted to use them as you are on 2012
, even if database has lower compatibility level
.
Here is a BOL article ALTER DATABASE (Transact-SQL) Compatibility Level that states:
Database compatibility level provides only partial backward
compatibility with earlier versions of SQL Server.
The classic scenario for why you might want to use an older database compatibility level is an upgrade to a newer version of SQL Server.
For example, your query plans
might change because of use of newer cardinality estimatior
, so the execution becomes slower and you want to generate similar plans as you had on the older version. When these queries are not numerous, you can use query hints to use the old estimator at query level
, but if these are almost all your procs you want to change your db compatibility level
to older one to preserve good (old) plans.
add a comment |
This is not a bug, you just misunderstand the compatibility level
.
You cannot use features of 2012
such as lead()
, lag()
, format()
in 2008 because they only appeared in 2012
.
But you are permitted to use them as you are on 2012
, even if database has lower compatibility level
.
Here is a BOL article ALTER DATABASE (Transact-SQL) Compatibility Level that states:
Database compatibility level provides only partial backward
compatibility with earlier versions of SQL Server.
The classic scenario for why you might want to use an older database compatibility level is an upgrade to a newer version of SQL Server.
For example, your query plans
might change because of use of newer cardinality estimatior
, so the execution becomes slower and you want to generate similar plans as you had on the older version. When these queries are not numerous, you can use query hints to use the old estimator at query level
, but if these are almost all your procs you want to change your db compatibility level
to older one to preserve good (old) plans.
This is not a bug, you just misunderstand the compatibility level
.
You cannot use features of 2012
such as lead()
, lag()
, format()
in 2008 because they only appeared in 2012
.
But you are permitted to use them as you are on 2012
, even if database has lower compatibility level
.
Here is a BOL article ALTER DATABASE (Transact-SQL) Compatibility Level that states:
Database compatibility level provides only partial backward
compatibility with earlier versions of SQL Server.
The classic scenario for why you might want to use an older database compatibility level is an upgrade to a newer version of SQL Server.
For example, your query plans
might change because of use of newer cardinality estimatior
, so the execution becomes slower and you want to generate similar plans as you had on the older version. When these queries are not numerous, you can use query hints to use the old estimator at query level
, but if these are almost all your procs you want to change your db compatibility level
to older one to preserve good (old) plans.
answered Dec 17 at 15:23
sepupic
6,751817
6,751817
add a comment |
add a comment |
In addition to the other posts: It seems like MS tries to, where possible, add new language elements without making them keywords. If a new language element is a keyword, then you can have objects with the same name, and that will cause confusion. In general, when that happens, the new language element is only available in newer compatibility level (since it requires you to encapsulate the object name in [square brakets] or "double quotes" if you had such. But by not making the new language elements keywords, then can allow for them in lower compatibility level. In general. So, in short, where it doesn't "break" anything and it seems safe, then the language element will be available in lower compatibility levels as well.
add a comment |
In addition to the other posts: It seems like MS tries to, where possible, add new language elements without making them keywords. If a new language element is a keyword, then you can have objects with the same name, and that will cause confusion. In general, when that happens, the new language element is only available in newer compatibility level (since it requires you to encapsulate the object name in [square brakets] or "double quotes" if you had such. But by not making the new language elements keywords, then can allow for them in lower compatibility level. In general. So, in short, where it doesn't "break" anything and it seems safe, then the language element will be available in lower compatibility levels as well.
add a comment |
In addition to the other posts: It seems like MS tries to, where possible, add new language elements without making them keywords. If a new language element is a keyword, then you can have objects with the same name, and that will cause confusion. In general, when that happens, the new language element is only available in newer compatibility level (since it requires you to encapsulate the object name in [square brakets] or "double quotes" if you had such. But by not making the new language elements keywords, then can allow for them in lower compatibility level. In general. So, in short, where it doesn't "break" anything and it seems safe, then the language element will be available in lower compatibility levels as well.
In addition to the other posts: It seems like MS tries to, where possible, add new language elements without making them keywords. If a new language element is a keyword, then you can have objects with the same name, and that will cause confusion. In general, when that happens, the new language element is only available in newer compatibility level (since it requires you to encapsulate the object name in [square brakets] or "double quotes" if you had such. But by not making the new language elements keywords, then can allow for them in lower compatibility level. In general. So, in short, where it doesn't "break" anything and it seems safe, then the language element will be available in lower compatibility levels as well.
answered Dec 18 at 8:38
Tibor Karaszi
1,4816
1,4816
add a comment |
add a comment |
BeardOfTriumph is a new contributor. Be nice, and check out our Code of Conduct.
BeardOfTriumph is a new contributor. Be nice, and check out our Code of Conduct.
BeardOfTriumph is a new contributor. Be nice, and check out our Code of Conduct.
BeardOfTriumph is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Database Administrators Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f225171%2fdoes-compatibility-level-allow-unsupported-functions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown