Is there a way to get information about a server using SQL

六月ゝ 毕业季﹏ 提交于 2020-01-24 17:55:07

问题


Is there a way to get information about a server using SQL? It is an Oracle database using a windows server. I searched google and all I found was @@version which does not work. Thanks for your help.


回答1:


Here is a good list of the main informations retrieve routines. Be sure this is the best way to obtain Server infos:

Oracle

Version: PL/SQL, TNS versions using with Oracle.

SELECT * FROM v$version;
-- Which version of oracle you are running.
SELECT * FROM v$version WHERE banner LIKE 'Oracle%';
-- Or, in more readable way.
SELECT * FROM product_component_version;

Instance: Displays the state of the current instance.

SELECT * FROM v$instance;
-- About license limits of the current instance.
SELECT * FROM v$license;

Database: Db Name.

SELECT * FROM GLOBAL_NAME
--Db IP Address.
SELECT UTL_INADDR.get_host_address FROM dual
--Db Host Name.
SELECT UTL_INADDR.GET_HOST_NAME('above ip address') FROM dual

Client: Client IP Address.

SELECT SYS_CONTEXT('USERENV','IP_ADDRESS') FROM dual
--Db Host Name
SELECT SYS_CONTEXT('USERENV','TERMINAL') FROM dual
--Db Host Name with domain.
SELECT SYS_CONTEXT('USERENV','HOST') FROM dual
--Current Client session details who using DB.
SELECT * FROM v$session WHERE username = 'User/Schema name'
--To which DB user connected to.
SELECT SUBSTR(GLOBAL_NAME, 1, INSTR(GLOBAL_NAME,'.')-1) FROM GLOBAL_NAME

SQL Server

Version: Which versions of Sql sever you are running.

SELECT @@VERSION
SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY ('edition')
-- SERVERPROPERTY Returns property information about the server instance.

Client: Client details (IP Address, Machine Name, Instance using).

SELECT con.client_net_address as IPAddress,
         sess.host_name as MachineName, sess.program_name as ApplicationName,
         login_name as LoginName
FROM sys.dm_exec_connections con
inner join sys.dm_exec_sessions sess
on con.session_ID=sess.session_ID
WHERE con.session_ID = @@SPID

For more details: http://msdn.microsoft.com/en-us/library/ms174396.aspx




回答2:


I really don't know why you are doing this since there are several better ways to get more info of your database, nevertheless:

Try this:

select * from v$version;

If it returns result, it is Oracle.

If not try this:

SELECT @@VERSION

If it returns result it is SQL Server.



来源:https://stackoverflow.com/questions/16565829/is-there-a-way-to-get-information-about-a-server-using-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!