Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. What kind of Errors the SELECT statement can raise??

What kind of Errors the SELECT statement can raise??

Scheduled Pinned Locked Moved Database
tutorialquestion
10 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _J_
    wrote on last edited by
    #1

    What kind of Errors the SELECT statement can raise?? In what cases? How to avoid them? How to handle them? ------------------------------------ To study, study and only to study

    C A 2 Replies Last reply
    0
    • _ _J_

      What kind of Errors the SELECT statement can raise?? In what cases? How to avoid them? How to handle them? ------------------------------------ To study, study and only to study

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      _J_ wrote: What kind of Errors the SELECT statement can raise?? That's kind of like asking "What kind of accidents can my car be involved in?" _J_ wrote: In what cases? When something goes wrong or not specified correctly. _J_ wrote: How to avoid them? Get your permissions sorted out. Don't refer to things that don't exist. Get the syntax right. _J_ wrote: How to handle them? DECLARE @error_number SELECT .... -- Your select statement goes here SET @error_number = @@ERROR -- @@ERROR is very short lived, grab it while you can. IF @error_number = ... -- You can find the error numbers and the errors they relate to in the sysmessages table If you can be more specific then perhaps I can give you a more specific response. There are somewhere in the region of 3900 error / warning messages in SQL Server.


      My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

      _ 1 Reply Last reply
      0
      • C Colin Angus Mackay

        _J_ wrote: What kind of Errors the SELECT statement can raise?? That's kind of like asking "What kind of accidents can my car be involved in?" _J_ wrote: In what cases? When something goes wrong or not specified correctly. _J_ wrote: How to avoid them? Get your permissions sorted out. Don't refer to things that don't exist. Get the syntax right. _J_ wrote: How to handle them? DECLARE @error_number SELECT .... -- Your select statement goes here SET @error_number = @@ERROR -- @@ERROR is very short lived, grab it while you can. IF @error_number = ... -- You can find the error numbers and the errors they relate to in the sysmessages table If you can be more specific then perhaps I can give you a more specific response. There are somewhere in the region of 3900 error / warning messages in SQL Server.


        My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

        _ Offline
        _ Offline
        _J_
        wrote on last edited by
        #3

        Ok. If i perform INSERT INTO ..... the most common error is cannot insert duplicate. However if i perform the SELECT and all parameters in my SELECT statement are ok, i.e. no syntax error and also all columns and tables that i specifyed are exist. So is the posibility of some kind of an error that can occur??? ------------------------------------ To study, study and only to study

        C 1 Reply Last reply
        0
        • _ _J_

          Ok. If i perform INSERT INTO ..... the most common error is cannot insert duplicate. However if i perform the SELECT and all parameters in my SELECT statement are ok, i.e. no syntax error and also all columns and tables that i specifyed are exist. So is the posibility of some kind of an error that can occur??? ------------------------------------ To study, study and only to study

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          _J_ wrote: So is the posibility of some kind of an error that can occur??? Yes. Lots of errors may still occur. Permissions errors, disk space may run out, deadlocking, lots of things.


          My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

          _ 1 Reply Last reply
          0
          • C Colin Angus Mackay

            _J_ wrote: So is the posibility of some kind of an error that can occur??? Yes. Lots of errors may still occur. Permissions errors, disk space may run out, deadlocking, lots of things.


            My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

            _ Offline
            _ Offline
            _J_
            wrote on last edited by
            #5

            So as i understand: SELECT ..., ...., .... ... FROM .... ..... .... SELECT @myERROR = @@ERROR IF @myERROR != 0 here i handle the error, maybe call to RAISEERROR ------------------------------------ To study, study and only to study

            C 1 Reply Last reply
            0
            • _ _J_

              So as i understand: SELECT ..., ...., .... ... FROM .... ..... .... SELECT @myERROR = @@ERROR IF @myERROR != 0 here i handle the error, maybe call to RAISEERROR ------------------------------------ To study, study and only to study

              C Offline
              C Offline
              Colin Angus Mackay
              wrote on last edited by
              #6

              IF @myERROR <> 0 The error will have already have generated a RAISERROR, but you can raise another if you like. It is rather like throwing an exception from within a catch block in C#.


              My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

              _ 1 Reply Last reply
              0
              • C Colin Angus Mackay

                IF @myERROR <> 0 The error will have already have generated a RAISERROR, but you can raise another if you like. It is rather like throwing an exception from within a catch block in C#.


                My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

                _ Offline
                _ Offline
                _J_
                wrote on last edited by
                #7

                I know that errors with severiry less than 10 is an information error(message) so in the C# i can't catch it in the try/catch/finally block, caues of that i will need to raise my error with severity > 10, after this i will catch this error in my application ------------------------------------ To study, study and only to study

                C 1 Reply Last reply
                0
                • _ _J_

                  I know that errors with severiry less than 10 is an information error(message) so in the C# i can't catch it in the try/catch/finally block, caues of that i will need to raise my error with severity > 10, after this i will catch this error in my application ------------------------------------ To study, study and only to study

                  C Offline
                  C Offline
                  Colin Angus Mackay
                  wrote on last edited by
                  #8

                  Sounds reasonable to me. Alternatively you could write the Stored Procedure to exit at that point with the error number as a return code.


                  My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

                  _ 1 Reply Last reply
                  0
                  • C Colin Angus Mackay

                    Sounds reasonable to me. Alternatively you could write the Stored Procedure to exit at that point with the error number as a return code.


                    My: Blog | Photos | Next SQL Presentation WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More

                    _ Offline
                    _ Offline
                    _J_
                    wrote on last edited by
                    #9

                    ok. Thank u. ------------------------------------ To study, study and only to study

                    1 Reply Last reply
                    0
                    • _ _J_

                      What kind of Errors the SELECT statement can raise?? In what cases? How to avoid them? How to handle them? ------------------------------------ To study, study and only to study

                      A Offline
                      A Offline
                      Andy Brummer
                      wrote on last edited by
                      #10

                      Most of the SQL errors are non-recoverable unless you are writing code to design SQL statements. If you commonly get SQL errors then it is a sign that your application isn't using the SQL server properly. For example if you are adding a username/password to a registration database and the username must be unique, you should send a statement that returns different results based on a transacted exist/insert statement rather then trap the exception. Common occurances shouldn't typically appear in error handling or catch blocks.


                      I can imagine the sinking feeling one would have after ordering my book, only to find a laughably ridiculous theory with demented logic once the book arrives - Mark McCutcheon

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups