Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running a log parser to find SQL errors in my log files. If the search string (regular expression) is evaluated to true, the line will be marked. So far I used the search expression "SQL0", which was given to me by our DBAs. However, I recently discovered that there are noteworthy SQL Errors that start with "SQL1".

I found some references, that negative SQL error codes mean that the statement was unsuccessful. So my current idea is to search for "SQL[0-9]+N" (SQL error messages were the number ends with an N). Will this find all SQL error codes?

Update: I am running automated scripts on a DB2 database. I need to parse the logs of these scripts to verify if errors occurred during execution.

share|improve this question
SQL is a language for querying relational datastores. – womble May 2 '12 at 13:22
I don't know much about DB2 but I suspect this Wikipedia page indicates that there are more possible error codes than what you're currently searching for. – Ladadadada May 2 '12 at 13:34
@womble: You are right with your statement, but what does it have to do with the question? My systems automatically runs database scripts that run SQL statements. In my case these scripts do funky stuff like dropping databases, recreate these databases (tables, indexes, sequences, grants, ...) and loading a set of initial data. Works pretty nice the most times but not always. So I need to search the logs for these error messages that incidentally start with the three letters 'SQL'. However, not everything that starts with these letters should be considered an Error. Therefor my question. – Peter Schuetze May 2 '12 at 16:01
I think you worked it out with your update. – womble May 2 '12 at 21:50
up vote 1 down vote accepted

Finally I found what I was looking for:

Message Structure

Message help describes the cause of a message and describes any action you should take in response to the message.

Message identifiers consist of a three character message prefix, followed by a four or five digit message number, followed by a single letter suffix. For example, SQL1042C. For a list of message prefixes, see Invoking message help and Other DB2 Messages. The single letter suffix describes the severity of the error message.

In general, message identifiers ending with a C are for severe messages; those ending with an E indicate urgent messages; those ending with an N indicate error messages; those ending with a W indicate warning messages; and those ending with an I indicate informational message.


For SQL messages, message identifiers ending with a C indicate critical system errors; those ending with an N indicate error messages; those ending with a W indicate warning or informational messages.


share|improve this answer

If I understand what I found in Google correctly, your error messages look like this:

SQL0204N "Some string explaining the error."

It seems that the number is the error code and I would guess that the leading 0 indicates that this example is negative error code 204. A leading 1 in the number will be for positive error codes so 1204 is +204 and 0204 is -204.

Grepping for "SQL[0-9]+N" will find all error messages that match that pattern, however I can't verify that DB2 will not produce other types of errors.

share|improve this answer
So you thing that the 0 stands for a critical error (equivalent to minus sign). I was guessing that the N might be the negative indicator. Will look for the SQL1... again to check how critical it is. – Peter Schuetze May 2 '12 at 15:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.