T-SQL Statement 1
The following T-SQL statement retrieves information such as Hostname, Current instance name, Edition, Server type, ServicePack and version number from current SQL Server connection. 'Edition' will give information on a 32 bit or 64 bit architecture and 'Productlevel' gives information about what service pack your SQL Server is on. It also displays if the current SQL Server is a clustered server. Refer Fig 1.1
SELECT
SERVERPROPERTY('MachineName') as Host,
SERVERPROPERTY('InstanceName') as Instance,
SERVERPROPERTY('Edition') as Edition, /*shows 32 bit or 64 bit*/
SERVERPROPERTY('ProductLevel') as ProductLevel, /* RTM or SP1 etc*/
Case SERVERPROPERTY('IsClustered') when 1 then 'CLUSTERED' else
'STANDALONE' end as ServerType,
@@VERSION as VersionNumber
T-SQL Statement 2
Server level configuration controls some of the features and performance of SQL Server. It is also important for a SQL Server DBA to know the server level configuration information. The following SQL Statement will give all of the information related to Server level configuration. Refer Fig 1.2
SELECT * from sys.configurations order by NAME
If you are using SQL Server 2000, you can execute the following command instead.
SP_CONFIGURE 'show advanced options',1
go
RECONFIGURE with OVERRIDE
go
SP_CONFIGURE
go
T-SQL Statement 3
Security is a very important aspect that a DBA should know about. It is also important to know which login has a sysadmin or security admin server level role. The following SQL Command will show information related to the security admin server role and system admin server role. Refer Fig 1.3
SELECT l.name, l.denylogin, l.isntname, l.isntgroup, l.isntuser
FROM master.dbo.syslogins l
WHERE l.sysadmin = 1 OR l.securityadmin = 1
T-SQL Statement 4
Another important bit of information that you need to know as a DBA is all of the traces that are enabled. The following T-SQL statement will list all of the trace flags that are enabled gloabally on the server. Refer Fig 1.4
DBCC TRACESTATUS(-1);
The following T-SQL statement will list all the trace flags that are enabled on the current sql server connection. Refer Fig 1.4
DBCC TRACESTATUS();
T-SQL Statement 5
Getting Database level information is equally as important as Server level information. The following T-SQL statement gives information on the database names, their compatibility level and also the recovery model and their current status. The result from this T-SQL Statement will help you to determine if there is any compatibility level update necessary. When upgrading from an older version to new version, the compatibility level of the database may not be in the desired level. The following statement will help you to list all of the database names with compatibilty level. It also lists the online/offline status of the database as well as helping the DBA to see if any update to recovery model is necessary. Refer Fig 1.5
SELECT name,compatibility_level,recovery_model_desc,state_desc FROM sys.databases
T-SQL Statement 6
The next level of information related to database that is needed is the location of the database. The following T-SQL Statement provides the logical name and the physical location of the data/log files of all the databases available in the current SQL Server instance. Referg Fig 1.7
SELECT db_name(database_id) as DatabaseName,name,type_desc,physical_name FROM sys.master_files
T-SQL Statement 7
A database may contain filegroups other than the primary file group. The following T-SQL Statement gets executed in each database on the server and displays the file groups related results. Refer Fig 1.9
EXEC master.dbo.sp_MSforeachdb @command1 = 'USE [?] SELECT * FROM sys.filegroups'
T-SQL Statement 8
Backup of a database is bread and butter for database administrators. The following T-SQL Statement lists all of the databases in the server and the last day the backup happened. This will help the database administrators to check the backup jobs and also to make sure backups are happening for all the databases. Refer Fig 1.10
SELECT db.name,
case when MAX(b.backup_finish_date) is NULL then 'No Backup' else convert(varchar(100),
MAX(b.backup_finish_date)) end AS last_backup_finish_date
FROM sys.databases db
LEFT OUTER JOIN msdb.dbo.backupset b ON db.name = b.database_name AND b.type = 'D'
WHERE db.database_id NOT IN (2)
GROUP BY db.name
ORDER BY 2 DESC
T-SQL Statement 9
The next level of information that is important for a SQL Server database administrator to know is the location of all the backup files. You don’t want the backups to go to the local drive or to an OS drive. The following T-SQL statement gets all the information related to the current backup location from the msdb database. Refer Fig 1.11
SELECT Distinct physical_device_name FROM msdb.dbo.backupmediafamily
T-SQL Statement 10
Last but not least, is the information related to current processes and connection related information. From the beginning, SQL Server database administrators used sp_who and sp_who2 to check the current users, process and session information. These statements also provided information related to cpu, memory and blocking information related to the sessions. Refer Fig 1.12. Also, search the internet for sp_who3. You can find many articles related to sp_who3.
sp_who
sp_who2
编辑推荐:
- Ten TOP T-SQL IN MS-SQL03-02
- 关于对sql server读写权限的控制03-02
- SQLServer会话数管理(转贴)03-02
- SQL优化实战03-02
- SQL Server中以星期一为每周第一天 计算周数03-02
- sql server 登录名和用户名的区别和联系03-02
- 智能手机、电脑之间如何传输数据03-02
- 电脑手动分区镜像的方法图解教程03-02
下一篇:
相关推荐
-
雷神推出 MIX PRO II 迷你主机:基于 Ultra 200H,玻璃上盖 + ARGB 灯效
2 月 9 日消息,雷神 (THUNDEROBOT) 现已宣布推出基于英
-
制造商 Musnap 推出彩色墨水屏电纸书 Ocean C:支持手写笔、第三方安卓应用
2 月 10 日消息,制造商 Musnap 现已在海外推出一款 Oce
热文推荐
- 关于对sql server读写权限的控制
关于对sql server读写权限的控制
26-03-02 - 智能手机、电脑之间如何传输数据
智能手机、电脑之间如何传输数据
26-03-02 - 电脑手动分区镜像的方法图解教程
电脑手动分区镜像的方法图解教程
26-03-02 - 计算机主板你知多少?
计算机主板你知多少?
26-03-02 - 电脑固态硬盘如何分区更好一点?
电脑固态硬盘如何分区更好一点?
26-03-02 - 跟我学电子入门知识-第一章-电
跟我学电子入门知识-第一章-电
26-03-02 - 电脑组装 组装电脑如何选购显卡、显示器、电源、机箱?
电脑组装 组装电脑如何选购显卡、显示器、电源、机箱?
26-03-02 - 计算机显卡你知多少?
计算机显卡你知多少?
26-03-02 - 关于计算机内部硬件接口的知识
关于计算机内部硬件接口的知识
26-03-02 - 现在电脑固态硬盘读写速度有多快?升级时可以选择的方案有哪些?
现在电脑固态硬盘读写速度有多快?升级时可以选择的方案有哪些?
26-03-02
