This document discusses challenges that can arise when developing T-SQL code as part of a team. It presents a scenario of a small initial team that grows larger over time. The document highlights potential issues that can stem from a lack of source control, inconsistent coding styles, and shortcuts like using table aliases and ordering by column number. It recommends adopting common coding standards and formatting tools to promote consistency. The presenter demonstrates a formatting tool and provides additional resources on T-SQL best practices.
Presentation on how to chat with PDF using ChatGPT code interpreter
Coding T-SQL in a Team Environment
1. Coding T-SQL in a Team
T-
Environment
Garth Honhart
Silicon Valley SQL Server User Group
November 17, 2009
Mark Ginnebaugh, User Group Leader
2. Before I Get Started…News
Released Today
SQL Server 2008 Cumulative Update #8
SQL Server 2008 Cumulative Update #5
Recently Released
SQL Server 2008 R2 November CTP
Office 2010 Beta (64-bit Client & PowerPivot!)
From PDC
Microsoft Pinpoint: Codename “Dallas”
Cloud based datasets, such as demographic and sales
information. Think of it as the un-federated portion of the
data that would be used when performing a PowerPivot.
3. Garth Honhart
• RF-4C (1960’s era Reconnaissance Aircraft)
• A-10 (Desert Storm Scud Hunters)
• Airmail Terminal Frankfurt (Yes, I know how to go postal)
USAF • U-2 (1950’s era Reconnaissance Aircraft…and they’re still flying)
• Global Metrology Reporting via Access & ASP 1.0
• Tandem Reporting Via FrontPage based Intranet (CGI)
• Learning Management Deferred Revenue Reporting (SQL 2000/ASP
Web 3.0)
• Data Quality and Business Rule Validation (HRIS:IDM:LMS) using SSIS
• Web Portal Reporting system Internal and Commercial sites based on
Web Logic / Tea Leaf using SSIS & SSRS
BI • Soup to Nuts BI infrastructure implementation. Full Microsoft BI Stack.
4. Agenda
Challenges of developing T-SQL in a team
environment.
A Scenario
Commonly used tools and their benefits
Point out development short cuts that can lead to
bad habits
Open discussion on how different organizations
approach the challenge.
5. Please Mind the Gap
Gap or Chasm?
Depends on where the T-SQL you’re coding resides.
If it is going into production, you are going to make
it a stored procedure, aren’t you?
What about development that happens before
code is folded into a larger project?
6. Scenario
Company initiates a BI effort, albeit with a very
limited budget.
“Team” consists of one FTE and one contractor.
Initial Focus is formalizing reports using SQL Server
Reporting Services.
No source control. No collaborative development.
Approach? Single threaded development.
7. (Code Examples Two Man Crew)
select a.title, a.type, a.price, c.au_fname, c.au_lname
from titles a, titleauthor b, authors c
where a.title_id = b.title_id and c.au_id=b.au_id
order by 3,2,1,5,4
Contractor 1
select t.title, t.type, t.price, a.au_fname, a.au_lname
from titles t, titleauthor ta, authors a
where t.title_id = ta.title_id and a.au_id=ta.au_id
order by t.price, t.type, t.title, a.au_lname, a.au_fname
FTE 1
8. Phase Two
Company adds funding for additional full time
positions.
Company also switches preferred contractors.
New team is three FTE and three contractors, one on
site, two off shore.
Primary development focus is still SSRS, but will also
include ETL via Integration Services.
9. (Coding Styles 2)
select
select
t.title,
t.type,
t.title as BookTitle
t.price, ,t.type as TitleType
a.au_fname, ,t.price as TitlePrice
a.au_lname ,a.au_lname + ', ' + a.au_fname as
from AuthorName
titles t
from titles as t
inner join titleauthor ta
on t.title_id = ta.title_id
inner join
inner join authors a (titleauthor as ta
on ta.au_id=a.au_id inner join
order by authors as a on ta.au_id=a.au_id
t.price, ) on t.title_id = ta.title_id
t.type,
order by t.price, t.type, t.title, a.au_lname,
t.title,
a.au_fname
a.au_lname,
a.au_fname
Contractor 2 FTE 2
10. Common (Bad) Shortcuts
ANSI-89 Style Joins
Table Aliases (a, b, c or t1,t2,t3)
Order by ordinal
select a.title, a.type, a.price, c.au_fname, c.au_lname
from titles a, titleauthor b, authors c
where a.title_id = b.title_id and c.au_id=b.au_id
order by 3,2,1,5,4
11. Tips and Tools
Settle on common table aliases, publish and keep
them up to date.
Decide what format works best for your team.
Use a formatting tool.
13. Other Tools that Format
Toad for SQL Server (Quest). Does a whole lot more
than just formatting.
http://www.quest.com/toad-for-sql-server/
SQL Pretty Printer. Integrates with SSMS, just does
formatting. Desktop version (free trial) or browser
based. http://www.dpriver.com/index.php
14. Links
T-SQL Formatting Standards (Coding Standards) –
Robert Sheldon Simple Talk
http://www.simple-talk.com/sql/t-sql-
programming/transact-sql-formatting-standards-
(coding-styles)/
Deprecated Database Engine Features in SQL Server
2008
http://msdn.microsoft.com/en-
us/library/ms143729.aspx
Aaron Bertrand’s Bad Habits to Kick
http://sqlblog.com/blogs/aaron_bertrand/archive/tag
s/best+practices/default.aspx
15. www.bayareasql.org
To learn more or to inquire about speaking opportunities, please contact:
Mark Ginnebaugh, User Group Leader mark@designmind.com