Some Important Scripts by Abubeker A. Refaw


Very useful SQL Script that make our life a lot easier

Important script by Abubeker A Refaw

/*Back up to Multiple Files

Databases are becoming larger and larger. You can tune the performance of SQL Server backup compression, by using multiple backup files, and the BUFFERCOUNT and MAXTRANSFERSIZE options. The DatabaseBackup procedure supports these options:*/

EXECUTE dbo.DatabaseBackup
@Databases = ‘USER_DATABASES’,
@Directory = ‘C:\Backup, D:\Backup, E:\Backup, F:\Backup’,
@BackupType = ‘FULL’,
@Compress = ‘Y’,
@BufferCount = 50,
@MaxTransferSize = 4194304,
@NumberOfFiles = 4,
@CleanupTime = 24

———————————————————

/*Solve “No Current Database” Issues

Most DBAs have experienced the error message “BACKUP LOG cannot be performed because there is no current database backup” or “Cannot perform a differential backup for database, because a current database backup does not exist”. These errors usually occur when you have created a new database or changed the database recovery model from Simple to Full. The answer is to determine, before you run the backup, whether a differential or transaction log backup can be performed. You can use the DatabaseBackup procedure’s @ChangeBackupType option to change the backup type dynamically if a differential or transaction log backup cannot be performed.*/

–Here’s an example of how to use the @ChangeBackupType option:

EXECUTE dbo.DatabaseBackup
@Databases = ‘USER_DATABASES’,
@Directory = ‘C:\Backup’,
@BackupType = ‘LOG’,
@Verify = ‘Y’,
@ChangeBackupType = ‘Y’,
@CleanupTime = 24

———————————————————–

/*Intelligent Index Maintenance

The SQL Server Maintenance Solution lets you intelligently rebuild or reorganize only the indexes that are fragmented. In the IndexOptimize procedure, you can define a preferred index maintenance operation for each fragmentation group. Take a look at this code:*/

/*In this example, indexes that have a high fragmentation level will be rebuilt, online if possible. Indexes that have a medium fragmentation level will be reorganized. Indexes that have a low fragmentation level will remain untouched.*/

EXECUTE dbo.IndexOptimize @Databases = ‘USER_DATABASES’,
@FragmentationLow = NULL,
@FragmentationMedium = ‘INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE’,
@FragmentationHigh = ‘INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE’,
@FragmentationLevel1 = 5,
@FragmentationLevel2 = 30

/*Update Statistics

The IndexOptimize procedure can also be used to update statistics. You can choose to update all statistics, statistics on indexes only, or statistics on columns only. You can also choose to update the statistics only if any rows have been modified since the most recent statistics update.*/

EXECUTE dbo.IndexOptimize @Databases = ‘USER_DATABASES’,
@FragmentationLow = NULL,
@FragmentationMedium = ‘INDEX_REORGANIZE,INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE’,
@FragmentationHigh = ‘INDEX_REBUILD_ONLINE,INDEX_REBUILD_OFFLINE’,
@FragmentationLevel1 = 5,
@FragmentationLevel2 = 30,
@UpdateStatistics = ‘ALL’,
@OnlyModifiedStatistics = ‘Y’

—————————————————————–

/*Create a DB Snapshot, when you name make sure you put date or time, should be very descrptive*/
use master
go
create database adventureworks_snapshot040809 on
(name = N’adventureworks_data’, filename = N’c:\db\aw_040809.sis’)
as snapshot of adventureworks
go
–verify that the snapshot contains same info as source DB
select *
from Adventureworks2008_snapshot040809.sales.salesorderDetail
order by SalesorderID
Go

Select *
From Adventureworks2008.Sales.SalesOrderDetail
Order by SalesOrderID
go
–Revert the DB to the Snapsot and restore it from snapshot
Drop Table adventureworks.Sales.SalesOrderDetail
GO

use master
Restore Database Adventureworks
From Database_Snapshot = ‘Adventureworks_Snapshot040809’
go

———————————————————————–

–To look for suspect pages to restore
select * from msdb..suspect_pages
where (event_type =1 or event_type = 2 or event_type = 3)
go

/*Restore certain page IDS, backups is the path or the device and ‘1:265’ is the one we found when we run the above code to look for the suspect page*/

use master
go
restore database adventureworks2008
page = ‘1:265′
from backups
go

—————————————————————————-

/*You can also move full-text catalogs by their logical name. But note that when you specify the new catalog location, you specify only new_path rather than new_path/file_name.To move a full-text catalog file to a new location, follow these steps:*/

