Monday, September 6, 2010

SQLSaturday #28 Baton Rouge, LA

 

A wonderful and informative SQLSaturday was held in Baton Rouge on the campus of LSU.

Steve Jones captured it on video:

Blogs about the event”

 

Tim Mitchell - http://www.sqlservercentral.com/blogs/tim_mitchell/archive/2010/08/21/sql-saturday-28-baton-rouge-recap.aspx

Wes Brown - http://sqlserverio.com/2010/08/16/what-a-great-sql-saturday-baton-rouge/

My new Friend Eli Wienstock-Herman -http://blogs.lessthandot.com/index.php/DataMgmt/DBAdmin/sql-saturday-28-baton-rouge

Here are some pictures:

SqlSat28_William_Twitter_BrSqlSat   SqlSat28_MikeHguetandBrianRigsl  

SqlSat28TrevorFriBanquet DSCN0223

DSCN0222   SqlSat28_Al_FriBanquet

SqlSat28_DotNetFreaks   DSCN0214

Friday, August 13, 2010

SQLSaturday Baton Rouge #28

Come one, come all to the largest FREE technology event ever in Baton Rouge and probably in Louisiana.

http://sqlsaturday.com/28/eventhome.aspx

600+ registered attendees to network with and 58 sessions from beginners to advanced. Many MS MVPs from SQL Server and .Net

I will be presenting about Database Normalization and how important it it. http://sqlsaturday.com/viewsession.aspx?sat=28&sessionid=1323


Track Starts Session Title Speaker


.Net 1 07:30 AM .NET 3.5 Fundamentals Mike Huguet

.Net 1 9:00 AM Zen Coding Brian Rigsby

.Net 1 10:15 AM Getting Started with the Entity Framework 4.0 Rob Vettor

.Net 1 11:30 AM Zen Testing Brian Rigsby

.Net 1 01:30 PM C# Ninjitsu Chris Eargle

.Net 1 2:45 PM Advance Your Debugging Skills with VS 2010 Rob Vettor

.Net 1 4:00 PM 6 Months of putting VS2010 and TFS thru the Paces Michael Moles

.Net 2 9:00 AM Exploratory Testing with Microsoft Test Manager Vaneshia Leachman

.Net 2 10:15 AM Building Richer Web Applications with SP2010 Kyle Kelin

.Net 2 11:30 AM The Best of Visual Studio 2010 Zain Naboulsi

.Net 2 01:30 PM 3P's (Principles, patterns and performance) of SD Chander Dhall

.Net 2 2:45 PM Introduction to NHibernate and Fluent NHibernate Brian Sullivan

.Net 2 4:00 PM RESTful Data Chris Eargle

Apps\Cloud\Personal Development 9:00 AM Building a Testable Data Access Layer Todd Anglin

Apps\Cloud\Personal Development 10:15 AM The Modern Resume: Building Your Brand Steve Jones

Apps\Cloud\Personal Development 11:30 AM Getting SQL Service Broker Up and Running Denny Cherry

Apps\Cloud\Personal Development 01:30 PM Intro to Windows Azure Ryan Duclos

Apps\Cloud\Personal Development 2:45 PM Azure - Best Practices Chander Dhall

Apps\Cloud\Personal Development 4:00 PM SharePoint 2010 Management with PowerShell Cody Gros

BI\SSRS 07:30 AM Breakfast Basics, SSAS Cube Creation Barry Ralston

BI\SSRS 9:00 AM An Introduction to Power Pivot Bryan Smith

BI\SSRS 10:15 AM Get your Mining Model Predictions out to all Steve Simon

BI\SSRS 11:30 AM Can you control your reports? Ryan Duclos

BI\SSRS 01:30 PM Data Mining.. Making $mart financial decisions Steve Simon

BI\SSRS 2:45 PM College Football and MSFT Business Intelligence Barry Ralston

BI\SSRS 4:00 PM My first SQL Report Mark Verret

DB Design & App Dev 9:00 AM iPhone Development using .NET and Monotouch Jason Awbrey

DB Design & App Dev 10:15 AM Efficient Data Warehouse Design Suresh Rajappa

DB Design & App Dev 11:30 AM Introduction to Windows Phone 7 Development Carlos Femmer

DB Design & App Dev 01:30 PM Conceptual Data Modeling: Defining Our Data Eli Weinstock-Herman

DB Design & App Dev 2:45 PM 3rd Normal Form: That's crazy talk!!! Thomas LeBlanc

DB Design & App Dev 4:00 PM Parallelism Options in .NET 4.0 Al Manint

