USE [dbatoolbox]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Connections_Full](
[server] [nvarchar](130) NOT NULL,
[name] [nvarchar](130) NOT NULL,
[login_time] [datetime] NOT NULL,
[last_batch] [datetime] NOT NULL,
[timestamp] [datetime] NOT NULL,
[status] [nvarchar](30) NOT NULL,
[hostname] [nvarchar](130) NOT NULL,
[program_name] [nvarchar](130) NOT NULL,
[nt_username] [nvarchar](130) NOT NULL,
[loginame] [nvarchar](130) NOT NULL
) ON [PRIMARY]
GO
ALTER PROCEDURE [dbo].[usp_ConnectionsCount_full]
AS
BEGIN
SET NOCOUNT ON;
INSERT INTO Connections_Full
SELECT @@ServerName AS SERVER
,NAME
,login_time
,last_batch
,getdate() AS DATE
,status
,hostname
,program_name
,nt_username
,loginame
FROM sys.databases d
LEFT JOIN sys.sysprocesses sp ON d.database_id = sp.dbid
WHERE database_id NOT BETWEEN 0
AND 4
AND loginame IS NOT NULL
END
No comments:
Post a Comment