SlideShare a Scribd company logo
1 of 13
• Supporting different versions
of SQL is a daily challenge for
a DBA
• One of our Microsoft SQL
Server consultants discovered
a handy tip
• One script for many different
versions of SQL server
SQL SERVER
I start writing this on my new SQL
Server 2012 box and quickly decide
to use the Dynamic Management
Views (DMV’s)
-- using DMV os Performance stats
SELECT instance_name
,cntr_value 'Log File(s) Used Size (KB)'
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Log File(s) Used Size
(KB)'
I START WITH SOMETHING LIKE…
• This runs well on my SQL Server
2012, 2008r2 and SQL 2005 servers
• SQL Server 2000 server simply
comes back with “object not found”
• In 2000 days, I have to use the DBCC
command SQLPERF to get the log
size
OF COURSE, SQL SERVER 2000
DIDN’T HAVE DMV’S…
createtable#dbccresults
(
DBName[varchar](255),
LogSize_MBdecimal(18,
8),
LogSpaceUsed
decimal(18,8),
statusint)
--GettheLogfilesizes
insertinto#dbccresults
exec('dbcc
sqlperf(logspace)')
--Outputtheresults
select*from#dbccresults
--USINGDBCCSQLPERF(LOGSPACE);
CREATEATABLE
• Write our scripts to ensure they check
the version of SQL Server first
• run the relevant piece of SQL based
on the version of SQL that part of the
script supports
• To do this we use
SERVERPROPERTY this is
supported in all version of SQL and
likely to be ever more.
1 SCRIPT THAT DOES BOTH
This will output the
following based on
the current version of
SQL Server:
8 – SQL Server 2000
9 – SQL Server 2005
10 – SQL Server
2008
11 – SQL Server
If we use this in our script with an IF
statement then we can allow our DMV
script to work on SQL Server 2005
onwards and our DBCC script to run on
SQL Server 2000 servers.
--RunifSQLServer2000
IFSELECT
CAST(LEFT(SERVERPROPERTY
('productversion'),2)asint)=8
BEGIN
--usingDBCCSQLPERF(LOGSPACE);
--Createatemptable
createtable#dbccresults
(
DBName[varchar](255),
LogSize_MBdecimal(18,8),
LogSpaceUseddecimal(18,8),
statusint)
--GettheLogfilesizes
insertinto#dbccresults
exec('dbccsqlperf(logspace)')
--Outputtheresults
select*from#dbccresults
END
-- Run if SQL Server 2005 or above
IF SELECT CAST(LEFT(SERVERPROPERTY
('productversion'), 2) as int) = 8
BEGIN
-- using DMV os Performance stats
SELECT instance_name
,cntr_value 'Log File(s) Used Size (KB)'
FROM sys.dm_os_performance_counters
WHERE counter_name = 'Log File(s) Used Size
(KB)'
END
You can use this method to do any
number of checks, and it’s always
there in the kitbag for when
needed
1 SCRIPT TO RULE THEM ALL…
dsp: One Script to Rule Them All - an SQL Script for all Versions

More Related Content

Viewers also liked

2016 Travel Predictions by Hotels.com
2016 Travel Predictions by Hotels.com2016 Travel Predictions by Hotels.com
2016 Travel Predictions by Hotels.com
hotelsdotcom
 

Viewers also liked (9)

Do more with LESS, Handlebars, Coffeescript and other Web Resources in AEM
Do more with LESS, Handlebars, Coffeescript and other Web Resources in AEMDo more with LESS, Handlebars, Coffeescript and other Web Resources in AEM
Do more with LESS, Handlebars, Coffeescript and other Web Resources in AEM
 
Successfully Implement Responsive Design Behavior with Adobe Experience Manager
Successfully Implement Responsive Design Behavior with Adobe Experience ManagerSuccessfully Implement Responsive Design Behavior with Adobe Experience Manager
Successfully Implement Responsive Design Behavior with Adobe Experience Manager
 
Deliveroo’s Best Practices for Managing Customers’ Digital Experiences
Deliveroo’s Best Practices for Managing Customers’ Digital ExperiencesDeliveroo’s Best Practices for Managing Customers’ Digital Experiences
Deliveroo’s Best Practices for Managing Customers’ Digital Experiences
 
Track A-3: Drive Innovation & Reduce Costs with Managed Services
Track A-3: Drive Innovation & Reduce Costs with Managed ServicesTrack A-3: Drive Innovation & Reduce Costs with Managed Services
Track A-3: Drive Innovation & Reduce Costs with Managed Services
 
SMBSeattle/IABC Seattle: Expedia -Social Media Lessons Learned
SMBSeattle/IABC Seattle: Expedia -Social Media Lessons LearnedSMBSeattle/IABC Seattle: Expedia -Social Media Lessons Learned
SMBSeattle/IABC Seattle: Expedia -Social Media Lessons Learned
 
Summit 2015: Mobile App Dev and Content Management with Adobe Experience Manager
Summit 2015: Mobile App Dev and Content Management with Adobe Experience ManagerSummit 2015: Mobile App Dev and Content Management with Adobe Experience Manager
Summit 2015: Mobile App Dev and Content Management with Adobe Experience Manager
 
2016 Travel Predictions by Hotels.com
2016 Travel Predictions by Hotels.com2016 Travel Predictions by Hotels.com
2016 Travel Predictions by Hotels.com
 
CIRCUIT 2015 - Hybrid App Development with AEM Apps
CIRCUIT 2015 - Hybrid App Development with AEM AppsCIRCUIT 2015 - Hybrid App Development with AEM Apps
CIRCUIT 2015 - Hybrid App Development with AEM Apps
 
Adobe Marketing Cloud Integrations: Myth or Reality? by Holger Marsen
Adobe Marketing Cloud Integrations: Myth or Reality? by Holger MarsenAdobe Marketing Cloud Integrations: Myth or Reality? by Holger Marsen
Adobe Marketing Cloud Integrations: Myth or Reality? by Holger Marsen
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 

dsp: One Script to Rule Them All - an SQL Script for all Versions