Microsoft .NET Framework from Scratch 9:00 AM Microsoft .NET Framework from Scratch Keith Elder

SQL Admin I 07:30 AM Basic SQL Server Steve Jones

SQL Admin I 9:00 AM Common TSQL Programming Mistakes Kevin Boles

SQL Admin I 10:15 AM An Introduction to Profiler and SQL Trace Trevor Barkhouse

SQL Admin I 11:30 AM Database Maintenance Essentials Brad McGehee

SQL Admin I 01:30 PM Understanding Storage Systems and SQL Server Wesley Brown

SQL Admin I 2:45 PM Running mixed workloads on SQL Server Jason Massie

SQL Admin I 4:00 PM Beginning Powershell Sean McCown

SQL Admin II 9:00 AM Best Practices Every SQL Server DBA Must Know Brad McGehee

SQL Admin II 10:15 AM Introduction to DMVs in SQL 2005/2008 William Assaf

SQL Admin II 11:30 AM SSIS and Powershell: A winning combination Sean McCown

SQL Admin II 01:30 PM SQL Server Memory Deep Dive Kevin Boles

SQL Admin II 2:45 PM Deciding if VMs are a good choice for your SQL Svr Denny Cherry

SQL Admin II 4:00 PM A PowerShell Cookbook for DBAs Trevor Barkhouse

SSIS\BI 07:30 AM Build Your First SSIS Package Tim Mitchell

SSIS\BI 9:00 AM Data Mining in Action: A case study Drew Minkin

SSIS\BI 10:15 AM Dynamic SSIS with Expressions and Configurations Tim Mitchell

SSIS\BI 11:30 AM CDC + SSIS = SCD Patrick LeBlanc

SSIS\BI 01:30 PM MDX 101 Bryan Smith

SSIS\BI 2:45 PM ssis templates: the easy way to win. Tim Costello

SSIS\BI 4:00 PM SQL Source Control: Poor man's data dude. Tim Costello


Thomas LeBlanc

Friday, July 30, 2010

SQLSaturday, BI and What I am reading

SQLSaturday # 28 (http://www.sqlsaturday.com/28/eventhome.aspx) is coming to Baton Rouge on August 14th at LSU in the CEBA building. We have 58 sessions and 490+ registered attendees.

This is the second SQLSaturday for BR thanks to SQL Server MVP Patrick LeBlanc leadership and employees of Sparkhound and Antares as well as LSU. Patrick is my brother from a different mother.

I spoke last year on RML Utilities and SQLNexus, but this year the session I will be presenting is “Third Normal Form: That’s Crazy Talk” (http://www.sqlsaturday.com/viewsession.aspx?sat=28&sessionid=1323). This seems to be my calling as a presentation that I have locked down. Volunteering has been interesting as we watch things change month to month by our fearless leader and great politician.


The other news is I have started a new position at Amedisys, moving from Senior DBA to BI Data Integration Lead Developer. The last 3 weeks have been filled with meetings and documentation review. They have already assigned me tech specs to complete, assist with latest Data Mart ETL and improve performance on the End of Month process. My whole career has revolved around normalized databases, which I am very passionate about. Changing my thinking is difficult (I am 42), and seems to be the biggest barrier. Please pray for me.

Louis Davidson's book Pro SQL Server 2008 Relational Database Design and Implementation (http://drsql.org/ProSQLServerDatabaseDesign.aspx)  is a great and long read that I believe is very comprehensive when it comes to educational reading for database design. I am using the reading of this book to help me prepare for SQLSaturday #28 as well as Houston TechFest (http://www.houstontechfest.com/)  on Oct. 9th. It looks like Houston has accepted 2 sessions, the one above and Whiteboarding Normalization (http://www.houstontechfest.com/dotnetnuke/HoustonTechFest/Sessions/tabid/56/CodecampId/3/SessionId/218/Default.aspx) for their sessions packed event.

Wish me luck, and come back for some more talk about Normalization, and Denormalization at this blog.

God Bless,
Thomas LeBlanc

Friday, July 16, 2010

Database Lookup Tables

Over the years, I have noticed a trend in building databases. A developer will get on a certain path when it comes to what I define as Lookup tables. There are many names or labels the community has placed on this Type/Code/Category of tables, but I want to give 3 examples of the types we ran into in the latest creation of a database.


The below list and table structure was standardized once so everybody (developer, DBA, BI, etc.) would be in agreement. After the Create Table below, please read for an explanation of the columns and types.

1. Drop-down list - this table is really just a pick list for a transaction or category type.
    Example
        BillingClass: B - Billable, NB - NonBillable, etc.
        RequstType: P - Phone, L - Letter, etc.

2. Developer Control - developers usually like to have some tables that cannot be change by end user because it would change the flow of the application code. This group of developers wanted to enumerate the IDs in .Net code. Too bad we (DBAs) can use enumeration in a Query window 
    Example
        WorkFlow - I - Initial, U - Updated, P - Processed & C - Close

3. End User Control - end users want to be able to add to the list for use in the application, but unlike the drop-down list, there are other properties to the Item.
    Example
        RevenueCode - 435 - Inventory stream, 321 - visit cost, etc.

The first 2 types have a consistent structure:

CREATE TABLE [Billing].[lkClass](
    [Code] [varchar](25) NOT NULL,
    [ID] [int] NOT NULL,
    [Name] [varchar](100) NOT NULL,
    [Description] [varchar](1000) NULL,
    [DisplayOrder] [int] NOT NULL,
    [RowState] [int] NOT NULL,
    [TimeStamp] [timestamp] NULL,
  CONSTRAINT [PK_lkClass] PRIMARY KEY CLUSTERED
    ([Code] ASC)
      WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
        IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
        ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
  CONSTRAINT [uc_lkClass_ID] UNIQUE NONCLUSTERED
    ( [ID] ASC )
    WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
       IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
       ALLOW_PAGE_LOCKS = ON) ON [DB_INDEX],
  CONSTRAINT [uc_lkClass_Name] UNIQUE NONCLUSTERED
      ( [Name] ASC )
     WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
        IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON,
        ALLOW_PAGE_LOCKS = ON) ON [DB_INDEX]
  ) ON [PRIMARY]

