I do not have access to the machine but I want to find out when this sql server was installed?
I have Server View state access which means I can access dmvs but I cannot connect to the machine, I cannot find any DMV with this information.
I don't think this information is held in any of the DMVs but a place I usually look for is the sys.server_principals. Look for the SYSTEM or NETWORK SERVICE logins, this will indicate you when this SQL Server was installed.
Select Create_Date
FROM sys.server_principals
WHERE name = N'NT AUTHORITY\SYSTEM'
OR name = N'NT AUTHORITY\NETWORK SERVICE'
use sys.server_principals
SELECT create_date,*
FROM sys.server_principals
WHERE sid = 0x010100000000000512000000 -- sid of NT AUTHORITY\SYSTEM
Referred from below article by Pinal Dave
SQL SERVER – Retrieve SQL Server Installation Date Time
This article How to find out the SQL Server installation date? has much more options
-- work with only English language installations
SELECT createdate AS 'SQL Server Installation Date'
FROM sys.syslogins
WHERE NAME = 'NT AUTHORITY\SYSTEM'
--neutral language
SELECT createdate AS 'SQL Server Installation Date'
FROM sys.syslogins
WHERE sid = 0x010100000000000512000000
--Using sys.server_principals
SELECT create_date as 'SQL Server Installation Date'
FROM sys.server_principals
WHERE name='NT AUTHORITY\SYSTEM'
Related
In the Microsoft documentation here, we have a list of 'Supported Compatibility Level Values' for each SQL Server version. Is this information persisted in SQL Server? If not, is there any other way to fetch this information?
I looked at the Windows registry already, I did not find it.
Microsoft used to have an approach where each version of SQL Server supported the compatibility level of the current release down to n-2.
Since the release of SQL Server 2016, the previously supported compatibility levels have not been removed (this is intended to assist with the change to certification at the database compatibility level). I'm not completely sure whether 100 will be removed in the next release of SQL Server, but I suspect that it will remain to assist with future upgrade paths.
There is a matrix that shows this pattern.
What this effectively means is that you could query the master database to get the current release compatibility level and then assume that each release down to 100 is also available.
This should be helpfu and exactly what youre after
select name, compatibility_level , version_name =
CASE compatibility_level
WHEN 65 THEN 'SQL Server 6.5'
WHEN 70 THEN 'SQL Server 7.0'
WHEN 80 THEN 'SQL Server 2000'
WHEN 90 THEN 'SQL Server 2005'
WHEN 100 THEN 'SQL Server 2008/R2'
WHEN 110 THEN 'SQL Server 2012'
WHEN 120 THEN 'SQL Server 2014'
WHEN 130 THEN 'SQL Server 2016'
WHEN 140 THEN 'SQL Server 2017'
WHEN 150 THEN 'SQL Server 2019'
ELSE 'new unknown - '+CONVERT(varchar(10),compatibility_level)
END
from sys.databases
Here is a query I use to get basic info on databases from a server. It queries sys.databases. To translate the compatability level you can use this list.
SELECT
name AS [DB Name]
, state_desc AS [Status]
, create_date AS [Create Date]
, database_id AS [DB ID]
, recovery_model_desc AS [Recovery Model]
, SUSER_SNAME(owner_sid) AS [Owner]
, [compatibility_level] AS [Compatibility Level]
, collation_name AS [Collation]
, is_auto_close_on AS [Auto Close]
FROM
sys.databases
ORDER BY
name;
I need query to get server_name, instance_name, machine_name, database_name, recovery_model, isclustered in SQL Server 2012 and above.
Thanks
You should use sys.databases view and add few SERVERPROPERTY metadata informations.
Something like this:
SELECT SERVERPROPERTY('MachineName') AS MachineName,
SERVERPROPERTY('ServerName') AS ServerName,
name AS DatabaseName,
recovery_model_desc AS RecoveryModel
FROM sys.databases
Getting information about Cluster is described here:
TSQL - how to tell if SQL is clustered?
How to find SQLServer Virtual Cluster name
Try this ...
SELECT
SERVERPROPERTY('MachineName') AS ComputerName,
SERVERPROPERTY('ServerName') AS InstanceName,
SERVERPROPERTY('Edition') AS Edition,
SERVERPROPERTY('IsClustered') AS IsClustered,
SERVERPROPERTY('ProductLevel') AS ProductLevel;
GO
More details on properties : https://learn.microsoft.com/en-us/sql/t-sql/functions/serverproperty-transact-sql
THIS TOPIC APPLIES TO:
SQL Server (starting with 2008)
Azure SQL Database
Azure SQL Data
Warehouse Parallel Data Warehouse
Returns property information about the server instance.
How can I monitor the quantity of active connections in SQL Server 2014 using SQL Server 2014 Management Studio?
SELECT * FROM sys.dm_exec_sessions
If active connections means those connections which are executing something right now then one solution is
sys.dm_exec_requests
https://msdn.microsoft.com/en-us/library/ms177648.aspx
"Returns information about each request that is executing within SQL Server."
To get count of active connections we can use:
SELECT COUNT(*)
FROM sys.dm_exec_requests
--Where status = 'Running'
Note: executing requests/statements can have a status. Please see doc for sys.dm_exec_requests.status column.
Using Tsql, how can I find out when MS SQL server was installed?
The NT AUTHORITY\SYSTEM login is created when you install SQL Server, so:
SELECT createdate
FROM sys.syslogins
WHERE name = 'NT AUTHORITY\SYSTEM'
This will return an incorrect result however if you've ever restored the Master database.
It looks like the first 100 principal_id values are reserved in sys.server_principals (SQL Server 2005+). Based on what I see in one of my sys.server_principals (SQL Server 2005, SP3), I'd try this:
SELECT MIN(create_date) FROM sys.server_principals WHERE principal_id > 100
I'm currently using SQL 2000 (it's a vendor server - don't ask...), and I'm wondering if there's a way to detect the connection protocol of connected clients. For SQL 2005+, I use:
select net_transport from sys.dm_exec_connections
where session_id = ##spid
But SQL2000 lacks this dynamic view. Anybody know the equivalent function on SQL2000?
SELECT net_library FROM sysprocesses WHERE spid = ##SPID
You can also sys.sysprocesses in SQL Server 2005/2008. It may be deprecated but there is no equivalent in after SQL 2000 for functionality, says MS Connect 144515