Showing posts with label T-SQL. Show all posts
Showing posts with label T-SQL. Show all posts
Thank you to everyone who attended my session yesterday! I appreciate that you chose my session and I also appreciate the honest
feedback that I have seen in the reviews thus far. As promised, you can find
the deck as well as the scripts used for my screen shots here - Ignite 2016 Presentation.
Presenting at Microsoft Ignite 2016
For those that read
my blog, I would like to apologize for not blogging much this year. My main focus has
been getting familiar with my new job and most of my free time that I spend
with the community has been focused on presenting in person, rebuilding TTSSUG
and a project with Paul Turley (more on this soon).
Significance of Square Brackets [] in T-SQL Code
After one of my
T-SQL presentations, I was asked about the significance of square brackets
around objects in T-SQL. I had an idea of their purpose but to confirm I asked
T-SQL guru, Itzik Ben-Gan.
T-SQL: Tips and Tricks Presentation
On Thursday I did my
last 2013 presentation for the Data Architecture Virtual Chapter. I found out that the session had 334 attendees and I would like to
thank everyone for taking the time to attend and also thanks for all the feedback that
I received. Special thanks to Rob Canzonire, the VC member who asked me to present and also moderated it as well.
The presentation and
the SQL scripts are available here. One of the databases is created by the
'01_DemoDB' script and the other one, AdventureWorks2012, can be downloaded
here. Below is a YouTube video of the session. Enjoy!
Online Presentation for the Data Architecture Virtual Chapter
This Thursday at
12:00 pm Central Time (2:00 pm in Trinidad ) I will be presenting, 'T-SQL Tips
and Tricks' for the Data Architecture VC.
Session abstract:
Queries are running
longer than expected? Your database server isn't performing as well as it
should? There are many reason that this could be happening and one of them is
the T-SQL being executed on the system. T-SQL offers various ways to get the
information that you need but sometimes the option you choose might return the
data that you want but may not be the best query structure or logic to use.
This session will share insight on how basic
query structure and logic works so you can avoid wasting too much time on trial
and error when writing queries. It will also show you some tips and tricks to
avoid some bad T-SQL coding habits and help you write better queries. This
session is for Developers and Database Administrators.
To register for this
online meeting or to find out more about the group
and their meetings, then visit their homepage.
Querying Microsoft SQL Server 2012 Live Event
This Friday, Tobias
Ternstrom (Microsoft Principal Program Manager Lead) and Brian Alderman (CEO
and Founder, MicroTechPoint) will be the instructor team for this 8 hour Microsoft Virtual Academy (MVA) Jumpstart event. The purpose of this course is to
help you prepare for the MCSA Exam 70-461. Even if you are not interested in
taking the exam, I suggest attending to get some more insight into the power of
queries and T-SQL.
Course Outline
- Introduction to SQL Server 2012
- Advanced SELECT statements
- SQL Server data types
- Grouping, aggregating and modifying data
- Table expressions and SET operators
- Programming with T-SQL
- Retrieving SQL Server metadata
Event details
Date: September 13th 2013
Time: 9:00am - 5:00pm (PDT)
DBCC CHECKDB WITH DATA_PURITY Command
As I mentioned in my
last post, many people may be considering upgrading their SQL Server
Instance(s) due to the release of SQL Server 2012 and the upcoming release of
SP1. Because of this reason I thought it would be a good idea to highlight the
importance of the command for people who are planning to upgrade from SQL Server
2000.
Before I get into
the details about the command, let me just highlight that DBCC CHECKDB is a command that checks the
logical and physical integrity of all the objects in the specified database and
should be run on a regular basis. If you are a SQL Server DBA but never used or
heard about DBCC CHECKDB before then you
need to do some reading about it and start using it!
In versions prior to
SQL Server 2005, it was possible to import invalid data into databases. This
was resolved for databases created in SQL Server 2005 and later versions by
adding column-value integrity checks. This was a great solution to avoid the
issue in the future but how do you deal with the invalid data issue in older
databases that are being upgraded?
Solution -
DBCC CHECKDB ([DATABASENAME]) WITH DATA_PURITY
When this command is
executed it will confirm if there are any data issues in the specified
database. Once there are no issues/errors then DBCC
CHECKDB column will check the column value integrity by default aka you
don’t have to specify the DATA_PURITY
anymore.
For more information
about this command, I recommend Paul Randal's post:
and of course MSDN: DBCC CHECKDB.
Script To Transfer Logins From SQL Server 2000/2005
A few years back
when I was working on a project to with some Dynamics databases, I found a
script on a Microsoft site that can capture SQL Logins for SQL Server 2000 and
2005 instances. The script is very useful for transferring SQL Logins not only
to 2000 and 2005 instances but also 2008, 2008 R2 and 2012 as well. Since I can
no longer find the link, I decided to upload the script – Capture_Logins.sql.
With the launch of
SQL Server 2012 and the upcoming release of SP1, many people may be considering
upgrading their 2000 and/or 2005 instances and this script might save you a
great deal of time. Remember it isn’t my script aka I didn't write and I don't own
it. Enjoy!
(Note: Even though
the script mentions that it works on SQL Server 7.0, I didn’t test it on that
edition so I can't guarantee that it works.)
TRUNCATE TABLE: A possible alternative for the DELETE statement
While reviewing an
archiving script at my company I realised that most of the time spent waiting
for the script to complete was due to the deletion process. While trying to
find a better way to perform the deletion of data from the database I came
across the DDL statement: TRUNCATE TABLE.
The TRUNCATE TABLE and DELETE statements can be used to remove records from a table, the difference is that DELETE can be used to remove some or all of the data in the table while TRUNCATE TABLE can only be used to remove all the data from a table (no WHERE clause). However TRUNCATE TABLE is faster than the DELETE statement and requires fewer system and transaction logs resources because of the difference in how they execute and operate. TRUNCATE TABLE removes data by deallocating data pages instead of removing rows one at a time.
I decided to do a comparison of the two statements using a test table with 3.4 million rows.
The results for each script/statement had four grids:
Script
See the following MSDN links to understand for more information about TRUNCATE TABLE and DELETE.
The TRUNCATE TABLE and DELETE statements can be used to remove records from a table, the difference is that DELETE can be used to remove some or all of the data in the table while TRUNCATE TABLE can only be used to remove all the data from a table (no WHERE clause). However TRUNCATE TABLE is faster than the DELETE statement and requires fewer system and transaction logs resources because of the difference in how they execute and operate. TRUNCATE TABLE removes data by deallocating data pages instead of removing rows one at a time.
I decided to do a comparison of the two statements using a test table with 3.4 million rows.
The results for each script/statement had four grids:
- The first result grid shows the size of the MDF and LDF before the process.
- The second result grid shows the number of records in the table before the DELETE/TRUNCATE TABLE statement is executed.
- The third result grid shows the number of records in the table after the DELETE/TRUNCATE TABLE statement is executed.
- The fourth result grid shows the size of the MDF and LDF after the process.
DELETE Statement
Script
Results
Notice the increase
sized of LDF after the process (from 5.5625 MB to 2321.375 MB). The script was
executed three times and each time the LDF was the increased to the same size.
The execution time
results:
SQL Server Execution Times:
CPU time = 6177 ms, elapsed time = 114451 ms.
SQL Server Execution Times:
CPU time = 6349 ms, elapsed time = 105675 ms.
SQL Server Execution Times:
CPU time = 6193 ms, elapsed time = 105816 ms.
TRUNCATE TABLE Statement
Script
Results
Notice no change to
the size of the MDF or LDF. The script was also executed three times.
The execution time
results:
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 140 ms.
SQL Server Execution Times:
CPU time = 15 ms, elapsed time = 96 ms.
SQL Server Execution Times:
CPU time = 0 ms, elapsed time = 191 ms.
Conclusion:
Based on the
execution times results it is very clear that the TRUNCATE TABLE statement is
faster than the DELETE statement. It is
also clear that the DELETE statement process of removing rows one at a time
requires more transaction log space when compared to the TRUNCATE TABLE
process.
See the following MSDN links to understand for more information about TRUNCATE TABLE and DELETE.
TTSSUG Event Review: Demonstrating T-SQL Constructs
Our meeting on Tuesday did not have as many people as we hoped but the presentation done by Mitra Sinanan was very informative to the few that attended. He created some scripts to highlight the difference between some T-SQL constructs and explained when would be the best situations to use them. He also spoke about one of the command line utilities that came with SQL Server 2005 - the TableDiff Utility.
Subscribe to:
Posts (Atom)
Categories
Analytics
Azure
B2B
Big Data
Business Intelligence
Conferences
CTP
Database Design
Developer
Fun facts
GUI
How-To
Hyper-V
Interview
MCSA
MCSE
Mobile Reporting
NoSQL
O365
PASS
PD
Presentation
Programming
Publication
RLS
SAGO
SBCS
Security
SoftwareONE
SolidQ
SolidQ Journal
SP1
SQL Azure
SQL Database
SQL Database V12
SQL in the City
SQL MVP
SQL Server 2008 R2
SQL Server 2012
SQL Server 2014
SQL Server 2016
SQL Server 2017
SQLSaturday
SSMS
SSRS
St Lucia
T-SQL
T-SQL Tuesday
TechEd 2013
Training
Trinidad & Tobago
TTSAC
TTSSUG
Upgrade
VDI
VHD
Virtual Machines
What's New
Win10
Windows 2012
Windows 2012 R2
XML



