Develop your Database using
“Database Projects” from SQL
Server Data Tools (SSDT)
Prepared for SQL Saturday #441
September 2015
Sep-15 1
Agenda
• Slides - 25 minutes
– What is SSDT and declarative development
– Local DB
– Creating a database project
– Project Properties
– Database References
– Pre and Post Deployment Scripts
– Build, Debug, and Publish
– Refactoring
– Lifecycle Management
• Demo - 25 minutes
• Q&A - 5 minutes
Sep-15 2
About Me…Andy Vold
• Architect with RevGen Partners
• Work primarily in business intelligence, SSIS/ETL,
and database development.
• Telemark Skier and Mountain Biker
• Twitter: @volda2000
• Email: avold@[Link]
Sep-15 3
What is SSDT?
• SQL Server Data Tools (SSDT) transforms
database development by introducing a ubiquitous,
declarative model that spans all the phases of
database development inside Visual Studio.
• You can use SSDT Transact-SQL design
capabilities to build, debug, maintain, and refactor
databases.
• You can work with a database project, or directly
with a connected database instance on or off-
premise.
Sep-15 4
Versions of SSDT
• SSDT is not the same as SSDT-BI
• SSDT is free
• SSDT can be installed standalone or can be integrated into
an existing Visual Studio installation. For the preview
release, SSDT is supported with Visual Studio 2015 and
Visual Studio 2013. If you already have the Professional or
higher edition of Visual Studio 2015 or Visual Studio 2013
and did not opt out of installing SQL Server Data Tools
during setup, then your machine has an existing installation
of SSDT.
• [Link]
Sep-15 5
Versions of SSDT
Sep-15 6
Declarative Development
• In computer science, declarative programming is a
programming paradigm, a style of building the
structure and elements of computer programs, that
expresses the logic of a computation without
describing its control flow
• Define what you want, not how you get there
Sep-15 7
Declarative Development with SSDT
• No more manual change scripts
• Model is built on source controlled scripts
– Enables offline development
– Allows model to be in an inconsistent or incomplete
state
– Broken dependencies will be immediately flagged by
the complier
– Rules can be optionally enforced over the model
Sep-15 8
Declarative Development – Build Type Property
• Build
• Build Extension Configuration (2013 +)
• Compile
• Deployment Extension Configuration (2013 +)
• None
• Post Deploy (only one per project)
• PreDeploy (only one per project)
• RefactorLog
Sep-15 9
Declarative Development - Object Type
Sep-15 10
What is Local DB?
LocalDB is a version of SQL Server
Express created specifically for
developers. LocalDB is a fast,
lightweight SQL Server instance that
requires minimal management or
configuration. SSDT installs and uses
LocalDB as a debug database to
provide a sandboxed environment for
building, testing, and debugging your
project.
Sep-15 11
Local DB
As a default, SSDT
also sets your
database project to
target LocalDB
during debugging.
This means that
without any
configuration, F5 is
already wired to
build your
database project
and deploy it to
LocalDB .
Sep-15 12
Creating a SSDT Database Project
• Two Options
– Import existing
– Create new
Sep-15 13
Project Settings
• Default schema
• Database settings
• Deployment server and deployment options
• Errors & Warnings
Sep-15 14
Database References
• Three types of database references
– System DB’s
– Project
‒ Same VS Solution
‒ No circular references
– Dacpac
Sep-15 15
Pre & Post Deployment Scripts
• Supports changes outside of schema changes
• Can be used to remove data or add data
• Files are interpreted as SQLCMD scripts by SSDT. You
can use most valid SQLCMD syntax within the script
• You are allowed only one Pre and one Post deployment
script in a project
Sep-15 16
Build, Debug, and Publish
• BUILD
– Verifies all references resolve
– Verifies no syntax errors
– Builds a dacpac
Sep-15 17
Build, Debug, and Publish
• DEBUG
– Deploys the pre deployment, schema, and post
deployment to the database configured in the properties
Sep-15 18
Build, Debug, and Publish
• PUBLISH
– Deploys the pre deployment, schema, and post
deployment to the database of choice
– Can either generate a script or push change
Sep-15 19
Refactor
• Rename (column or object)
• Move to Schema
• Expand Wildcards
• Fully-qualify Names
Sep-15 20
Refactor
Sep-15 21
Lifecycle Management
• Put Database in Version Control
• Use Branching
• Use Schema compares to generate migration scripts
– Project vs. Development
– Development vs. UAT
– UAT vs. Production
Sep-15 22
Lifecycle Management – Schema Compare
Sep-15 23
Sep-15 24
Thank you to all of our Sponsors!
Diamond Sponsors
Platinum Sponsors
Gold Sponsors
Marquee Sponsors
25 | 9/19/2015 SQLSaturday #441 – Denver 2015
Thank you to all of our Sponsors!
Silver Sponsors
SWAG Sponsors
26 | 9/19/2514 SQLSaturday #441 – Denver 2015