Generate source code and installation script
Another important feature of Visual Studio. NET is that it can generate a complete script for an existing database. In fact, you can use Visual Studio. NET generates source code for the entire database layer (including generating tables and indexes, authorization, and stored procedures ), you can also generate a command line script that can be used to install these database objects on an existing SQL Server.
It is easy to generate the installation script, which involves two steps: first, you need to generate a T-SQL script to create database objects (tables, indexes, procedures, etc ). A command line script that executes the T-SQL script against the target SQL Server is then generated.
Generate T-SQL script
Before generating the installation script, you need to generate a script set, including creating all the objects (tables, indexes, constraints, users, etc.) in the database ).
Figure 11: generate a script set
Follow these steps to generate a T-SQL script:
In Server Explorer (Server resource manager), right-click the selected database node (DotNetKB), and select Generate Create Script from the context menu... (generate the creation script ...), open the Generate Create Scripts dialog box.
On the General tab, select the Script all objects (write all object scripts) check box.
On the Formatting tab, select all check boxes except the last one (only compatible with version 7.0 scripts ). The last item is required only when your target Server is SQL Server 7.0 instead of SQL Server 2000.
On the Options tab, in the Security Scripting Options section, select all Options except Script SQL Server logins (write SQL Server login Script. Make sure that all check boxes in the Table Scripting Options section are selected. Retain the default single button for both File Format and Files to Generate. Finally, when all the settings are set correctly, click OK to start the script generation process.
The system prompts you to specify the file location. By default, Visual Studio. NET directs to the Create Scripts (Create script) folder in the existing database project. Click OK to accept the default location.