The code is 25 characters because we voted to have a varchar () that would satisfy all possibilities. Why still use Code when there is a unique ID field? End users still like to be able to type known code/type values into an interface for fast data entry. Even with the intelliSence possibilities, I personally do not see codes going away with end users. Also, reports need abbreviated versions of lookup to help compact display. This is the foreign key to a related table, not the ID.

The ID is used for .Net objects that want to reference a list with an integer, rather than using a Search/Find method to locate the entry in a list/collection. The Name is really the long description, while the Description is what you might call a memo field (notice MS Access reference).

DisplayOrder is self-explanatory and RowState has values like 0-active, 1-inactive, and other numbers reserved for future use. This allows the row to be ‘deleted’ – inactive, but not removed from the table. Timestamp is really the RowVersion data type from SQL Server data types. We have not changed this to RowVersion, yet.

Even though State Abbreviation is known as only 2 characters and you need only 2 columns in the table, we still use this structure because the Object Oriented interface/object code using the same structure is global throughout the project. The end user control type table will include the additional columns on the same table. We do not create a one-to-one relationship to another table just for more attibutes, in most cases.

Primary key is in the Primary file group because it is the clustered index, but the other Unique Constraints are in the INDEX File Group in order to place the Clustered Index (table) on a different file group than the Indexes. The Unique constraints are used to make sure duplicate IDs and/or Names are never possible even though the developers promise that will prevent that in the Code.

Thursday, July 8, 2010

Database Standards Part VI: code and design

Database Standards Part VI:  code and design

This is Part 6 of 6 blogs about database standards. This last post is about coding standards that should be followed.

Design
A data dictionary and diagram should be maintained. The diagram can be a bird's eye view. The dictionary contains tables with description and columns with data type, size, default, constraints and descriptions. The foriegn keys would be listed along with primary keys.

Coding

- Avoid using SELECT *.
- Use CTEs instead of Cursors
- Dynamic SQL is difficult to read, confuses security and not very maintainable.
- NOLOCK and READUNCOMITTED can only be used when absolutely necessary.
- INNER JOIN not JOIN
- prefix objects with schema, even dbo.
- Use TRY/CATCH for error trapping
- only use parentheses for AND\OR expressions
- spaces between expressions and variables
   Type = 'S' NOT type='S'

- BEGIN/END should only be used with there is more than one execution line after condition


Formatting
    Bad:
Select Sample.*, Analysis.*,

Sample.DueDate, Sample.EnteredBy
FROM Sample JOIN
Analysis on Sample.SampleID = Analysis.SampleID

   Better:
SELECT s.SampleID, s.Description AS SampDesc,
    a.AnlCode AS AnalysisCode
  FROM Sample s
      INNER JOIN Analysis a
        ON a.SampleID = s.SampleID
  WHERE s.SampleID = @SampleID


