![]() |
|
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||
Published: Wednesday, July 13, 2005 By Scott Mitchell
In Part 1 we examined how to add a new Database project to an existing Visual Studio .NET Solution. In this second and final part we'll look at how to take the objects from an existing SQL Server database and quickly add them to the Database project within the Visual Studio .NET IDE.
Quickly Adding the Database Objects from SQL Server to the Database Project Launch SQL Enterprise Manager and right-click on the database whose objects you want to import to the Database project created in Part 1 of this article. From the context-menu, choose All Tasks --> Generate SQL Script. This will display the Generate SQL Scripts dialog box (see the screenshot below). Click on the Show All button to list all of the database objects in the database. Next, move those objects you want scripted over to the 'Objects to be scripted' list by selecting those objects and clicking the Add >> button, or by checking the appropriate 'Objects to script' checkboxes.
Before generating the script, be certain to go to the Options tab and, under the Files to Generate section, opt to 'Create one file per object.' This will create a separate file for each object being scripted; the default option, 'Create one file,' will instead create just one file that contains the script for all of the objects. If you are scripting tables, you may also want to check the checkboxes in the Table Scripting Options section. If you have any special permissions for the various objects you might also want to check the 'Script object-level permissions' option as well.
Finally, click the OK button to generate the SQL script. This will create one file for each object selected from the General tab. The final step, then, is to import these script files into the Database project. To do that, return to Visual Studio .NET, right-click on the Database project folder you want the object to reside and choose to Add Existing Item. Then browse to the directory where you saved the scripted objects and add the appropriate script files. When you need to create new database objects you have the option of either creating a new file in the Database project and writing the necessary T-SQL or creating the object through SQL Enterprise Manager and then importing it into the Visual Studio .NET Database project through the techniques discussed above. Personally I find myself creating tables and jobs through SQL Enterprise Manager, but Views, UDFs, and stored procedures through the Database project directly.
Using the Database Project
Conclusion I learned about Database projects nearly two years ago and have been using them ever since. Now I don't know how I'd survive without them! If you've yet to explore Visual Studio .NET's Database projects, I heartily encourage you to check them out and give them a whirl. Happy Programming!
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
![]() |
![]() |
|||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||