database projects in visual studio 2010 anthony brown [email protected]

24
Database projects in visual studio 2010 Anthony Brown [email protected] http://www.sqlblogcasts.com/blogs/ antxxxx

Upload: kelly-williamson

Post on 17-Jan-2016

229 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Database projects in visual studio 2010

Anthony [email protected]

http://www.sqlblogcasts.com/blogs/antxxxx

Page 2: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Agenda

• What are they?• How they work• What else you can do• Limitations

Page 3: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

What are they for

• Offline development of database objects• Manage database objects in source control• Validation at design time, not deploy• Allow easy creation of databases in a

consistent state

Page 4: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Version comparison

Feature Visual Studio 2010 Professional Visual Studio 2010 Premium and Ultimate

Schema Compare ü

Data Compare ü

Database Unit Tests Execute Only ü

Transact-SQL Refactoring Execute Only ü

Transact-SQL Static Code Analysis Execute Only ü

Data Generation Execute Only ü

Team Foundation Server Build Integration ü ü

Command line deploy (VSDBCMD) ü ü

Page 5: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Before database projects

• Created a change script which was run against all environments

• Had to maintain change script for each change and run in specific order

• Had to know state of target server to work out which scripts to run, or create complex scripts

Page 6: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Before database projectsif not exists (select null from sys.tables where name = 'ErrorLog' and schema_id = schema_id('dbo'))begin

CREATE TABLE [dbo].[ErrorLog] ([ErrorLogID] INT IDENTITY (1, 1) NOT NULL,[ErrorTime] DATETIME NOT NULL,[UserName] [sysname] NOT NULL,[ErrorNumber] INT NOT NULL,[ErrorSeverity] INT NULL,[ErrorState] INT NULL,[ErrorProcedure] NVARCHAR (126) NULL,[ErrorLine] INT NULL,[ErrorMessage] NVARCHAR (4000) NOT NULL

);endgoif not exists (select null from sys.columns where name = 'newcolumn' and OBJECT_NAME(object_id) = 'ErrorLog')begin

alter table ErrorLogadd newcolumn int null

end

Page 7: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

With database projects

• Change script generated at deploy time based on compiled project and state of target database

• Do not need to know state of target database before deploy

Page 8: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

With database projects

THE PROJECT IS THE TRUTH

Page 9: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Structure

• All database objects are stored in a project• All objects are defined fully • Server projects for server level objects (logins,

endpoints etc)• Database projects for database level objects

(tables, stored procedures, users etc)

Page 10: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Import schema

• Can import whole database only into blank project

• Can import script into existing database project

Page 11: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

demos

Page 12: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Build

• Validates all objects• Doesn’t need a database connection• Creates compiled dbschema file

Page 13: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Schema compare

• Gui method of comparing project and target server

• Not available in professional

Page 14: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Deploy

• Used to generate sql file that will make the target database the same as the project

• Optionally runs the sql file against the target database

• Can be run from– Visual studio– Msbuild/team build– Vsdbcmd– API

Page 15: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Deploy

Schema model

Schema model

Compare

Sql file

Dbschema file

Deployment options Database deployment

Database project Database

Page 16: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

demo

Page 17: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Permissions

• Managed in an xml file• Validated to ensure object and user/role exists

in project• Might need to define login for user in server

project• Not very user friendly • Can import from a script

Page 18: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Demo

Page 19: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

What else they can do

• References (dbschema, xsd, clr)• Static code analysis• Database unit tests & data generation

(execute only in professional)• Refactor (execute only in professional)• Extensibility

Page 20: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

New in 2010

• Code snippets• Intellisense• Integrated debugger• Extensibility

Page 21: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Not supported - 1

• Sql agent jobs• Replication• Replicated tables schema modification (can

workaround by setting VerifyDeployment=false)

• For replication on stored procedures

Page 22: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Not supported - 2

• Change data capture (change tracking supported in 2010)

• Reference data• Circular cross database references

Page 23: Database projects in visual studio 2010 Anthony Brown anthony@found-it.net

Not supported - 3

• Session/global temporary table• With check/with no check on constraints• Non sql server linked servers• Create resource pool• Create workload group• Create full text stoplist• Reporting services• Integration services• Analysis services• Table – lock escalation• Index options – maxdop, drop_existing, sort_in_tempdb