没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
试读
1页
获取服务器名称: SELECT SERVERPROPERTY('MachineName') select @@SERVERNAME select HOST_NAME() 获取IP地址可以使用xp_cmdshell执行ipconfig命令: --开启xp_cmdshell exec sp_configure'show advanced options', 1 reconfigure with override exec sp_configure'xp_cmdshell', 1 reconfigure with override exec sp_configure'show advanced
资源推荐
资源详情
资源评论
SQL语句实现查询语句实现查询SQL Server服务器名称和服务器名称和IP地址地址
获取服务器名称:
SELECT SERVERPROPERTY('MachineName')
select @@SERVERNAME
select HOST_NAME()
获取IP地址可以使用xp_cmdshell执行ipconfig命令:
--开启xp_cmdshell
exec sp_configure'show advanced options', 1
reconfigure with override
exec sp_configure'xp_cmdshell', 1
reconfigure with override
exec sp_configure'show advanced options', 0
reconfigure with override
go
begin
declare @ipline varchar(200)
declare @pos int
declare @ip varchar(40)
set nocount on
set @ip = null
if object_id('tempdb..#temp') is not null drop table #temp
create table #temp(ipline varchar(200))
insert #temp exec master..xp_cmdshell'ipconfig'
select @ipline = ipline
from #temp
where upper(ipline) like '%IPv4 地址%'--这里需要注意一下,系统不同这里的匹配值就不同
if @ipline is not null
begin
set @pos = charindex(':',@ipline,1);
set @ip = rtrim(ltrim(substring(@ipline ,
@pos + 1 ,
len(@ipline) - @pos)))
end
select distinct(rtrim(ltrim(substring(@ipline ,
@pos + 1 ,
len(@ipline) - @pos)))) as ipaddress from #temp
drop table #temp
set nocount off
end
go
但是很多情况下由于安全问题是不允许使用xp_cmdshell,可以通过查询SYS.DM_EXEC_CONNECTIONS :
SELECT SERVERNAME = CONVERT(NVARCHAR(128),SERVERPROPERTY('SERVERNAME'))
,LOCAL_NET_ADDRESS AS 'IPAddressOfSQLServer'
,CLIENT_NET_ADDRESS AS 'ClientIPAddress'
FROM SYS.DM_EXEC_CONNECTIONS WHERE SESSION_ID = @@SPID
您可能感兴趣的文章您可能感兴趣的文章:SQL Server Table中XML列的操作代码SQLSERVER查询所有数据库名,表名,和字段名的语句SQL
Server SQL高级查询语句小结SQLServer中用T—SQL命令查询一个数据库中有哪些表的sql语句关于SQL Server查询语句的
使用详解SQL Server的简单查询语句SqlServer 基础知识 数据检索、查询排序语句SQL Server中Table字典数据的查询SQL示
例代码
资源评论
weixin_38617335
- 粉丝: 7
- 资源: 918
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功