SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

Destacado

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 AEMBob Paulin
 
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 ManagerPerficient, Inc.
 
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 Experiencesmarketingfinder.co.uk
 
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 Servicesscoopnewsgroup
 
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 LearnedSMB Seattle
 
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 Managerbrucelefebvre
 
2016 Travel Predictions by Hotels.com
2016 Travel Predictions by Hotels.com2016 Travel Predictions by Hotels.com
2016 Travel Predictions by Hotels.comhotelsdotcom
 
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 AppsICF CIRCUIT
 
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 MarsenAEM HUB
 

Destacado (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
 

Último

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI AgeCprime
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentPim van der Noll
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesThousandEyes
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfNeo4j
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Nikki Chapple
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesKari Kakkonen
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Hiroshi SHIBATA
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integrationmarketing932765
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesBernd Ruecker
 

Último (20)

The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
A Framework for Development in the AI Age
A Framework for Development in the AI AgeA Framework for Development in the AI Age
A Framework for Development in the AI Age
 
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native developmentEmixa Mendix Meetup 11 April 2024 about Mendix Native development
Emixa Mendix Meetup 11 April 2024 about Mendix Native development
 
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyesHow to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
How to Effectively Monitor SD-WAN and SASE Environments with ThousandEyes
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
Connecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdfConnecting the Dots for Information Discovery.pdf
Connecting the Dots for Information Discovery.pdf
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
Microsoft 365 Copilot: How to boost your productivity with AI – Part one: Ado...
 
Testing tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examplesTesting tools and AI - ideas what to try with some tool examples
Testing tools and AI - ideas what to try with some tool examples
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024Long journey of Ruby standard library at RubyConf AU 2024
Long journey of Ruby standard library at RubyConf AU 2024
 
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS:  6 Ways to Automate Your Data IntegrationBridging Between CAD & GIS:  6 Ways to Automate Your Data Integration
Bridging Between CAD & GIS: 6 Ways to Automate Your Data Integration
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
QCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architecturesQCon London: Mastering long-running processes in modern architectures
QCon London: Mastering long-running processes in modern architectures
 

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