/*1. Take the database you want to work with offline by typing the following:*/
ALTER DATABASE database_name
SET offline
GO
/*2. Move one file at a time to the new location by typing these commands:*/
ALTER DATABASE database_name
MODIFY FILE ( NAME = logical_name, FILENAME = “new_path”.
GO
/*3. Repeat the previous step to move other full-text catalog files as necessary.*/

–4. Put the database online by typing the following:
ALTER DATABASE database_name
SET online
GO

—————————————————————————–

/*To move data or log files to a new location, follow these steps:*/

/*1. Get the logical name of the data and log files associated with the database by typing the following:*/

USE master
SELECT name, physical_name
FROM sys.master_files
WHERE database_id = DB_ID(“Personnel”);

/*2. Take the database you want to work with offline by typing these commands:*/

ALTER DATABASE Personnel
SET offline
GO
/*3. Move one file at a time to the new location by typing the following:*/

ALTER DATABASE Personnel
MODIFY FILE ( NAME = Personnel_Data, FILENAME =
“C:\Data\Personnel_Data.mdf”)
GO

/*4. Repeat the previous step to move other data and log files.*/

/*5. Put the database online by typing the following commands:*/

ALTER DATABASE Personnel
SET online
GO

–You can verify the change or changes by typing this:

USE master
SELECT name, physical_name
FROM sys.master_files
WHERE database_id = DB_ID(“Personnel”);

——————————————————————————-

/*
WAITFOR

–Blocks the execution of a batch, stored procedure, or transaction until a specified time or time interval is reached, or a
specified statement modifies or returns at least one row.

–USING A WHILE LOOP TO SELECT DATA FROM SALES.CUSTOMER_ALL WITH A 5 min 1 SEC DELAY
— READ INTENSIVE

*/

use AdventureWorks2008
go
DECLARE
@COUNT INT

SET @COUNT = 1
WHILE (@COUNT <= 500)
BEGIN
WAITFOR DELAY ’00:05:01’

select GETDATE()

SET @COUNT = @COUNT + 1
END

————————————————————————-

–how to configure Service Broker and send and receive messages.
——————————————————————-
CREATE DATABASE ServiceBrokerTest
GO
USE ServiceBrokerTest
GO
— Enable Service Broker
ALTER DATABASE ServiceBrokerTest SET ENABLE_BROKER
GO
— Create Message Type
CREATE MESSAGE TYPE SBMessage
VALIDATION = NONE
GO
— Create Contract
CREATE CONTRACT SBContract
(SBMessage SENT BY INITIATOR)
GO
— Create Send Queue
CREATE QUEUE SBSendQueue
GO
— Create Receive Queue
CREATE QUEUE SBReceiveQueue
GO
— Create Send Service on Send Queue
CREATE SERVICE SBSendService
ON QUEUE SBSendQueue (SBContract)
GO
— Create Receive Service on Recieve Queue
CREATE SERVICE SBReceiveService
ON QUEUE SBReceiveQueue (SBContract)
GO
— Begin Dialog using service on contract
DECLARE @SBDialog uniqueidentifier
DECLARE @Message NVARCHAR(128)
BEGIN DIALOG CONVERSATION @SBDialog
FROM SERVICE SBSendService
TO SERVICE ‘SBReceiveService’
ON CONTRACT SBContract
WITH ENCRYPTION = OFF
— Send messages on Dialog
SET @Message = N’Very First Message’;
SEND ON CONVERSATION @SBDialog
MESSAGE TYPE SBMessage (@Message)
SET @Message = N’Second Message’;
SEND ON CONVERSATION @SBDialog
MESSAGE TYPE SBMessage (@Message)
SET @Message = N’Third Message’;
SEND ON CONVERSATION @SBDialog
MESSAGE TYPE SBMessage (@Message)
GO
— View messages from Receive Queue
SELECT CONVERT(NVARCHAR(MAX), message_body) AS Message
FROM SBReceiveQueue
GO
— Receive messages from Receive Queue
RECEIVE TOP(1) CONVERT(NVARCHAR(MAX), message_body) AS Message
FROM SBReceiveQueue
GO
— Receive messages from Receive Queue
RECEIVE CONVERT(NVARCHAR(MAX), message_body) AS Message
FROM SBReceiveQueue
GO
— Clean Up
USE master
GO
DROP DATABASE ServiceBrokerTest
GO

————————————————————————

/*—————————————————————————–

This script captures CPU Utilization Percent using TSQL. It uses system functions @@CPU_BUSY and @@IDLE
to see what is the CPU Utilization % at a particular instant. You can then use this number in a table or variable
to trigger other events.
@@CPU_BUSY shows the time SQL Server has been busy
@@IDLE shows the time SQL Server has been idle

————————————————————————————————————*/

DECLARE @CPU_BUSY int
DECLARE @IDLE int

SELECT @CPU_BUSY = @@CPU_BUSY, @IDLE = @@IDLE

WAITFOR DELAY ‘000:00:01’

SELECT
(@@CPU_BUSY – @CPU_BUSY)/((@@IDLE – @IDLE + @@CPU_BUSY – @CPU_BUSY) * 1.00) *100 AS CPU_Utilization_Pct

About the Author: Abubeker Refaw 

By Abubeker A Refaw -How to install SQL Server 2008 in Windows Server 2008


Your results may vary, try this on a lab computer to verify the steps needed and how they work for you. This Post is NOT SCCM specific and is provided as is to help you get up and running in a lab environment. The specific roles installed in this sample install are not in any way customised for an SCCM install. In a Production environment, you should consult Technet to verify best practices for where to install SQL and to separate the DB and LOG files to SAN drives if appropriate. Insert the DVD or mount the iso (SQLFULL_ENU.iso), once done double click on setup.exe in case it doesn’t autorun.sql_requires.jpgIf you get a requirements needed message click ok so that it can install them (updated .NET framework and Windows Installer)Microsoft .NET Framework 3.5 SP1 update

Accept the license agreement for the .NET update and click install

dotnetagree.jpg

The actual installation seems to take a few minutes…. if it fails it will give you an error log, you can try installing it again or read the installation issues readme.

dotnetdone.jpg

Windows Installer 4.5 Update

Next you may be promted to install a hotfix (KB942288), click Ok.

hotfix_ok.jpg

if you were prompted to install the hotfix then you’ll be asked to Restart, so lets do that…

restart_now.jpg

after the restart and now that we’ve updated those two components run setup.exe again from the SQL 2008 iso (dvd). You should see the following

sqlsplash.jpg

Planning phase

click on System Configuration Checker to check our system for any problems that may prevent SQL 2008 from installing/working.

In my case i got one warning (telling me that installing SQL server on a domain controller is not recommended) but I choose to ignore that warning.

check_done.jpg

Clicking ok brings you back to the SQL 2008 main menu, here you can see many more options for your SQL server (hardware requirements, security documentation, release notes, upgrade advisor and more).

Installation

Click on Installation in the left pane, in the new window that appears, choose the first option which is a new SQL server stand-alone installation.

new_install.jpg

setup support rules

this is turn will do a quick test for setup support rules,

setup_support_rules.jpg

click ok to continue

at this point you can use the drop down menu to select a different SQL version (we dont need to) or input your SQL Server product key, click next when done.

product_key.jpg

accept the license terms and click next

eula.jpg

click install to install setup support files…

setup_install_files.jpg

once again, I was presented with another setup support rules test result this time with two warnings, the domain controller one (safe to ignore) and my windows firewall telling me that the appropriate ports should be opened

setup_warning2.jpg

I clicked next.

Feature Selection

I chose to Select All and left the path of the install as default.

sql_feature_selection.jpg

Instance Configuration

I left these options as default

instance.jpg

Disk Space Requirements

The disk space requirements gave me a green ok arrow, so I clicked next to continue

disk_space.jpg

Server Configuration

Note: if you need to change collation, or verify it then click on the Collation Tab.

Otherwise, click on Account Name to the right of SQL Server Agent and enter your the administrator/password values

server_config_perms.jpg

click next

Database Engine Configuration

You can adjust the user settings here depending on your security preferences

Quote

Beginning in SQL Server 2005, significant changes were implemented to help ensure that SQL Server was more secure than previous versions. Changes included a “secure by design, secure by default, and secure in deployment” strategy designed to protect the server instance and its databases from security attacks.

SQL Server 2008 continues the security hardening process by introducing more changes to the server and database components. SQL Server 2008 leverages the User Account Control (UAC) found in Windows Vista and Windows Server 2008.

The changes introduced in SQL Server 2008 further decrease the surface and attack areas for the server and its databases by instituting a policy of “Least Privileged Authority.” This means that internal accounts are protected and separated into operating system functions and SQL Server functions. These measures include:

The ability to provision one or more Windows principals into the Sysadmin server role inside SQL Server. This option is available during SQL Server Setup.

The Surface Area Configuration (SAC) tool has been removed, and replaced by poliyc-based management and changes in the Configuration Manager tool.

These changes will affect your security planning for SQL Server, and help you create a more complete security profile for your system.

for the purpose of this guide, we will add the local administrator by clicking on Add Current User, if this or any options confuse you then click on help in the bottom right corner of the installer.

add_current_user.jpg

For Analysis Services configuration, enter the same value (add current user, assuming you are doing this as local administrator…)

analysis_conf.jpg

for the Reporting Services configuration, I left the default value (native)

reporting.jpg

choose your Error and Usage reporting settings and click next

error_and_usage.jpg

your installation Rules will get a quick check…

inst_rules.jpg

click next to see ‘Ready to install’ summary’

ready_to_install.jpg

click install to start the installation…

(time for lots of coffee..)

setup_progress.jpg

After dinner it was completed

sql_server_success.jpg

one more click and then it’s all completed.

completed.jpg

🙂

sql_2008.jpg

Note: This step is optional for troubleshooting Kerberos authentication issues. The named pipes protocol is not required for Configuration Manager 2007 site database operations and should only be used for troubleshooting kerberos authentication problems.

Enable Named Pipes and TCP/IP in your SQL server protocols (by default they are disabled), start up your SQL Server Configuration Manager, expand SQL Server Network Configuration in the left pane, and choose Protocols for MSSQLSERVER (or whatever your SQL server instance is called).

named_pipes.jpg

Right click on named pipes and set to enable, do the same for TCP/IP,

named_pipes_and_tcpip_enabled.jpg

once done you must Restart the SQL server service (click on SQL Server Services in the left pane, and in the right pane right click on SQL Server (MSSQLSERVER), choose restart

sqlserverconfigmanager.jpg

Final configurationGive the site server computer account Admin rights to the site systemNote: if you have setup SQL on a server which is NOT the active directory domain controller, then merely add the Computer account as a member of the Local Administrators group on that server as in the screenshot below.local_admin_computer_account.jpgHowever, if you are installing an All In One server (DC with SQL etc…) then do as follows:

Start up Active Directory Users and Computers, and verify that Advanced Features are selected under View

advanced_features.jpg

Select Builtin in the Left pane, highlight Administrators in the right pane and right click, choose properties and click on the Members Tab, click Add.

add_computer_account.jpg

when the Select Users, Contacts, Computers or Groups window appears, choose Object Types

select.jpg

when the Object Types window appears, put a checkmark in the Computers option

object_types.jpg

click Advanced, followed by Find Now

advanced.jpg

find_now.jpg

add the computer account by clicking it’s name and Ok.

computer_account.jpg

Click Ok again and now you should see the computer account added

added.jpg

Check TCPIP properties for listening IP address in SQL Server Configuration Manager

Start up the SQL Server Configuration Manager, and expand SQL Server Network Configuration on the left pane, highlight Protocols for <Instancename> and double click on TCPIP in the right pane

check_ip_in_sql_manager.jpg

Click on the IP Addresses tab

ip_addresses.jpg

change the Status from Disabled (default) to Enabled for both the Servers local ip and localhost values (see screenshots)

disabled.jpg

enabled.jpg

restart the SQL service to make the changes work

restart_sql.jpg

restart.jpg

that’s it ! all Done.

Thanks to the original source:

The Best 3rd Party SQL Server Tools


 The Best 3rd Party SQL Server Tools by Abubeker Refaw

Don’t rely on Windows’ PerfMon tool to give you the kind of performance data you require for enterprise-level, SLA-bound database workloads. It cannot provide enough information or provide you with the kind of extensive reporting that third-party tools do. These three SQL Server performance tools dig deep into your SQL Server’s performance and retrieve metrics that can pinpoint and diagnose those elusive and annoying performance problems. It’s easy to optimize systems for the best end-user experience when you have the right tool for the job.

SQL Server comes with a decently robust set of management tools, including ones for performance and tracing, that can be invaluable. Don’t believe for a moment, however, that SQL Server is fully equipped out of the box. Even if you’re just supporting the SQL Server data base that comes with a packaged software system, there are a few specific third-party tools you should have on hand to make SQL Server more reliable, more secure and easier to manage.

  1. 1.    First up is the SQL Admin Toolset from Idera. This is a package of two dozen tools designed for monitoring, troubleshooting and managing one or more SQL Server computers. You get a unified console that makes accessing each tool easy, including tools for checking SQL Server’s patch status, analyzing index performance, moving databases, quickly reindexing tables and more. And priced at under $300, it’s affordable, too.

Features

Diagnostic tools

  • Check whether your databases are backed up
  • Search for text anywhere you have SQL code (stored procs, functions, triggers etc.)
  • Find objects by name anywhere they are hiding in your SQL Servers
  • Find the SQL Servers lurking on your network
  • Check the strength of your SQL Server passwords
  • Diagnose connection problems, quickly determine why users can’t reach your SQL Servers Sites.

Analytics tools

  • Get a list of everything important about your SQL Servers, including version, hardware and more
  • Report and analyse your SQL Server version levels
  • Analyse your indexes for usage patterns and sizes. Determine if you need more, less etc…
  • Analyse the space usage of your SQL Server by drive or database
  • View loads of statistics about your SQL Server
  • Keep a constant eye on the status of your SQL Servers.

Administration tools

  • Execute and manage queries across multiple SQL Servers
  • Move or copy a database and associated logins across servers or relocate data files
  • Copy server logins across SQL Servers
  • Create a new user using an existing user as a template
    • Move and copy between servers
    • View and edit jobs across multiple SQL Servers
    • Quickly review and rebuild the indexes on your SQL Servers
    • Compare and edit server configuration for one or more SQL Servers
    • Compare and edit database configuration for one or more databases
    • View existing partition information and generate new partitions
    • Wade the multitude of options for connection strings and create your own in seconds
    • SQL Server Linked Copy Tool-Quickly and easily copies linked servers from one server to another
    • View and manage the pinned status of your tables (SQL Server 2000 and earlier only).
  1. 2.    Next in third-party tools is AppAssure’s Replay product. This is a generic backup and recovery tool, but it doesn’t have SQL Server-specific functionality. Replay is different than the time-based snapshot backups you’re probably used to. Rather than grabbing a full or differential backup every night, Replay uses an agent that’s installed on SQL Server itself to grab every disk block that changes as SQL Server writes data to disk. That includes database and transaction log files. Changed blocks are replicated immediately to a separate backup server, which stores the blocks.

In the event of a total failure, you can get a database back up and running in a few minutes, as Replay can also restore blocks as needed by SQL Server. But beyond dealing with total failures (which, admit it, don’t happen every day), Replay can also mount its backup data as a live Microsoft SQL Server database that can be queried, enabling you to restore anything down to a single row of data.

What’s more, Replay can mount any given point in time as a live SQL Server database, meaning you could retrieve a row that was deleted at 3:34 p.m. yesterday afternoon if you needed to. There are tools from other vendors that have this same basic approach, and they tend to cost hundreds of dollars, not thousands, so they offer an affordable alternative to tape-based backup. The backup server itself can be dumped to tape periodically, allowing you to maintain your off-site backup rotation schedule.

Features

Live Recovery™

  • Near-instant recovery of your entire server from your backup with RTOs and RPOs of minutes.

Universal Recovery™

  • No need to maintain identical standby machines. Replace them with AppAssure’s less costly hardware-independent machine-to-machine or machine-to environment recoveries: P2V, V2V, V2P.

Minutes-long recoveries

  • Live Recovery™ technology cuts RTOs (recovery time objectives) to minutes. Choose from 288 recovery points in a day.

Minimize disk storage footprint

  • True Global™ deduplication and compression technology cuts storage requirements by up to 80% over traditional single-machine schemes.

Recovery Assure™

  • Know for sure that your backup file is completely recoverable with AppAssure’s automated recovery verification technology.

Near-zero data loss

  • Schedule snapshot technology and incremental-forever, changed-block tracking backups as frequently as every five minutes.

Replication feature

  • Turn on a preconfigured virtual machine clone immediately after a production machine failure.

Line-speed efficiency

  • Dell AppAssure TrueScale™ scalable architecture backs up fast-changing data without interrupting or slowing user access to physical or virtual production machines.
  1. 3.    Last up is Capacity Manager for SQL Server from Quest Software. If you have more than a few SQL Server machines to worry about, this is a great way to get a handle on database growth, disk space utilization, index maintenance and other capacity-related issues. More and more companies are trying to consolidate Microsoft SQL Server databases into fewer machines and often rely on virtualization to do so. Quest’s tool helps by giving you a centralized view of your SQL Server databases, letting you see your total storage needs, project growth and make smart decisions when it comes to consolidation.

All database administrators — no matter how “reluctant” — have their favorite tools, and these are some of mine. Anything that helps me get a better handle on SQL Server utilization and performance and that helps keep SQL Server safe and reliable, is a big help to me every day.

Features

  • Capacity Manager for SQL Server locates the problems associated with managing disk space by providing trend analysis of current disk use, forecasts of future disk space requirements, notification when there is an immediate storage need, and wizards to guide you through the steps to alleviate your disk space management problems.
  • Capacity Manager allows you to identify SQL Server performance problems providing graphical charts for CPU utilization, server processor queue length, instance memory usage, disk I/O rates, etc. You can select performance data collection method. One of them based on Spotlight historical data, another one used SQL Agent jobs to collect data. You can easily switch between methods using settings in Options.
  • Capacity Manager fully supports table and index partitioning. The Manage Partitions tool helps you analyze and manage partitioned objects, monitor partitioned data growth, and detect the largest, most fragmented or fastest growing and fragmenting partitions.
  • The Intelligent Defragmentation feature and Manage Fragmentation tools help you to analyze fragmentation of database objects and configure automatic reorganization of the most fragmented objects.
  • Capacity Manager also provides a job management tool (Manage Jobs) that helps you control, monitor, and manage Capacity Manager jobs as well as all other jobs on your system on a daily calendar. You can create, alter, or delete SQL Server jobs or you can reschedule jobs quickly by dragging and dropping jobs to another day.
  • The Manage SharePoint Capacity tool helps you analyze current and future disk use for SharePoint applications and track and forecast site collections and sites growth.
  • The Capacity Planner tool helps you calculate the effect of consolidation for several databases. Please note that Performance reports for Capacity Planner are based on Spotlight historical data only.

Source

Don Jones is a senior partner and principal technologist at strategic consulting firm Concentrated Technology. Contact him via www.ConcentratedTech.com.

Sql documentation tool made easy for DBA by Abubeker Refaw


What information do we need to gather in order to help us to do our job better as a DBA?

  • Server Information (Server name, SQL Server version, collation information, and so on)
  •  Database Management (Primarily to monitor data and log file growth)
  • Database Backups (Have backups run successfully? Which databases are in Full recovery mode versus Simple or Bulk-Logged? Are we doing regular log backups of Full recovery databases?)
  • Security (Who has access to do what?)
  • SQL Agent Jobs (Which could include those that run your database backups).

Server information
To find the whole Server information and  to retrieve a number of useful pieces of server information for each of my servers, such as:
• The server name
• The physical location of the server
• The SQL Server version, level and edition
• Security mode – Either Windows (Integrated) or Mixed mode
• SQL Server collation.

We have to run the following Scripts

SELECT CONVERT(CHAR(100), SERVERPROPERTY(‘Servername’))
AS Server,
CONVERT(CHAR(100), SERVERPROPERTY(‘ProductVersion’))
AS ProductVersion,
CONVERT(CHAR(100), SERVERPROPERTY(‘ProductLevel’))
AS ProductLevel,
CONVERT(CHAR(100),
SERVERPROPERTY(‘ResourceLastUpdateDateTime’))
AS ResourceLastUpdateDateTime,
CONVERT(CHAR(100), SERVERPROPERTY(‘ResourceVersion’))
AS ResourceVersion,
CASE WHEN SERVERPROPERTY(‘IsIntegratedSecurityOnly’) = 1
THEN ‘Integrated security’
WHEN SERVERPROPERTY(‘IsIntegratedSecurityOnly’) = 0
THEN ‘Not Integrated security’
END AS IsIntegratedSecurityOnly,
CASE WHEN SERVERPROPERTY(‘EngineEdition’) = 1
THEN ‘Personal Edition’
WHEN SERVERPROPERTY(‘EngineEdition’) = 2
THEN ‘Standard Edition’
WHEN SERVERPROPERTY(‘EngineEdition’) = 3
THEN ‘Enterprise Edition’
WHEN SERVERPROPERTY(‘EngineEdition’) = 4
THEN ‘Express Edition’
END AS EngineEdition,
CONVERT(CHAR(100), SERVERPROPERTY(‘InstanceName’))
AS InstanceName,
CONVERT(CHAR(100),
SERVERPROPERTY(‘ComputerNamePhysicalNetBIOS’))
AS ComputerNamePhysicalNetBIOS,
CONVERT(CHAR(100), SERVERPROPERTY(‘LicenseType’))
AS LicenseType,
CONVERT(CHAR(100), SERVERPROPERTY(‘NumLicenses’))
AS NumLicenses,
CONVERT(CHAR(100), SERVERPROPERTY(‘BuildClrVersion’))
AS BuildClrVersion,
CONVERT(CHAR(100), SERVERPROPERTY(‘Collation’))
AS Collation,
CONVERT(CHAR(100), SERVERPROPERTY(‘CollationID’))
AS CollationID,
CONVERT(CHAR(100), SERVERPROPERTY(‘ComparisonStyle’))
AS ComparisonStyle,
CASE WHEN CONVERT(CHAR(100),
SERVERPROPERTY(‘EditionID’)) = -1253826760
THEN ‘Desktop Edition’
WHEN SERVERPROPERTY(‘EditionID’) = -1592396055
THEN ‘Express Edition’
WHEN SERVERPROPERTY(‘EditionID’) = -1534726760
THEN ‘Standard Edition’
WHEN SERVERPROPERTY(‘EditionID’) = 1333529388
THEN ‘Workgroup Edition’
WHEN SERVERPROPERTY(‘EditionID’) = 1804890536
THEN ‘Enterprise Edition’
WHEN SERVERPROPERTY(‘EditionID’) = -323382091
THEN ‘Personal Edition’
WHEN SERVERPROPERTY(‘EditionID’) = -2117995310
THEN ‘Developer Edition’
WHEN SERVERPROPERTY(‘EditionID’) = 610778273
THEN ‘Enterprise Evaluation Edition’
WHEN SERVERPROPERTY(‘EditionID’) = 1044790755
THEN ‘Windows Embedded SQL’
WHEN SERVERPROPERTY(‘EditionID’) = 4161255391
THEN ‘Express Edition with Advanced Services’
END AS ProductEdition,
CASE WHEN CONVERT(CHAR(100),
SERVERPROPERTY(‘IsClustered’)) = 1
THEN ‘Clustered’
WHEN SERVERPROPERTY(‘IsClustered’) = 0
THEN ‘Not Clustered’
WHEN SERVERPROPERTY(‘IsClustered’) = NULL
THEN ‘Error’
END AS IsClustered,
CASE WHEN CONVERT(CHAR(100),
SERVERPROPERTY(‘IsFullTextInstalled’)) = 1
THEN ‘Full-text is installed’
WHEN SERVERPROPERTY(‘IsFullTextInstalled’) = 0
THEN ‘Full-text is not installed’
WHEN SERVERPROPERTY(‘IsFullTextInstalled’) = NULL
THEN ‘Error’
END AS IsFullTextInstalled,
CONVERT(CHAR(100), SERVERPROPERTY(‘SqlCharSet’))
AS SqlCharSet,
CONVERT(CHAR(100), SERVERPROPERTY(‘SqlCharSetName’))
AS SqlCharSetName,
CONVERT(CHAR(100), SERVERPROPERTY(‘SqlSortOrder’))
AS SqlSortOrderID,
CONVERT(CHAR(100), SERVERPROPERTY(‘SqlSortOrderName’))
AS SqlSortOrderName
ORDER BY CONVERT(CHAR(100), SERVERPROPERTY(‘Servername’))

——————————————————————————-

Database management

It is obviously important that DBAs know what databases are on each of their servers. While DBAs may not be intimately familiar with every database schema on every SQL Server, it is essential that they are aware of the existence of every database, and at least understand the basic characteristics of each, such as what server they are on, what size they are and where on disk they are located.

IF EXISTS ( SELECT *
FROM tempdb.dbo.sysobjects
WHERE id =
OBJECT_ID(N'[tempdb].[dbo].[HoldforEachDB]’) )
DROP TABLE [tempdb].[dbo].[HoldforEachDB] ;
CREATE TABLE [tempdb].[dbo].[HoldforEachDB]
(
[Server] [nvarchar](128) COLLATE
SQL_Latin1_General_CP1_CI_AS
NULL,
[DatabaseName] [nvarchar](128) COLLATE
SQL_Latin1_General_CP1_CI_AS
NOT NULL,
[Size] [int] NOT NULL,
[File_Status] [int] NULL,
[Name] [nvarchar](128) COLLATE
SQL_Latin1_General_CP1_CI_AS
NOT NULL,
[Filename] [nvarchar](260) COLLATE
SQL_Latin1_General_CP1_CI_AS
NOT NULL,
[Status] [nvarchar](128) COLLATE
SQL_Latin1_General_CP1_CI_AS
NULL,
[Updateability] [nvarchar](128) COLLATE
SQL_Latin1_General_CP1_CI_AS
NULL,
[User_Access] [nvarchar](128) COLLATE
SQL_Latin1_General_CP1_CI_AS
NULL,
[Recovery] [nvarchar](128) COLLATE
SQL_Latin1_General_CP1_CI_AS
NULL
)
ON [PRIMARY]
INSERT INTO [tempdb].[dbo].[HoldforEachDB]
EXEC sp_MSforeachdb ‘SELECT CONVERT(char(100),
SERVERPROPERTY(”Servername”)) AS Server,
”?” as DatabaseName,[?]..sysfiles.size,
[?]..sysfiles.status, [?]..sysfiles.name,
[?]..sysfiles.filename,convert(sysname,DatabasePropertyEx(”?”
,”Status”)) as Status,
convert(sysname,DatabasePropertyEx(”?”,”Updateability”)) as
Updateability,
convert(sysname,DatabasePropertyEx(”?”,”UserAccess”)) as
User_Access,
convert(sysname,DatabasePropertyEx(”?”,”Recovery”)) as
Recovery From [?]..sysfiles ‘

SELECT [Server]
,[DatabaseName]
,[Size]
,[File_Status]
,[Name]
,[Filename]
,[Status]
,[Updateability]
,[User_Access]
,[Recovery]
FROM [tempdb].[dbo].[HoldforEachDB]

The above result e.g will be shown as follow

SQL Server backup pic by Abubeker Ali Refaw

Database backups

Having backup information is critical for the DBA, especially when working with a large infrastructure. Knowing where the full, differential or log backups are located is more than helpful; it is essential. This type of information can easily be gathered directly from the MSDB database, which has not changed substantially from SQL Server 2000 to 2008. Listing 2.4 shows the driving query for gathering from MSDB the vital database backup information that you need for each server, including information such as backup start date, end data and size. Notice, in the WHERE clause, that this query actually retrieves 30 days worth of history.

SELECT CONVERT(char(100), SERVERPROPERTY(‘Servername’))
AS Server,
msdb.dbo.backupmediafamily.logical_device_name,
msdb.dbo.backupmediafamily.physical_device_name,
msdb.dbo.backupset.expiration_date,
msdb.dbo.backupset.name,
msdb.dbo.backupset.description,
msdb.dbo.backupset.user_name,
msdb.dbo.backupset.backup_start_date,
msdb.dbo.backupset.backup_finish_date,
CASE msdb..backupset.type
WHEN ‘D’ THEN ‘Database’
WHEN ‘L’ THEN ‘Log’
END AS backup_type,
msdb.dbo.backupset.backup_size,
msdb.dbo.backupset.database_name,
msdb.dbo.backupset.server_name AS Source_Server
FROM msdb.dbo.backupmediafamily
INNER JOIN msdb.dbo.backupset ON
msdb.dbo.backupmediafamily.media_set_id =
msdb.dbo.backupset.media_set_id
WHERE ( CONVERT(datetime,
msdb.dbo.backupset.backup_start_date, 102) >= GETDATE()
– 30 )

sql back image

Security
For security reporting, we essentially want to know who has access to which databases, and with which permissions. A sample query of the kind of information that can be gathered.

IF EXISTS ( SELECT *
FROM tempdb.dbo.sysobjects
WHERE id =
OBJECT_ID(N'[tempdb].[dbo].[SQL_DB_REP]’) )
DROP TABLE [tempdb].[dbo].[SQL_DB_REP] ;
GO
CREATE TABLE [tempdb].[dbo].[SQL_DB_REP]
(
[Server] [varchar](100) NOT NULL,
[DB_Name] [varchar](70) NOT NULL,
[User_Name] [nvarchar](90) NULL,
[Group_Name] [varchar](100) NULL,
[Account_Type] [varchar](22) NULL,
[Login_Name] [varchar](80) NULL,
[Def_DB] [varchar](100) NULL
)
ON [PRIMARY]
INSERT INTO [tempdb].[dbo].[SQL_DB_REP]
Exec sp_MSForEachDB ‘SELECT
CONVERT(varchar(100), SERVERPROPERTY(”Servername”))
AS Server,
”?” AS DB_Name,usu.name u_name,
CASE WHEN (usg.uid is null) THEN ”public”
ELSE usg.name
END as Group_Name,
CASE WHEN usu.isntuser=1 THEN ”Windows Domain
Account”
WHEN usu.isntgroup = 1 THEN ”Windows Group”
WHEN usu.issqluser = 1 THEN”SQL Account”
WHEN usu.issqlrole = 1 THEN ”SQL Role”
END as Account_Type,
lo.loginname,
lo.dbname AS Def_DB
FROM
[?]..sysusers usu LEFT OUTER JOIN
([?]..sysmembers mem INNER JOIN
[?]..sysusers usg ON mem.groupuid = usg.uid)
ON usu.uid = mem.memberuid LEFT OUTER JOIN
master.dbo.syslogins lo ON usu.sid = lo.sid
WHERE
( usu.islogin = 1 AND
usu.isaliased = 0 AND
usu.hasdbaccess = 1) AND
(usg.issqlrole = 1 OR
usg.uid is null)’
Select * from [tempdb].[dbo].[SQL_DB_REP]

sql security info

SQL Agent jobs
Finally, it is critical that a DBA monitors closely the status of any SQL Agent jobs running on their servers so that they are aware of any failed jobs, unscheduled jobs, disabled jobs, notifications and so on. In most large shops, failed jobs will notify the on-call DBA and they will be expected to respond immediately, especially in the case of failed backup jobs.

SELECT CONVERT(nvarchar(128), SERVERPROPERTY(‘Servername’)) AS
Server,
msdb.dbo.sysjobs.job_id,
msdb.dbo.sysjobs.name,
msdb.dbo.sysjobs.enabled AS Job_Enabled,
msdb.dbo.sysjobs.description,
msdb.dbo.sysjobs.notify_level_eventlog,
msdb.dbo.sysjobs.notify_level_email,
msdb.dbo.sysjobs.notify_level_netsend,
msdb.dbo.sysjobs.notify_level_page,
msdb.dbo.sysjobs.notify_email_operator_id,
msdb.dbo.sysjobs.date_created,
msdb.dbo.syscategories.name AS Category_Name,
msdb.dbo.sysjobschedules.next_run_date,
msdb.dbo.sysjobschedules.next_run_time,
msdb.dbo.sysjobservers.last_run_outcome,
msdb.dbo.sysjobservers.last_outcome_message,
msdb.dbo.sysjobservers.last_run_date,
msdb.dbo.sysjobservers.last_run_time,
msdb.dbo.sysjobservers.last_run_duration,
msdb.dbo.sysoperators.name AS Notify_Operator,
msdb.dbo.sysoperators.email_address,
msdb.dbo.sysjobs.date_modified,
GETDATE() AS Package_run_date,
msdb.dbo.sysschedules.name AS Schedule_Name,
msdb.dbo.sysschedules.enabled,
msdb.dbo.sysschedules.freq_type,
msdb.dbo.sysschedules.freq_interval,
msdb.dbo.sysschedules.freq_subday_interval,
msdb.dbo.sysschedules.freq_subday_type,
msdb.dbo.sysschedules.freq_relative_interval,
msdb.dbo.sysschedules.freq_recurrence_factor,
msdb.dbo.sysschedules.active_start_date,
msdb.dbo.sysschedules.active_end_date,
msdb.dbo.sysschedules.active_start_time,
msdb.dbo.sysschedules.active_end_time,
msdb.dbo.sysschedules.date_created AS
Date_Sched_Created,
msdb.dbo.sysschedules.date_modified AS
Date_Sched_Modified,
msdb.dbo.sysschedules.version_number,
msdb.dbo.sysjobs.version_number AS Job_Version
FROM msdb.dbo.sysjobs
INNER JOIN msdb.dbo.syscategories ON
msdb.dbo.sysjobs.category_id =
msdb.dbo.syscategories.category_id
LEFT OUTER JOIN msdb.dbo.sysoperators ON
msdb.dbo.sysjobs.notify_page_operator_id =
msdb.dbo.sysoperators.id
LEFT OUTER JOIN msdb.dbo.sysjobservers ON
msdb.dbo.sysjobs.job_id = msdb.dbo.sysjobservers.job_id
LEFT OUTER JOIN msdb.dbo.sysjobschedules ON
msdb.dbo.sysjobschedules.job_id = msdb.dbo.sysjobs.job_id
LEFT OUTER JOIN msdb.dbo.sysschedules ON
msdb.dbo.sysjobschedules.schedule_id =
msdb.dbo.sysschedules.schedule_id

SQL  Agent job information

special thanks to Rodney Landrum

By Abubeker A. Refaw-the personal damage of False Feedback and review on internet


By Abubeker Ali Refaw:

The advantage of the Internet gives several benefits to everyone who is willing to utilize it. The massive amount of information presented and the many uses one can have through the internet have made it the most advantageous tool in different situation of one person’s life. Also, use of the Internet has made jobs easier to find and oversimplified tasks and has developed into a significant tool for avoiding the hassles of the bank, contributing the opportunity to compose the transactions instantly and safely.  On the other hand there are several ways in which the internet can be dangerous to users since anybody can be a publisher — or an attacker. we see a proliferation of online services for users we also see proliferation of attacks on these same services and users. Information that is presented as accurate or important may be inaccurate and misleading. some people deliberately use internet to damage and ruin your career for the rest of your life until you can prove your innocence.

What bad or good things are posted online can also be re-posted and continue to live long after the original message has been deleted. Sometimes the form of the damage can be much more complicated than we can imagine. For instance some people can incorrectly take that bad feedback the bad guy make against you and label you in a bad way and you might end up lose your job and your life in general. In the past, traditional media typically filtered mass messages to particular audiences, limiting the likelihood of harm as well as its effects. Now, anyone is a publisher to unlimited, worldwide audiences, without nearly as many filters. This greatly increases the potential for harm.

I am that victim. I recently learned that I am falsely accused and my personal information is used on RipoffReport.com by anonymous person to kill my Professional reputations by relating my personal name with the Ethiotec company that I have never owned and I have no connection with what so ever. This accusations are in any way discriminatory against me to try assassin my character. It is really amazing how easy it comes to post anything we want or harm anybody we compete with or don’t like personally or it can be any reason but what hurts the most  is not the false information about me but when I found out that the false Complaints filed on RipoffReport.com against me can NOT be removed. Looking more closely at the site’s information confirms that the owner of this site feels no obligation or intention of removing content.

If I have to talk a little about me, my name is Abubeker A. RefawI have earned a Bachelor degrees in General Study, and I pursued a science degree at the post-secondary level by attending D’youville College and graduated with my second degree with a major in Healthcare Administration and a minor in Health Care Management. Since my early 20’s I have been engaged in ongoing learning and research in the various fields of science, nutrition, natural health, metaphysics and volunteer work and spirituality, I couldn’t stop pursing my other career. For me learning is a natural part of life that I cannot imagine myself without. To date I have actively pursued Graduate college, and continue to immerse myself in pursuing my Doctorate in Medical PT while working as a Microsoft Certified IT Professional DBA. My other additional areas of my expertise include: Microsoft Certified Technology Specialist (MCTS) and Microsoft Certified Solutions Associate (MCSA).

It is a surprise for me now a days how things are easy to damage someone’s reputation using a fabricated information behind our advance technology. It doesn’t matter how hard you worked to build your life sometimes you can lose your credibility and achievement in a few second by a cold-blooded online hacker and you can NOT do anything about it literally. A lawyer friend recently told me, “there are two ways to exact revenge in the 21st century: The rich and powerful use the legal system. For the rest of us, there’s the Internet.” These days Websites you never knew existed can contain fictitious information about you, lying in wait like an Easter egg on the vast lawn of Google for any random passerby to find.

These days network is truly a place that has its dark and hostile corners and many bad deeds not only go unpunished, but often go undetected by all but the victim and the perpetrator. To sum up, for a vital public communications utility in today’s world, that’s probably not a very reassuring place to find ourselves.

In the future, I hope there will be laws to defend a victim like me and when a person has been wronged, and more laws to prevent the bullying behavior that damage and hurt the society. But for now we live in a frightening place where our lives have moved online and yet our fortresses are not even close to being built. Most of us are profoundly undefended against someone who gets a wild hair to ruin us. Sad World but what can you do.