3

I need to write a SQL Script in DB2 and I have to make a constraint in order for this SQL to run only on some specific DBs.

I looked online for solutions but I did not find any.

Does anybody know a way to get the name of the current connected DB?

1 Answer 1

4

Try this:

Select CURRENT_SERVER from sysibm.sysdummy1

The database name can be retrieved via the special register CURRENT_SERVER.

Sign up to request clarification or add additional context in comments.

3 Comments

Hi data_henrik, your SQL seems to work. I only wonder if it will bring back the accurate Name on other DB. I also found the DB_Name Column in SYSIBMADM->APPLICATIONS->DB_NAME meanwhile. Thank you! I will mark your answer as useful :).
My feedback will be recorded and it'll be displayed soon. Thank you once again :)
CURRENT_SERVER throws an error in DB2 v9. (z/os) CURRENT SERVER works though

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.