Does Compatibility Level allow unsupported functions?












4














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?










share|improve this question







New contributor




BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    4














    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?










    share|improve this question







    New contributor




    BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      4












      4








      4







      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?










      share|improve this question







      New contributor




      BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      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






      share|improve this question







      New contributor




      BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Dec 17 at 15:02









      BeardOfTriumph

      555




      555




      New contributor




      BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      BeardOfTriumph is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          3 Answers
          3






          active

          oldest

          votes


















          9















          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.






          share|improve this answer























          • Thank you. Sounds like I had a misunderstanding of what it should be used for.
            – BeardOfTriumph
            Dec 17 at 15:18





















          3














          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.






          share|improve this answer





























            0














            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.






            share|improve this answer





















              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.










              draft saved

              draft discarded


















              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









              9















              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.






              share|improve this answer























              • Thank you. Sounds like I had a misunderstanding of what it should be used for.
                – BeardOfTriumph
                Dec 17 at 15:18


















              9















              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.






              share|improve this answer























              • Thank you. Sounds like I had a misunderstanding of what it should be used for.
                – BeardOfTriumph
                Dec 17 at 15:18
















              9












              9








              9







              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.






              share|improve this answer















              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.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              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




















              • 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















              3














              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.






              share|improve this answer


























                3














                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.






                share|improve this answer
























                  3












                  3








                  3






                  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.






                  share|improve this answer












                  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.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Dec 17 at 15:23









                  sepupic

                  6,751817




                  6,751817























                      0














                      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.






                      share|improve this answer


























                        0














                        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.






                        share|improve this answer
























                          0












                          0








                          0






                          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.






                          share|improve this answer












                          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.







                          share|improve this answer












                          share|improve this answer



                          share|improve this answer










                          answered Dec 18 at 8:38









                          Tibor Karaszi

                          1,4816




                          1,4816






















                              BeardOfTriumph is a new contributor. Be nice, and check out our Code of Conduct.










                              draft saved

                              draft discarded


















                              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.




                              draft saved


                              draft discarded














                              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





















































                              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







                              Popular posts from this blog

                              Список кардиналов, возведённых папой римским Каликстом III

                              Deduzione

                              Mysql.sock missing - “Can't connect to local MySQL server through socket”