SSDT and Database Project Basics SQL Server Data Tools 2016 SSDT and Database Project Basics
Content Map Introduction Visual Studio Tooling Database Projects Useful SSDT Tools Advanced Concepts
Introduction Steve Grier - Associate Architect with Computer Enterprise, Inc. (CEI) www.ceiamerica.com Microsoft P-Seller; Partner Technical Specialist 10+ years experience working with SQL Server 10+ years working as a .NET software developer 6 years working as a windows system administrator
SSDT Overview Manage Development Built on Visual Studio SSAS Cubes & Tables SSRS Reports SSIS Packages Database Schema Built on Visual Studio Complete IDE Functionality
SSDT Project Types Analysis Services Projects Database Project Integration Services Project Report Project
Fun Stuff First! DEMO Extract Modify Build Publish
Visual Studio Tooling
Visual Studio Development Project and File based Approach Solution – Collection of Projects Project(s) – Collection of Files Folder(s) – Used for organization File(s) – Object definitions
Solutions Define Projects, Files, Build Configurations and Build Dependencies Plain Text formatting Created by default
Projects Collection of Source Code and Reference Files Unit of Build and Deployment Defines organizational structure of Files Holds Build, Debug, Package and Deployment Configuration XML formatting Build – Checks Syntax; Checks Model Integrity; Packages everything for deployment
Database Projects
Database Project Collection of SQL objects Builds a DACPAC for Deployment Deployment-time Script Support Refactor Support
Project Structure Default organization is: Schema\Object_Type\ObjectName Individual Files can be included/excluded from the Build Project properties Project references
Project Files Declarative Statements (Create not Alter) T-SQL Syntax Content and Properties Content in File Properties in Project Best Practice One object per File
Project Properties Project and Database level settings Target Platform (SQL Server version)
Database Settings sp_configure options Recovery options Collation Compatibility Other Database- level settings/defaults
File Properties View from Properties Window (View-Properties Window [F4]) Bold properties stored in project file Build Actions Build – include as SQL object None – do not compile PreDeploy – run script before deployment PostDeploy – run script after deployment RefactorLog – list of rename actions
Useful SSDT Tools
Schema Compare SQL Compare Examine the structure of source and target database definitions Can compare Database Projects, Dacpacs or SQL Server Databases Differences are listed with changes highlighted Targets can be updated directly from SQL Compare
Data Compare Data Compare Examine the data in a source and target database Objects with matching table names and primary keys can be examined Targets can be updated to add/modify/remove records Foreign Keys are dropped/recreated during updates
Advanced Concepts
Pre and Post Deploy Scripts One Pre Deploy and One Post Deploy script Reference other script files SQLCMD format Runs as part of the deployment process Built at Compile Time, not Deployment Time (target unspecific)
Pre and Post Deploy Patterns Idempotent Scripts Check then Execute Echo actions using PRINT statements Create a migrations table to track migration scripts Avoid environment specific actions where possible
Database References Useful to split a database up into multiple sub-projects Allows inheriting sections of a database definition in multiple projects Use to enable cross-database querying in database project objects Avoid where possible because of added complexity
Source Control ! Must Use Licensed Version Of Visual Studio ! Version Changes to Projects and Files Branch and Merge to maintain concurrent development Keep a released branch for patch development and bug fixes Keep a development branch for new features Move/Sync changes between the two branches Manage and Prioritize changes with a Product Backlog Link object changes to Backlog Items and Tasks
Continuous Integration & Continuous Deployment Automate build and release with tools like Visual Studio Team Services (VSTS) or Team Foundation Server (TFS) Constantly build and release changes to detect issues as soon as possible in the development projects Greatly increase consistency and deployment reliability
Questions?
Thank You! Steve Grier sgrier@ceiamerica.com