Next set of Blogs will be a diary of the transition from production senior DBA to BI Data Integration Lead Developer.

Thomas LeBlanc
Outoging Production Senior DBA

Thursday, June 17, 2010

Database Standards Part V: Triggers and User-defined Functions

Database Standards Part V: Triggers and User-defined Functions

 
This is Part 5 of 6 blogs about database standards. Again, though we do not enforce these with an iron fist, they are advised for clarity and consistency. The important point, in my opinion, is to establish a set of standards and stick to them.
 
Triggers
Naming convention for triggers are 'it' for insert, 'ut' for update and dt for delete (itPatient). Trigger can slow CRUD statements so we warn developers to be careful when creating triggers. It also can 'hide' logic from development. Over and over, we get confused people trying to find how data gets added to a table because of a trigger on another table. Verify during a review that the trigger can handle multi-row updates when joining to the inserted or deleted recordsets. Most triggers I see are related to auditing Ins/Upd/Del statements.
 
User-Defined Functions
User-defined functions are prefixed with udf. They can be helpful with string manipulation commonly used in stored procedures or SQL statements. UDFs do add processing time to the execution and can cause scans when used on fields in a WHERE clause. Looking at an execution plan might exclude the code from the UDF. I see table-valued UDFs used like DMFs from dynamic management objects from Microsoft, mostly on small data sets.
 
Also, when  profiling, you get a statement for each call to the udf for each row in the SELECT statement if used in a query, so you might want to exclude the data in the profiled output.
 
Repeating again, and again…

Though my opinion is not the same as some of these standards, I do believe standards should be discussed and established, then followed. If a deviation is needed, a group discussion should be voted on to change.

Next week I will talk about coding and deisgn standards.

Thomas LeBlanc

Friday, June 4, 2010

Database Standards Part IV: Stored Procedures


This is Part 4 of 6 blogs about database standards. Again, though we do not enforce these with an iron fist, they are advised for clarity and consistency. The important point, in my opinion, is to establish a set of standards and stick to them.

Stored Procedure
Stored procedures should be required for all create, read, update and delete (CRUD) DML (Data Manipulation Language) statements. Using stored procedures benefits security, consistence, performance and manageability on the DBA side of applications.

Security can be managed by giving GRANT EXECUTE to logins requiring access to DML statements, or in 2005 and greater EXECUTE can be granted to a login on the entire database. Performance gains are realized in compiled query plans and SQL Server’s ability to re-compile only the statement in the SP that needs a new/better plan.

Naming conventions:
  Read - uspPatientGet or GetPatient
  Delete - uspPatientDel or DelPatient
  Report – rptSecurityAudit
  Process – prcProcessPatient

The use of Schemas can better organize the SPs. Do not use prefixes sp, sp_ or xp_. These are used by the SQL Server system or custom extended procedures.

Precompiled SQL can use less memory in the Procedure Cache and require less look up in Proc Cache for existing plans.

Remember not to repeat the schema name in the SP – Patient.GetDetails instead of Patient.GetPatientDetails.

SET ANSI_NULLS ON can be a requirement because it will be depreciated in future SQL Server versions.

SET NOCOUNT ON can be prevent round trips to the client - http://msdn.microsoft.com/en-us/library/ms189837.aspx

Using a Source Control application can reduce comments in a SP. The versioning in TFS or Source Safe gives the developer the ability to associate comments with the check in. Our SPs begin with the following structure

IF NOT EXISTS (SELECT * FROM Sys.Objects
                              WHERE Object_Id = OBJECT_ID(N’[Ptient].[rptPatientReleased] ’)
                                 AND type in (N’P’, N’PC’))
  BEGIN
    CREATE PROCEDURE [Ptient].[rptPatientReleased]
      AS RETURN
    GO
  END

ALTER PROCEDURE [Aptient].[rptPatientReleased] AS
    SELECT TOP 10 * FROM NewProcedureView
  GO

Always end the SP in GO when creating or altering. The Alter is preferred because it retains permissions on SP. If DROP/CREATE is used, remember to apply the permissions. Return should not be used to return data to the calling application. Return should be reserved for returning the status of the SP. Use INPUT and OUTPUT parameters in the SP.

Repeating again, and again…
Though my opinion is not the same as some of these standards, I do believe standards should be discussed and established, then followed. IF a deviation is needed, a group discussion should be voted on to change.

Next week I will talk about Triggers and User-Defined Functions.

Thomas LeBlanc