In SSMS, right-click on the database name and choose Tasks | Generate Scripts. Rather than hand-type my INSERT statements, I use SQL Server Management Studio (hereafter, SSMS) and let it do the lifting for me. For instance, here I have added a file that will insert all of the States into my State table after the database is deployed. You can simply right-click on the Post-Deployment folder and choose Add | Script. Instead, I like to create separate files for each table for which I want to INSERT data. You could place all of your post deployment INSERT statements into this file directly, but that can get ugly quickly. The scripts that are created here can contain any valid SQL. This script is run automatically after the database is deployed by the Database project. If you open the Post-Deployment folder, you’ll note a file called. As we are interested in inserting data into tables, we obviously need to insert code in the Post-Deployment step when the tables actually exist. If you take a look in the Database project, you’ll see a folder called Scripts and under Scripts there are folders for both Pre-Deployment and Post-Deployment. To follow along with this post, you can simply add a new project in Visual Studio and choose the Database | SQL Server project type and select the SQL Server 2008 Database Project. There is plenty of decent material available on doing that. This post specifically addresses including and deploying data and is not intended as a general overview of Database projects. However, there is a way to tap into the scripts that Visual Studio creates when it creates a new Database Project. To my knowledge, there’s not really an automated way in Visual Studio to tell the Database Project that you want to bring the data into the project and have it be part of your deployment. Most any reasonably-sized application will have lookup lists and other data that need to be there for the application to function properly. For developers that need to get up and running locally, the joy of simply right-clicking and choosing “Deploy” is hard to beat. It gives me a nice warm feeling to see that the database schema and even necessary seed data is maintained in source control in the solution right along with the other projects. If you are not familiar with using the Database Project, I encourage you to give it a look. I’m a big fan of Visual Studio’s Database Project and I’ve used them successfully in several client projects.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |