By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,688 Members | 1,888 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,688 IT Pros & Developers. It's quick & easy.

Determine Database Name or Instance Name from SQL in DB2

P: n/a
Is it possible with a SQL query against a system table to determine
what the database name or instance name is that you are logged into?
We are on DB2 8.1.6.
Spencer
Nov 12 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
I'd look at the snapshot table functions for this.. Just a guess.

Cheers
Serge
Nov 12 '05 #2

P: n/a
Ian
Spencer wrote:
Is it possible with a SQL query against a system table to determine
what the database name or instance name is that you are logged into?
We are on DB2 8.1.6.
Spencer


In SQL, you can use 'CURRENT SERVER' special register to return the name
of the database you're connected to, as in:

"insert into mytable (database) values (current server)"

I don't think you can get the instance within SQL, without writing a
UDF.

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 12 '05 #3

P: n/a
Thanks Ian. This is exactly what I was looking for!

SELECT CURRENT SERVER
FROM SYSIBM.SYSDUMMY1;
Ian <ia*****@mobileaudio.com> wrote in message news:<41**********@corp.newsgroups.com>...
Spencer wrote:
Is it possible with a SQL query against a system table to determine
what the database name or instance name is that you are logged into?
We are on DB2 8.1.6.
Spencer


In SQL, you can use 'CURRENT SERVER' special register to return the name
of the database you're connected to, as in:

"insert into mytable (database) values (current server)"

I don't think you can get the instance within SQL, without writing a
UDF.

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Nov 12 '05 #4

P: n/a
Ian
Spencer wrote:
Thanks Ian. This is exactly what I was looking for!

SELECT CURRENT SERVER
FROM SYSIBM.SYSDUMMY1;


You can also issue the statement 'values current server' without having
to hit a catalog table.

Still this strikes me as a funny requirement. Don't you know what
database you connected to? You issued a CONNECT TO <db> statement!

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Nov 12 '05 #5

P: n/a
Well you are right it does seem funny at first. However I will not be
running the SQL. This is a batch job and we need to do slightly
different operation if we are in development or production. By being
able to programmitically do this we can take different paths in our
code.
Spencer
Ian <ia*****@mobileaudio.com> wrote in message news:<41**********@corp.newsgroups.com>...
Spencer wrote:
Thanks Ian. This is exactly what I was looking for!

SELECT CURRENT SERVER
FROM SYSIBM.SYSDUMMY1;


You can also issue the statement 'values current server' without having
to hit a catalog table.

Still this strikes me as a funny requirement. Don't you know what
database you connected to? You issued a CONNECT TO <db> statement!

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Nov 12 '05 #6

P: n/a
Maybe wrapping this

To identify the instance to which a user is currently attached, call
sqleatin - Attach, with null arguments except for the sqlca structure.
PM
Nov 12 '05 #7

P: n/a
Ian wrote:
Spencer wrote:
Thanks Ian. This is exactly what I was looking for!

SELECT CURRENT SERVER
FROM SYSIBM.SYSDUMMY1;


You can also issue the statement 'values current server' without having
to hit a catalog table.


You don't hit a catalog table. SYSIBM.SYSDUMMY1 is a view defined like
this:

create view sysibm.sysdummy1 (ibmreqd) as values (char('Y'))

(taken from SYSCAT.VIEWS.TEXT)

--
Knut Stolze
Information Integration
IBM Germany / University of Jena
Nov 12 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.