SSDT Workshop @ SQL Bits X (2012-03-29)

4,652 views

Published on

Mastering SSDT with the DataDude

This is your chance to hear the real story behind SSDT, directly from the man who built it. SQL Server Data Tools is effectively the 3rd version of the DataDude project, started in 2005 by Gert Drapers. SQL Server Data Tools (SSDT) lets you develop, test, and maintain SQL Server and SQL Azure databases offline on your desktop. SSDT's modern T-SQL development environment supports declarative model-driven development whether working connected or offline, and integrates with Visual Studio's project and application lifecycle management tools to enable team development and source code control support for SQL Server and SQL Azure databases.

This master class will get you started using SSDT; provides you with the architectural ins and outs of schema management using SSDT; team oriented database development and leveraging the command line and programmatic interfaces that accompany SSDT for importing, comparing and deploying database schemas. Learn it from the DataDude himself.

Published in: Technology
1 Comment
3 Likes
Statistics
Notes
No Downloads
Views
Total views
4,652
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
104
Comments
1
Likes
3
Embeds 0
No embeds

No notes for slide
  • Developer-focused toolset for building SQL Server & SQL Azure databasesExperiences EnabledConnected DevelopmentProject Based DevelopmentApplication Lifecycle & ToolsFundamentalsDeclarative, model based database developmentIntegrated tools with modern language services Connected and offline with local testingTarget SQL Server and SQL AzureDetecting and managing database drift
  • SQL Server Object Explorer (SSOX)Modeled after SSMS object explorerModern T-SQL Coding Experience Buffered Declarative Object EditingModel-based with Error DetectionImperative Script ExecutionT-SQL IntelliSenseCode-behind Table DesignerView/Edit/Script Data (incl. copy/paste)Execute/Debug T-SQL Procedures, Functions
  • Database definition managed in a Visual Studio projectMulti-target SQL Server {2005, 2008, 2008R2, 2012, Azure}Advanced Language Services for T-SQLGo To Definition/Find All References/RefactoringF5 debugging with LocalDBVisualize schema differences and migrate changesPublish direct to database or via SQL script or DACPACIntegrated database drift detectionPoint-in-time SnapshotDrag & Drop import from SQL Server Object ExplorerApplication Lifecycle & ToolsMSBuild tasks for:BuildPublishT-SQL Static Code AnalysisMSBuild in a redist (SSDTBuildUtilities.msi)Database projects in build server environment (like Team Build) without installing full VS on build serverSSDT Integrates with all standard VS SCCS providersDACFX v3Schema ComparePublish
  • Publishing your Database ChangesTarget version aware:SQL Server 2005SQL Server 2008 & SQL Server 2008 R2SQL Server 2012SQL AzurePublish Direct, via SQL script, or DACPAC snapshots
  • DAC Framework v3.0 (DACFX)DAC FrameworkDACFX is the core SQL redist providing modeling, reverse engineering and deployment pipeline capabilitiesv3.0 supports the full domain of SQL Server 2005, 2008/R2, 2012, and SQL AzureManaged Public APIExposes verbs for DACPAC and BACPAC operationsCommand-line tool (SqlPackage.exe)Exposes DACPAC verbs, project publishDACUnpack.exeWindows file handler for unpacking DACPAC to diskDACFX ClientsSSMS, SSDT, SAMP, I&E, VS Web and DB Publishing
  • SQL Server Data Tools – SummaryDeveloper-focused toolset to author, debug and publish SQL Server & SQL Azure databasesSupports SQL PlatformFree, web updates for SQL Server and SQL Azure releasesWorks in concert with other SQL Server tooling (SAMP, SSMS)Compatible with your development environmentSupports Visual Studio 2010 & Visual Studio 11Migrates VS2010 database projects (*.dbproj)
  • Schema Compare is an incredibly useful tool, providing a visual head over SSDT’s model differencing and update engine. It can be used to compare any combination of database, project or dacpac, and allows selective update of the target schema (via an update script in the case of a dacpac). We’ve made some significant changes to the tool for the RTW release, improving its look and feel, particularly to make it easier to digest and process comparison results. This post describes many of Schema Compare's key features – some of which surfaced in CTP4 – with a screen shot at the bottom that highlights several of them.First, the visual comparison ‘language’ of the results grid:Differences-Only by Default: By default the grid contains differences only (with empty folders removed) – if there is only one difference you will see just one item. And the grid always contains all the actions resulting from the comparison – while you can hide an action temporarily within a contracted group it is always present in the grid and will apply to the update or script unless you exclude it by unchecking the action.Equal Objects filter:A toolbar button adds equal objects to the grid. Enabling this is useful if you want to review, for example, unchanged columns alongside the changed columns in a table. Unsupported Actions filter: You can also choose to see unsupported actions – these result from differences for which there is no supported action that can be taken on the target. These typically result from differences in server objects or built-in types between schema versions.Action Icons: Actions (Add, Change, and Delete) are visualized using icons, making it easier to absorb a set of changes at a glance. The checkbox alongside an icon indicates if the action will be included in the update or generated script. If there is no icon the item will not be included in an update or script.Grayed Items: Items that do not contribute to the update are grayed – excluded actions, unsupported actions and equal objects are all grayed. Folders are grayed when all their contents are grayed making it easy to see when a group of differences have all been excluded without you needing to drill in.Grouping: By default, items are grouped by action so you can quickly assess what changes will be made on update. You can also group the results by object type or by schema. You can expand or collapse a group to temporarily hide detail, and you can exclude all or include all objects in a group.Refactor Highlighting: Schema Compare processes the refactor log if present when targeting a database. Refactoring is indicated in the grid as a change action with the source name bolded to highlight the new schema and/or name. Refactoring will cause objects to be renamed in the database. Refactoring sometimes also shows up as a second order effect on other objects that SQL Server will modify when applying the rename. These will not be marked as actions in the grid as you cannot exclude them, but you will see the changed script if you select the affected object. Probably the biggest set of changes affects the script difference pane. While the grid provides a great overview, to see all changes to an object in the grid you have to fully expand it, which, can quickly clutter the view if you're reviewing many objects. To address this we’ve focused more attention on the script differencing experience – after all, you are writing and editing object scripts to begin with. Changes include:Expanded Object Scripts: The script difference pane now shows the combined scripts for an object and its hierarchical children. This gives a complete picture of all the changes affecting an object in one easy-to-scan place. To complement this, the Next and Previous buttons step between top-level objects only. Together, these two changes can dramatically simplify scanning through the results of a comparison. Enhanced Script Differencing: The script difference algorithm now treats child objects as discrete entities, more effectively highlighting those that have been added, deleted or changed. The color scheme is now more subtle and better reinforces the direction of changes. And remember that you can expand the script pane or swap it to the top – so you can easily optimize the layout to better focus on reviewing scripts.The screen shot below highlights many of these improvements.
  • SqlPackage: Command-line tool for creating and deploying SQL Server databases and DACPAC packages.Copyright (c) Microsoft Corporation. All rights reserved.Help for dynamic property usage./@<file>:<string> Read response file for more options./help:[True|False] (short form /?)Help for command actions./Action:{Extract|DeployReport|DriftReport|Publish|Script} Specifies the action to be performed. (short form /a)/OutputPath:<string> Specifies the file path where the output files are generated. (short form /op)/OverwriteFiles:[True|False] Specifies if sqlpackage.exe should overwrite existing files. Specifying false causes sqlpackage.exe to abort action if an existing file is encountered. Default value is True. (short form /of)/Profile:<string> Specifies the file path to a DAC Publish Profile. The profile defines a collection of properties and variables to use when generating outputs. (short form /pr)/Properties:{PropertyName}={Value} Specifies a name value pair for an action specific property; {PropertyName}={Value}. Refer to the help for a specific action to see that action's property names. Example: sqlpackage.exe /Action:Publish /?. (short form /p)/Quiet:[True|False] Specifies whether detailed feedback is suppressed. Defaults to False. (short form /q)/SourceConnectionString:<string> Specifies a valid SQL Server/Azure connection string to the source database. If this parameter is specified it shall be used exclusively of all other source parameters. (short form /scs)/SourceDatabaseName:<string> Defines the name of the source database. (short form /sdn)/SourceEncryptConnection:[True|False] Specifies if SQL encryption should be used for the source database connection. (short form /sec)/SourceFile:<string> Specifies a source file to be used as the source of action instead of a database. If this parameter is used, no other source parameter shall be valid. (short form /sf)/SourcePassword:<string> For SQL Server auth scenarios, defines the password to use to access the source database. (short form /sp)/SourceServerName:<string> Defines the name of the server hosting the source database. (short form /ssn)/SourceTimeout:<int> Specifies the timeout for establishing a connection to the source database in seconds. (short form /st)/SourceTrustServerCertificate:[True|False] Specifies whether to use SSL to encrypt the source database connection and bypass walking the certificate chain to validate trust. (short form /stsc)/SourceUser:<string> For SQL Server auth scenarios, defines the SQL Server user to use to access the source database. (short form /su)/TargetConnectionString:<string> Specifies a valid SQL Server/Azure connection string to the target database. If this parameter is specified it shall be used exclusively of all other target parameters. (short form /tcs)/TargetDatabaseName:<string> Specifies an override for the name of the database that is the target of sqlpackage.exe Action. (short form /tdn)/TargetEncryptConnection:[True|False] Specifies if SQL encryption should be used for the target database connection. (short form /tec)/TargetFile:<string> Specifies a target file (i.e., a .dacpac files) to be used as the target of action instead of a database. If this parameter is used, no other target parameter shall be valid. This parameter shall be invalid for actions that only support database targets. (short form /tf)/TargetPassword:<string> For SQL Server auth scenarios, defines the password to use to access the target database. (short form /tp)/TargetServerName:<string> Defines the name of the server hosting the target database. (short form /tsn)/TargetTimeout:<int> Specifies the timeout for establishing a connection to the target database in seconds. (short form /tt)/TargetTrustServerCertificate:[True|False] Specifies whether to use SSL to encrypt the target database connection and bypass walking the certificate chain to validate trust. (short form /ttsc)/TargetUser:<string> For SQL Server auth scenarios, defines the SQL Server user to use to access the target database. (short form /tu)/Variables:{PropertyName}={Value} Specifies a name value pair for an action specific variable; {VariableName}={Value}. The DACPAC file contains the list of valid SQLCMD variables. An error will result if a value is not provided for every variable. (short form /v)
  • SSDT Workshop @ SQL Bits X (2012-03-29)

    1. 1. SQL SERVER DATA TOOLSWORKSHOPEverything you need to know to get started
    2. 2. Slides 2  SQLProj.com  http://sqlproj.com/index.php/2012/03/sqlbits-2012- ssdt-workshop/  Slides:  http://sqlproj.com/wp-content/uploads/2012/03/SSDT- Workshop-2012-03-29-final.pdf  Handout  http://sqlproj.com/wp-content/uploads/2012/03/SSDT- Workshop-2012-03-29-handout.pdfCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    3. 3. 3 Introduction gert.drapers@microsoft.comCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    4. 4. Copyright and Disclaimer 4  This presentation, including examples are provided for informational purposes only, the author makes no warranties, either express or implied.  Information in this presentation, including samples, URL and other Internet Web site references, are subject to change without notice.  Complying with all applicable copyright laws is the responsibility of the user.  Without limiting the rights under copyright, no part of this document may be reproduced, stored in or introduced into a retrieval system, or transmitted in any form or by any means (electronic, mechanical, photocopying, recording, or otherwise), or for any purpose, without the express written permission of the author.  The names of actual companies and products mentioned herein may be the trademarks of their respective owners.Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    5. 5. @DataDude 5  1986-1988 IBM Corporation  1988-1991 Ashton-Tate  1991-present Microsoft Corp.  SDE in the Developer Relations Group (the Netherlands)  Senior Development Consultant in MCS (the Netherlands)  SDE in Storage Engine (DBCC, Bulk Insert and Convert)  Program Manager SQL-DMO and Query Analyzer  Product Unit Manager SQL Server Management Tools  Software Architect DTS 2005 (now SSIS) and SMO  Software Architect MS-DTC, COM+, System.Transactions, WS-AT  Software Architect SQL Server Customer Advisory Team (Europe)  Principal Group Engineering Manager “Visual Studio Team System Database Edition”  Principal Software Architect Azure Active Directory  Principal Software Architect Cloud Programmability (SQL)  Principal Group Program Manager SQL Server Data PlatformCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    6. 6. Agenda 6  SQL Server Data Tools Overview  SQL Server Data Tools Installation  Data-Tier Application Component (DAC)  Declarative Database Development  Connected Development  Project Based Development  Application Life Cycle Integration  Programmatic and Command Line UsageCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    7. 7. 7 SQL Server Data Tools OverviewCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    8. 8. Database Development Challenges 8  Databases are inherently stateful  Focus is on ALTER instead of CREATE  Dependencies complicate scripts  Errors are often found only when scripts are executed  Synchronizing application and database versions  Database development often not integrated in to application life cycle management and processes  Targeting different SQL Server and SQL Azure versionsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    9. 9. History of the “DataDude” Project 9  Project funded April 2005  Project started July 1st 2005  Visual Studio 2005 Team System for Database Professionals  Visual Studio 2008 Team System for Database Professionals  Re-architected to be declarative model based system  Visual Studio 2008 Team System for Database Professionals GDR R2  Visual Studio 2010 Team System for Database Professionals  Transitioned to SQL Server 2009  SQL Server Data ToolsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    10. 10. Introducing SQL Server Data Tools 10Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    11. 11. Connected Development 11 T-SQL IntelliSense Drift Detection Table Designer SQL Server Object Explorer T-SQL Debugging View Code Schema Comparison T-SQL Editor View/Edit Data Error InformationCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    12. 12. Project Based Development 12 Source Code Point-in-time Go To Definition Source Code Based Snapshots Control Visualize Schema Find All References F5 Debugging & MSBuild Differences Testing with Headless LocalDB T-SQL Static Code Refactoring Command Line Analysis ToolsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    13. 13. Schema Deployment 13 Model Based SQL Server 2005 DACPAC Format SQL Server 2008 SQL Server 2012 Incremental SQL Azure Connected Engine Schema Deployment Retargeting Support SQL Script API & REDISTCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    14. 14. SQL Azure Management Portal Import Publish Export Compare Register Sync Unregister DAC SQL Server Data Tools SQL Server Management StudioCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    15. 15. Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    16. 16. Resources 16  SQL Server Data Tools Online Installation  http://msdn.microsoft.com/data/tools Get It  Team Blog  http://blogs.msdn.com/b/ssdt/  MSDN Forum  http://social.msdn.microsoft.com/Forums/en- US/ssdt/threads  Articles  MSDN Magazine Sept 2011 The "Juneau" DatabaseCopyright © 2012 GertProject Drapers - All Rights Reserved. 03/29/2012
    17. 17. SQL Server Data Tools 17 InstallationCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    18. 18. Setup Options 18  Install from online Web Platform Installer feed  Install from SQL Server 2012 DVD  Install from Visual Studio 11  Install from offline administrative installCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    19. 19. Supported OS Platforms 19  Windows Vista SP2+  Windows 7 SP1+  Windows Server 2008 SP+  Windows Server 2008 R2 SP1+  Note: this is different then the Visual Studio 2010 platformsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    20. 20. Visual Studio Requirements 20  Visual Studio 2010 Integrated Shell+  SQL-CLR requires Visual Studio 2010 Standard+  Visual Studio 2010 SP1+  Notes:  SQL Server 2012 only installs VS 2010 Integrated Shell SP1  If you have an existing Visual Studio 2010 installation you must install SP1 yourself (?KB VS2010 SP1 checks)  Watch for mixed mode (?KB detecting mixed mode)Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    21. 21. SSDT Online Acquisition 21  Install online via Web Platform Installer (WebPI)  SSDT download link for latest bits  http://msdn.microsoft.com/en-us/data/hh297027  Requires WebPI v3.0 or better to be installed  User is prompted on first attempt when not installed or updated  Automatically downloads all required new or updated dependencies  Invokes SSDTSetup.exe (chained installer)Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    22. 22. Installing from SQL Server 2012 DVD 22  Install SSDT from SQL Server 2012 DVD image  Install VS 2010 SP1 shell if you do not have VS installed  If you do have VS 2010 install, user needs to install SP1!  DVD puts down a “stub” which will acquire latest SSDT bits online via (WebPI)  See http://sqlproj.com/index.php/2011/11/ssdt-setup- from-sql-server-2012/ for detailed step throughCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    23. 23. Creating an Admin Install 23  SSDTSetup.exe /layout C:SSDTAdminInstall  Pulls down all the latest dependencies from the web  Enables generating a local install point which can be shared via a file share or USD drive  DMZ or offline installation scenario  For detailed steps see:  http://sqlproj.com/index.php/2011/11/creating-an- administrative-install-for-ssdtCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    24. 24. SSDTSetup 24  SSDTSetup.exe  Setup chainer (486 KB)  SSDTx86SSDT.msi  Actual tools (5.75 MB)  SSDTx86SSDTBuildUtilities.msi  MSBuild targets and utilities (970 KB)  SSDTx86DbSqlPackageProvider.msi  Web Deploy Provider (729 KB)Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    25. 25. Setup Dependencies (payload directory) 25  x86DACFramework.msi  dotNetFx40_Full_x86_x64.exe  x86NDP40-KB2468871-v2-x86.exe  NDP40-KB2544514-x86-x64.exe  x86SharedManagementObjects.msi  x64DACFramework.msi  x86SQLDom.msi  x64NDP40-KB2468871-v2-x64.exe  x86SqlLocalDB.msi  x64SharedManagementObjects.msi  x86sqlls.msi  x64SQLDom.msi  x86SQLSysClrTypes.msi  x64SqlLocalDB.msi  x86SSDTDBSvcExternals.msi  x64sqlls.msi  x86TSqlLanguageService.msi  x64SQLSysClrTypes.msi  x86VS10sp1-KB983509.exe  x64TSqlLanguageService.msi  x86VSIntShell.exeCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    26. 26. Setup Dependencies 26  .NET 4.0 CLR runtime  dotNetFx40_Full_x86_x64.exe  .NET 4.0 CLR general update  http://support.microsoft.com/kb/2468871  NDP40-KB2544514-x86-x64.exe  Update 4.0.2 for Microsoft .NET Framework 4 – Runtime Update  http://support.microsoft.com/kb/2544514  NDP40-KB2544514-x86-x64.exe  LocalDB support  Visual Studio 2010 integrated shell  VSIntShell.exe  Visual Studio 2010 SP installer  VS10sp1-KB983509.exe  http://support.microsoft.com/kb/983509Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    27. 27. Setup Dependencies… 27  SQL Server 2012 Data-Tier Application Framework v3.0  DACFramework.msi  SQL Server 2012 Express LocalDB  SqlLocalDB.msi  SQL Server 2012 Script DOM (parser)  SQLDom.msi  SQL Server 2012 Language Services (compiler and binder)  sqlls.msi  SQL Server 2012 CLR types (geo and hierarchy)  SQLSysClrTypes.msi  SQL Server 2012 Management Objects (SMO)  SharedManagementObjects.msi  SQL Server 2012 Language Services (IntelliSense parser)  TSqlLanguageService.msiCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    28. 28. Headless Installation 28  Install the five following components:  SQL Server 2012 Data-Tier Application Framework (DACFramework.msi)  SQL Server 2012 Transact-SQL ScriptDom (SQLDOM.MSI)  SQL Server 2012 Transact-SQL Compiler Service (SQLLS.MSI)  Microsoft System CLR Types for Microsoft SQL Server 2012 (SQLSysClrTypes.msi)  SQL Server Data Tools Build Utilities (SSDTBuildUtilities.msi)  NOTE: Need to copy from SSDT Administrative install point  For detailed description see:  http://sqlproj.com/index.php/2012/03/headless-msbuild-support-for-ssdt- sqlproj-projects/Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    29. 29. Visual Studio 2012 29  SQL Server Database Projects are a standard feature in Visual Studio 2012  Replaces Visual Studio Database Projects  Available in Visual Studio Professional edition and up  Integrate shell version will be made available separately as online download  Visual Studio 2012 RTM will ship with the same functionality as the SSDT version shipping with SQL Server 2012 RTM  Round tripping of projects and project artifacts between VS2010 and VS2012 hosted SQL Server Database ProjectsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    30. 30. Setup Log Files 30  dir %temp%sql_SSDT_1000*.log  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_0_SQLLS11X64.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_1_SQLDOM11X64.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_2_TSQLLANGSVC11X64.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_3_DACFX11X86.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_4_DACFX11X64.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_5_SQLLOCALDBX64.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_6_SQLCLRTYPES11X86.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_7_SQLCLRTYPES11X64.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_8_SQLSMO11X86.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_9_SQLSMO11X64.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_10_SSDTEXTERNALS10.log“  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_11_SSDTBUILDUTILITIES10.log"  "C:UsersgertdAppDataLocalTempsql_SSDT_1000_20120218114502_12_SSDT10.log"Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    31. 31. 31 Declarative Database Development The foundationCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    32. 32. Simple Schema Versioning Example 32 -- version 1 -- version 2 CREATE TABLE dbo.Auction ALTER TABLE dbo.Auction ( WITH CHECK ADD CONSTRAINT Au_PK id INT NOT NULL, name VARCHAR(25) NOT NULL, -- version 3 start DATETIME NULL, ALTER TABLE dbo.Auction len INT NULL WITH CHECK ) ADD CONSTRAINT Au_SK UNIQUE (name) V1 V2 V3 Revision HistoryCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    33. 33. Imperative 33  Imperative scripts hard codes knowledge about:  The state of the target system:  Presence of objects, dependencies, unbinding, rebinding  Required ordering of operations  Cumulative changes need to be serialized  v1v2v3v4v5 instead of v1v4v5  Validating the end-result against expected end-state is hard  No easy way to compare expected vs. actual  Batching or separating multiple changesCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    34. 34. Imperative Versioning 34 -- version 1 Add table dbo.Auction IF OBJECT_ID (Ndbo.Auction, NU) IS NULL BEGIN CREATE TABLE dbo.Auction (` id INT NOT NULL, name VARCHAR(25) NOT NULL, start DATETIME NULL, len INT NULL ) END -- version 2 Add PK Au_PK IF NOT EXISTS (SELECT * FROM sys.key_constraints WHERE name = Au_PK AND type = PK) BEGIN ALTER TABLE Auction WITH CHECK ADD CONSTRAINT Au_PK PRIMARY KEY (id) END -- version 3 Add UC Au_SK IF NOT EXISTS (SELECT * FROM sys.key_constraints WHERE name = Au_SK AND type = ‘UQ) BEGIN ALTER TABLE Auction WITH CHECK ADD CONSTRAINT Au_SK UNIQUE (name) ENDCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    35. 35. Declarative 35  Define what you want in the form of a model  Fill the model using a DSL (domain specific language)  T-SQL  Use the model as the starting point “blueprint” for all operations  Deployment/publish, start by comparing the current state of the target with the required state (blueprint)  Use the resulting difference knowledge to programmatically generate an deployment plan  Use plan to create sequence of (SQL) statements required to make the target state become like the blueprint stateCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    36. 36. Declarative Versioning 36 -- version 1 CREATE TABLE dbo.Auction -- version 2 ( CREATE TABLE dbo.Auction -- version 3 id ( INT NOT NULL, dbo.Auction CREATE TABLE name id ( INT NOT NOT NULL, VARCHAR(25) NULL PRIMARY KEY, start DATETIME INT NOT NOT NULL, name id NULL, VARCHAR(25) NULL PRIMARY KEY, len start NULL VARCHAR(25) NOT NULL UNIQUE, INTname DATETIME NULL, ) len start NULL INT DATETIME NULL, ) len INT NULL ) V1 V2 V3 Revision HistoryCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    37. 37. Declarative Schema Deployment 37 37 Source Target Model Reverse Schema Schema Compare Engineer Model Model Diff List Plan Optimizer Additional schema Deploy Plan artifacts Script Generator Script Target Executor Incremental target update DBCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    38. 38. Imperative vs. Declarative 38  Manual vs. generated / programmatic  Point in time vs. always current  Sequential vs. differentialCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    39. 39. Script Fundamentals 39  Requirement to be able to round trip DSL A artifacts S T  Script  Model Script  SQL script Parse T-SQL Parser Script fragment Fragment  Script fragment Script Gen  SQL script Script Script Gen T-SQL  Script fragment is AST Fragment (Abstract Syntax Tree)Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    40. 40. ScriptDom 40  SQL Server 2012 managed parser  Supports SQL Server 2005+  Class TSqlXXXParser  XXX = [80, 90, 100, 110]  SQLDom.msi (redist x86/x64)  Microsoft.SqlServer.TransactSql.ScriptDom.dll  C:Program Files (x86)Microsoft SQL Server110SDK AssembliesMicrosoft.SqlServer.TransactSql.ScriptDom.dll  GACCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    41. 41. Basic ScriptDom loop 41 static void Main(string[] args) { bool initialQuotedIdentifiers = false; TSqlParser parser = new TSql110Parser(initialQuotedIdentifiers); StreamReader sr = new StreamReader(@".test.sql"); IList<ParseError> errors; TSqlFragment fragment = parser.Parse(sr, out errors); StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()); Sql110ScriptGenerator scriptGen = new Sql110ScriptGenerator(); scriptGen.GenerateScript(fragment, sw); }Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    42. 42. Reusable Building Blocks 42  Model Store  Model Builder  Model Serialization  Model Comparison  Model CopyCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    43. 43. Model Store 43  Elements  Models are stored in  Relationships ESE database or in- memory  Properties  *.dbmdl (Database  Identifiers Model) file extension  Annotations used by local model cache.Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    44. 44. Model Builder 44  The schema model is populated using information from the AST representation of the SQL parser  From a model element you can recreate a script fragment (AST)Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    45. 45. Model Serialization 45  Act of serializing and de-serializing a schema model to and from disk or in- memory persistence model  Model is serialized as XML  See digesting aCopyright © 2012 GertDACPAC Drapers - All Rights Reserved. 03/29/2012
    46. 46. Digesting a .DACPAC 46  OPC file  Unpack handler associated at file system level  Rename .dacpac to .zip to open  Compressed  Versioned  SQL Server 2012 ships with DACPAC version 3.0.0.0  http://en.wikipedia.org/wiki/Open_Packaging_Convent ionsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    47. 47. .DACPAC streams 47Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    48. 48. Reverse Engineer 48  Reverse Engineering is a special form of model builder, which scripts the content of a source database in the form of SQL scripts (model DSL input format) to construct a modelCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    49. 49. Model Copy / Compare 49  Comparing two declarative models to determine the difference  The comparison engine exposes options for excluding object instances, object types, specific options on objects and certainCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    50. 50. Deployment & Schema Compare 50 Script Script Model Model Builder Builder Fragment Fragment Source Target Reverse Reverse DB Schema Schema DB Engineer Engineer Model Model Model Schema Model Compare Model Schema Package Serializer Serializer Package Diff List Plan Diff Optimizer Visualizer Deploy Plan ScriptCopyright © 2012 Gert Drapers - All Rights Reserved. Generator 03/29/2012
    51. 51. Model Based 51 .SQL SqlScript Schema Parse Dom Interpret Validate Source Model  All schema objects are represented inside a model  What is in the model is defined by the provider  To load/hydrate a model instance  Parse  SqlCodeDom, based on parsers Abstract Syntax Tree (AST)  Interpretation Schema Model  Symbol list  Object References (hard and soft dependencies)  ValidationCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    52. 52. Component Stack 52 SQL Server Data Tools TSQL DACFX SMO System.Data. SqlClient Language Services NetFX Patches Visual Studio SQLLS SQLDOM SQLCLRTypes LocalDB VS2010 SP1, VS2012Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    53. 53. Data-Tier Application 53 Component DACCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    54. 54. What is a Data-Tier Application (dacpac)? 54  Data-Tier Application Component (DAC)  SQL Server database registered as Data-Tier Application Component  DAC is a self contained entity of a database used by an application  Unit of deployment and management  Authored along side your application code  Compiled into a DAC package (DACPAC)  Extracted for existing databases  Database extracted (DACPAC) or exported (BACPAC) into packages  Package is deployable to SQL Server and SQL AzureCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    55. 55. DAC Framework v3.0 (DACFX) 55  Core SQL Server redist component providing modeling, reverse engineering and deployment capabilities  Managed Public API  Exposes verbs for DACPAC and BACPAC package operations  Command-line tool (SqlPackage.exe)  Executable over the managed public API  DACUnpack.exe  Windows file handler for unpacking DACPACs to disk  DACFX Clients  SqlPackage.exe, SSMS, SSDT, SAMP, I&E, VS Web and DB PublishingCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    56. 56. DACFX Packages 56  .dacpac - Packaged Schema representing the declarative model of the database  Not SQL, but a declarative Schema Model representation of the database  Compiled from source code or Extracted from existing databases  Deploy as new database or Incremental Upgrade an existing database  Supports all SQL Server Objects and Types  .bacpac - Packaged Schema and Data representing the state of the database  Composed of Schema Model with stateful properties and Data Streams  Exported from existing databases  Imported as a new database or populates an empty database  Supports most SQL Server Objects and Types (SQL Azure parity)Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    57. 57. DAC Evolution 57Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    58. 58. DACFX Supported SQL Server Objects and Versions 58  SQL Server 2012 DACFX (v3.0) supports the full SQL Server Domain  Supports the following versions:  SQL Server 2005  SQL Server 2008/R2  SQL Server 2012  SQL Azure  DACFX (v3.0) backwards compatibility  DACFX 1.0, 1.1, and 2.0Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    59. 59. Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    60. 60. SQL Server Data Tools 60  Developer-focused toolset for authoring, building and publishing DACPACs  Experiences Enabled  Connected Development  Project Based Development  Application Lifecycle & Tools  DACPAC verbs  Author DACPAC declaratively and build from source  Compare DACPAC to project, database, and other DACPACs  Import DACPAC into project  Publish DACPAC/Project to databaseCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    61. 61. SQL Server Management Studio 61  DBA-focused tools for deploying and extracting DACPACs; importing and exporting BACPACs  Experiences Enabled  Administration and Monitoring  Connected Development  Configuration and Task Wizards  DACPAC Verbs Supported  Deploy Data Tier Application  Register/Unregister Data Tier Application  Upgrade Data Tier Application  BACPAC Verbs Supported  Import Data Tier Application  Export Data Tier Application  Migrate Database to SQL AzureCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    62. 62. SQL Azure Management Portal 62  Subscriber and Operator oriented toolset for managing SQL Azure databases through DAC Verbs  Experiences Enabled  Connected Development  Portal Based Tools  Application Lifecycle support  DACPAC verbs supported  Deploy Data Tier Application (create new database from dacpac)  Upgrade Data Tier Application (upgrade database to match dacpac)  Extract Data Tier Application (create dacpac from existing database)  BACPAC Verbs supports  Export Data Tier Application (export database as bacpac to Windows Azure Blob Storage)  Import Data Tier Application (import bacpac as new database from Windows Azure Blob Storage)Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    63. 63. DAC Lifecycle 63 Developer DBA DBA/Admin Develop (SSDT) Deploy (SSMS) Manage (SSMS and SAMP) • Import Database/ • Deploy Package • Export and Extract DACPAC • New Databases Packages • Author DAC • Upgrade Databases • Register Database as DAC • Compare and Synchronize Source • Compile Database Project to DACPAC • Publish DACPACCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    64. 64. 64 Connected Development Imperative & Declarative Schema Authoring and DeploymentCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    65. 65. Connected Development 65  SQL Server Object Explorer (SSOX)  T-SQL Editor/Debugger/IntelliSense (New Query)  Power-Buffer (New Object/View Code)  Table Designer (View Designer)  Data Editor (View Data)  Execute Procedure/Function  Schema CompareCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    66. 66. SQL Server Object Explorer (SSOX) 66  The SQL Server navigation tool window  Modeled after the SSMS Object Explorer  Server scoped vs. Server Explorer which is database scoped  Launch point for T-SQL Editor, Debugger, Object Execution, Designers, …  Supports connecting directly to SQL Server  SQL Server {2005, 2008, 2008R2, 2012} and SQL Azure  Supports connecting directly to a (contained) database  Constructs a partial model in the background and under the covers  Supports:  Cascading Drops and Renames  Drift detection  Automatically updates the tree/source as changes occur on the server  SSOX is a DSRef drag sourceCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    67. 67. SSOX Drift Detection 67  Controlling Refresh Rate  HKEY_CURRENT_USERSoftwareMicrosoftVis ualStudio10.0SQLDBDialogPageMicrosoft.Visu alStudio.Data.Tools.Package.ToolsOptions.Online Editing.OnlineEditingOptionsSettings] "PollingDriftCheckSeconds"="30"  Defaults to 30. If set to <= 0 will be infinite (3 days). Cannot be less than 30.Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    68. 68. T-SQL Editor/Debugger/IntelliSense 68  T-SQL IntelliSense  Other Options:  SQL Server 2005+ incl. SQL  Actual Execution Plan Azure  SQLCMD mode  Result to Grid | Text | File  Client Statistics  Execution modes  Code snippets  Parse  Reusable debug script  Estimated Execution Plan generation  Execute  Keyboard shortcut mapping  Execute with debugger alignment  Out-of-band delivery of SSMSCopyright © 2012 Gert Drapers - All Rights Reserved. profile 03/29/2012
    69. 69. T-SQL Editor Keyboard Mapping 69 Commands SSMS Keyboard Compatibility Settings SQL Server Development Settings Execute CTRL+E / ALT+X / CTRL+SHIFT+E CTRL+SHIFT+E Execute w/Debugger ALT+F5 ALT+F5 Cancel Query Execution ALT+BREAK ALT+BREAK Include Actual Execution Plan CTRL+M CTRL+D, A Display Estimated Execution Plan CTRL+L CTRL+D, E Results As Grid CTRL+D CTRL+D, G Results As Text CTRL+T CTRL+D, T Results As File CTRL+SHIFT+F CTRL+D, F Show/Hide Results CTRL+R CTRL+D, R New File CTRL+N None defined http://blogs.msdn.com/b/ssdt/archive/2012/03/07/using-ssms-keyboard-mappings-in-ssdt.aspxCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    70. 70. T-SQL Editor/Debugger/IntelliSense 70  Toolbar consistencyInclude SSMS Display with Estimated Actual SQLCMD Parse Execution Execution Mode Plan PlanCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    71. 71. T-SQL Editor/Debugger/IntelliSense 71  Context menu consistency improvementCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    72. 72. Power-Buffer/Table Designer 72  Declarative deferred online schema management  Brings “project-oriented” features to online / connected development  Live errors and warnings as changes are made against code  “Project-oriented” validation during editing  Table designer  Code-behind designer  Works on top of Power-Buffer (partial model) or project model  Strives to be the same experience online as experienced in the project system  Coordinated execution of buffers against the same target  Diff scripts by default are transactional (ToolsOptionsSQL Server ToolsOnline EditingInclude transactional scripts)Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    73. 73. Data Editor 73  View and Edit Data via grid editor  Copy-Paste support  Generate as INSERT to file or query windowCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    74. 74. Execute Procedure/Function 74  Dialog based input for parameter collection  Generates SQL script for execution/debuggingCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    75. 75. Schema Compare 75  Performs a model comparison between:  Databases  Projects  DACPAC files (snapshots, build outputs, extracts)  Supports:  Refactoring log  SQLCMD variablesCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    76. 76. Schema Compare 76  Behavioral comparison options  Object type filtering  Applicationscoped  Non-application scopedCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    77. 77. Schema Compare 77 Next and Previous move between top- Simpler set of columns are aligned around the central level objects, no longer expand the tree. action column echoes alignment of schemas above Group-by Action is the Same default column order is used for all groupings; cleaner and Schema no longer easier to used as a parent for parse top-level objects; only regardless of shown when changed grouping Improved script diff’ algorithm for tables emphasizes columns as unit of change. Gives much improved alignment. Also improved lookCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    78. 78. Schema Compare 78Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    79. 79. 79 Project Based Development Offline and Isolated Schema Authoring and DeploymentCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    80. 80. Project Based Development 80  Database Projects  Database References  Publishing ProjectsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    81. 81. Database Projects 81  Creating and Importing  Additional Language Services  Isolated Sandbox  Database Schema Snapshots  Build Time Validation  T-SQL Static Code Analysis  SQL-CLR Support  Pre & Post Deployment ScriptsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    82. 82. Creating and Importing 82  Single project template  VSDB note:  No distinction between server or user projects  Server projects are projects with target database set to master  Import from:  Database  DACPAC  SQL Script (multi-file import enabled)  Selective import by using Schema Compare  “Create New Project” from SSOX  Inherits version from source databaseCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    83. 83. Project Files 83  *.sqlproj  MSBuild based project file  *.sqlproj.user  MSBuild based user specific settings (merged-in)  *.dbmdl  <project>.dbmdl is the schema model cache file  Will get rebuild when deleted  Should not get checked-in, in to source code control (SSC)  ESE (Extensible Storage Engine) database file  http://technet.microsoft.com/en-us/library/bb310772.aspx  Managed interface http://managedesent.codeplex.com/Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    84. 84. Folder Structure 84  Options on import:  None  Schema  Object type  SchemaObject typeCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    85. 85. Project Directory Guidelines 85  The projects directory root path is the only thing that matters!  This is determined based on the location of the .sqlproj file  You have to stay underneath this location  All file paths are relative to this location  The initial project structure is a good starting point and works for all objects  You can change the complete directory structure  But if you remove the default layout we do not know where the automatically place objects when using “Add New Item” or when using Import Script  Result: Objects will be placed in the project root location  Advice: Extend the base structure, do not replaceCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    86. 86. Project Directory Guidelines… 86  Be aware of MAX_PATH (260 characters)  All relative file locations must fit within MAX_PATH  Your SCC environment might have problems when you exceed MAX_PATH  Choose your project root location wisely  Filenames encoding:  objectname.sql or schema.objectname.sql  <sysname>.<sysname>.sql  sysname = max 128 charactersCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    87. 87. Project Directory Guidelines… 87  Be aware of empty directories when using Source Code Control  Placement of new objects when using Add New Item or when using Schema Compare end up in the project root when location is not present  Do not host more then one table inside script file  Table designer will not see additional tables inside scriptCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    88. 88. Include files 88  Include files  Add Existing Item As Link <Build Include="..Northwind2dboTablesCategories.sql"> <Link>Categories.sql</Link> </Build>  Use to share files between projects  VSDB note:  SQL Server Database Projects do not support partial projectsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    89. 89. Additional Language Services 89  Projects enable additional language services  Go To Definition  Find All References  Refactoring  Rename (sp_rename)  Move to Schema (ALTER SCHEMA schema_name TRANSFER)  Wildcard Expansion  Fully Quality Name  Invoked from Editor, Table Designer and SQL Server Object Explorer for project based schema objectsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    90. 90. Isolated Sandbox 90  F5 – Run by default configure to use the LocalDB instance associated with the project  Data Source=(localdb)<project name>;Initial Catalog=<project name>;Integrated Security=True;Pooling=False;Connect Timeout=30  To retarget to a different SQL Server version and/or shared SQL Server change:  Project propertiesDebugTarget Connection StringCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    91. 91. SQL Server 2012 Express LocalDB 91  Simplify embedded usage of SQL Server  Simple installation  Zero-admin database  Same programming surface as User Instances of SQL Express  The same sqlservr.exe as in service-based SQL Server with the same language and features  Connection through the same client-side APIs, using a new connection string option  SQL Server programming symmetry  Installation similar to .NET Framework model  One set of installed binaries (per major version), no global configuration, no constantly-running service  Activation model similar to RANU (Access, SQL Compact, …)  The application connects to a database file, SQL activates automatically  No service: SQL process starts in the context of current user  Default connection string  (localdb)v11.0  http://msdn.microsoft.com/en-us/library/hh510202(v=SQL.110).aspxCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    92. 92. LocalDB Setup 92  Packaged in a small single MSI  SqlLocalDB.msi x32 (27.5 MB)  SqlLocalDB.msi x64 (32.7 MB)  Single registry key to check if LocalDB Runtime is installed C: [HKLMSOFTWAREMicrosoftMicrosoft SQL Server Local Program Files DBInstalled Versions11.0] Microsoft SQL Server 110  Silent installation LocalDB sqlservr.exe SQLLocalDB.msi /Quiet /IAcceptLicenseTerms […] 120  Side-by-side versions LocalDB sqlservr.exe […]Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    93. 93. Each user has their LocalDB instance (process)  Created and started lazily when needed LocalDB Process Model All SQL Server process infrastructure is hidden  Including System Databases (master & friends) 93 Same Machine, Same User Context new SqlConnection( “Server=(LoacalDB)v11.0; AttachDBFile=|DataDirectory|App1DB.mdf“); App1 App1 DB User Code – Visible Infrastructure – Hidden temp model master C:Program Files C:UsersjohnsmithAppData Microsoft SQL Server msdb LocalMicrosoftMicrosoft SQL 110LocalDBBinnsqlservr.exe ServerLocalDBv11.0...Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    94. 94. Database Schema Snapshots 94  Point-in-time representation of schema model  Model must be “error-free” state  Produces same file format (*.dacpac) as build or extract  To be used for:  Versioning  Comparison  Sharing schema definitions or changes …Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    95. 95. Build Time Validation 95  Build validates the complete model  Platform specific validation  Example – Enforces clustered index requirement on tables in SQL Azure  Integration with Compiler Services  Engine-level build-time validation without schema deployment  Leverages CDB and SQL2012 engine capabilities  Pre & Post Deployment scripts  Build validates syntactical correctness of pre- and post- deployment scripts using the SQLCMD variables  Build serializes the model in to model.xml stream inside .dacpac fileCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    96. 96. Build Actions 96  Build - This script will be interpreted as T-SQL (or an XML Schema in the case of XML Schema Collections) and reflected in the T-SQL Model  Compile - C# or VB (depending on your project properties) to be deployed as a SQLCLR assembly  None - Use this for any loose artifacts (like text files)  PreDeploy - The pre deployment master script (there can only be one)  PostDeploy - The post deployment master script (there can only be one)  RefactorLog - This is a refactor log which notifies the DaxFx deployment engine that particular changes should be interpreted as refactoring operations and not drop/adds  Build Extension Configuration - Reserved for future use, for this is interpreted as NoneCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    97. 97. Build Output 97  Build output path  .sqldebug  .sqlrelease  Intermediate output path  .objdebug  .objreleaseCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    98. 98. T-SQL Static Code Analysis 98  Rule set  Suppression  Filelevel  Project level  MSBuild supportCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    99. 99. SQL-CLR Support 99  Supports:  Embedded C# or VB.NET code artifacts  Deployed as SQL-CLR objects  Binary assembly deployment and SQL-CLR object association  Example:  CREATE TYPE [ClrSchema].[IPv4] EXTERNAL NAME [IPAssembly].[IPv4];Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    100. 100. Pre & Post Deployment Scripts 100  Can be used for any “arbitrary” SQL actions that you need to perform “before” and “after” deployment of the schema objects  The pre deployment block comes after the generic database context validation block  The post deployment block comes after the schema objects block  Pre and post deployment scripts must be idempotent  They are “executed” each deployment!  http://blogs.msdn.com/gertd/archive/2007/01/25/idempotent- scripts-required.aspxCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    101. 101. Pre & Post Deployment Scripts… 101  The pre or post deployment master files are identified in the .sqlproj file through special item type tags  <PreDeploy Include="ScriptsPre- DeploymentScript.PreDeployment.sql"> <SubType>Code</SubType> </PreDeploy> <PostDeploy Include="ScriptsPost- DeploymentScript.PostDeployment.sql"> <SubType>Code</SubType> </PostDeploy>Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    102. 102. Pre & Post Deployment Scripts… 102  Include files using :r (SQLCMD include)  File paths of includes are relative to the pre or post deployment master file  Included files must exist, even when empty  Not existing include fail will cause an error state at build time  Include files have to be tagged “NotInBuild”  <NotInBuild Include="ScriptsPost- DeploymentDatabaseObjectOptions.sql"> <SubType>NotInBuild</SubType> </NotInBuild>Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    103. 103. SQLCMD Variables 103  Restrictions  Substitution order (vs. sqlcmd.exe)  MSBuild mapping  SQLCMD variables can be used in:  Pre & post deployment scripts  Within schema objects variable have to be placed between square brackets or double or single quotes  [$(var)] or “$(var)” or „$(var)‟  !!!Cannot be used as object identifiers!!!  Variables are defined and store in ???  Configuration dependent ???Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    104. 104. Database References 104  master and msdb references  3-4 part names  CompositionCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    105. 105. Database References 105  Literal vs. variable references  Literal can be used for 2 and 3-part names only  Self vs. 3- vs. 4-part name  Same database  Different database, same server  Different database, different server  Build order and circular referencesCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    106. 106. Database References 106  File based references (*.dacpac)  Create directory underneath the project root to store dacpac files, to ensure it is a relative path and transports correctly with the project in source code control  Example: Reference*.dacpac  Make sure to point to a v3.0 .dacpacCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    107. 107. master and msdb references 107  master references can be explicit or implicit  master.dbo.<object> or master.sys.<object>  <Annotation Type="AliasedToDbo" />  Global namespace  <Annotation Type="GloballyScoped" />  Example:  select * from master.dbo.sysprocesses select * from master.sys.sysprocesses select * from sysprocesses  msdb references are always explicit 3-part references  Example:  select job_id from msdb.dbo.sysjobsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    108. 108. 3- & 4-part Names 108  3-part name usage:  SELECT * FROM [LiteralDBRef].[Schema1].[Table1]  SELECT * FROM [$(DBRef)].[Schema1].[Table1]  4-part name usage:  SELECT * FROM [$(ServerRef)].[$(DBRef)].[Schema1].[Table1]  SELECT * FROM [$(ServerRef)].[LiteralDBRef].[Schema1].[Table1]Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    109. 109. Composition 109  Composite Projects  Schema distributed across multiple database projects  Enable division of schema along security or organizational boundaries  Published as “one” logical database  Referenced objects brought into parent model on build  Controlled by “Include Composite Objects” advanced publish option  Removes the need for separate deployment of composing projectsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    110. 110. Publishing Projects 110  Multi-targeting  Deployment OptionsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    111. 111. Multi-Targeting 111  Target version aware:  SQL Server 2005  SQL Server 2008 & SQL Server 2008 R2  SQL Server 2012  SQL Azure  Publish  Direct, via SQL script, or DACPAC snapshotsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    112. 112. Publishing Profiles 112 MSBuild fragment for sharing deployment  settings <?xml version="1.0" encoding="utf-8"?> <Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <IncludeCompositeObjects>True</IncludeCompositeObjects> <TargetDatabaseName>DinnerNow</TargetDatabaseName> <DeployScriptFileName>TestSqlProj.sql</DeployScriptFileName> <TargetConnectionString>Data Source=gmf4vyn24r.database.windows.net; User ID=gertd@gmf4vyn24r;Pooling=False</TargetConnectionString> <ProfileVersionNumber>1</ProfileVersionNumber> </PropertyGroup> </Project>Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    113. 113. Deployment Options 113  Options to influence deployment behavior  Ignore*  Deployment validation options  Do not alter Change Data Capture objects  Do not ALTER replicated objects  Verify deployment  Deploy without a safety-netCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    114. 114. 114 Application Life Cycle Integration Team development and central build servicesCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    115. 115. Application Life Cycle Integration 115  MSBuild Support  Source Code Control Integration  Build Server IntegrationCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    116. 116. MSBuild Support 116  MSBuild tasks for:  Build  Publish  Note: requires using a publishing profile  T-SQL Static Code Analysis  SSDTBuildUtilities.msi  Redist for MSBuild specific components  http://sqlproj.com/index.php/2012/03/headless-msbuild- support-for-ssdt-sqlproj-projects/Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    117. 117. Source Code Control Support 117  SQL Server Data Tools works with all Visual Studio Source Code Control (SCC) providers  SQL Server Database Projects fully integrate with SCC, no need to do anything specialCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    118. 118. Build Server Integration 118  Building  Use MSBuild  Deploying/publishing  Use MSBuild (requires publish profile)  Use SqlPackage.exe  Suggestion: use answer file, override from command lineCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    119. 119. Programmatic and Command 119 LineCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    120. 120. SqlPackage.exe 120  Part of DACFramework.msi (redist)  Location:  %ProgramFiles(x86)%Microsoft SQL Server110DACbin  /Action:  {Extract|DeployReport|DriftReport|Publish|Script}  Supports response file @file  Command line override settings in response fileCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    121. 121. DacUnpack.exe 121  C:Program Files (x86)Microsoft SQL Server110DACbin  Explorer file handler for unpacking .DACPAC  Note: not a command line toolsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    122. 122. MSBuild Tasks 122  MSBuild /t:Build | Publish | StaticCodeAnalysis  Target file  C:Program Files (x86)MSBuildMicrosoftVisualStudiov10.0SSDT Microsoft.Data.Tools.Schema.SqlTasks.targetsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    123. 123. MSBuild 123  msbuild /t:build sqlproj-nw.sqlproj  msbuild /t:publish sqlproj-nw.sqlproj /p:SqlPublishProfilePath=sqlproj- nw.publish.xml  msbuild /t:StaticCodeAnalysis sqlproj- nw.sqlprojCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    124. 124. MSBuild Target Definitions 124  PreBuildEvent  BeforePublish  BeforeBuild  PrePublishEvent  AfterBuild  PostPublishEvent  PostBuildEvent  AfterPublish <Target Name="BeforeBuild"> <Target Name="BeforePublish"> <Message Text="BeforeBuild message" /> <Message Text="BeforePublish message" / </Target> > <Target Name="AfterBuild"> </Target> <Message Text="AfterBuild message" /> <Target Name="AfterPublish"> </Target> <Message Text="AfterPublish message" />Copyright © 2012 Gert Drapers - All Rights Reserved. </Target> 03/29/2012
    125. 125. Microsoft.SqlServer.Dac.dll 125  Public API  Implements the common DAC verbs  Deploy, ExportBacpac, Extract, GenerateCreateS cript, GenerateDeployReport, GenerateDeployScr ipt, GeneratedriftReport, ImportBacpac, Register, Unregister, Unpack  C:Program Files (x86)Microsoft SQL erver110DACbinMicrosoft.SqlServer.Dac.dllCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    126. 126. 126 SummaryCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    127. 127. SQL Server Data Tools – Summary127  Developer-focused toolset to author, debug and publish SQL Server & SQL Azure databases  Supports SQL Platform  Free, web updates for SQL Server and SQL Azure releases  Works in concert with other SQL Server tooling (SAMP, SSMS)  Compatible with your development environment  Supports Visual Studio 2010 & Visual Studio 11  Migrates VS2010 database projectsCopyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012
    128. 128. Widescreen Test Pattern (16:9) Aspect Ratio Test (Should appear circular) 4x3 16x9Copyright © 2012 Gert Drapers - All Rights Reserved. 03/29/2012

    ×