SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for ASP.Net, SQL Server, Reporting Services, T-SQL, Windows, AWS, SAP HANA and ABAP


Create SQL Server Database Object Script using Visual Studio 2015

Visual Studio SQL Server Database Project enables to generate database object scripts as an alternative to SQL Server Management Studio built-in tools to generate scripts of database objects including database tables, views, procedures, etc for database administrator and T-SQL developers. As a developer if you do not have SQL Server Management Studio installed, but working on Microsoft Visual Studio 2015 for example, using the Database project template it is possible to connect to an existing database and generate scripts of the database objects as illustrated in this SQL Server tutorial.

If you have SSMS running and connecting to a source database on a SQL Server instance, you can refer to SQL Server tutorials shared with you at the end of this guide. Instead of working with Visual Studio SQL Server Database Project on VS2015, you can use SQL Server Management Studio 2014 for example.

Launch Visual Studio 2015.
If you don't have Visual Studio 2015 installed on your PC, you can download Visual Studio 2015 and try free after you install trial edition.

Create new database project following menu options:
File > New > Project...

new Visual Studio Project for SQL Server 2014

Choose "SQL Server Database Project" template among installed Visual Studio project templates. You can find it at full path "Installed > Templates > SQL Server > SQL Server Database Project" in Visual Studio 2015 new project wizard.

Set project name and location. Before you proceed with next step, check other configuration settings. Then press OK button.

SQL Server Database Project template in Visual Studio

After SQL Server database project is created successfully, database administrators or SQL developers can create SQL Server database objects' scripts like all database table scripts, etc using Visual Studio Import Database wizard. There are two ways to launch the import database tool in Visual Studio 2015.

First option is using Visual Studio 2015 main menu: Project > Import > Database...

Import Database within SQL Server Database Project in Visual Studio 2015

Or second option is displaying the Import wizard within Solution Explorer window. Right click on the project node in Solution Explorer window and display context menu.
Choose Import > Database

import database in Visual Studio Solution Explorer window

Here is the initial screen of the Visual Studio 2015 Import Database tool for SQL Server Database Project templates to import database objects which can also be used to create SQL scripts for database objects like all tables, schema objects, stored procedures, logins, etc by SQL Server database administrator and T-SQL programmers.

Import Database tool in Visual Studio SQL Server Database Project

First of all, choose your database connection as the source database connection. If you have not yet defined a database connection, you can use "New Connection..." button to create a new SQL Server database connection and test it if it is successfully reachable.

Second, configure import settings for database objects. If you are not sure, and if you only want to generate Create scipts of database tables for example, clear all checkboxes. You can leave the target folder structure as "Schema\Object Type" or choose "Object Type" for simplicity. Then press the Start button to let Visual Studio generate database script for you.

Visual Studio generates database script for SQL Server developers

Before pressing Finish button to include the generated create script files for all database objects, let's check the log to see what has Visual Studio 2015 done for administrator and developers.

06.07.2015 10:28:59 Import of database schema has started.
06.07.2015 10:29:02 Gathering database options
06.07.2015 10:29:02 Gathering users
06.07.2015 10:29:02 Gathering roles
06.07.2015 10:29:02 Gathering application roles
06.07.2015 10:29:02 Gathering role memberships
06.07.2015 10:29:02 Gathering filegroups
06.07.2015 10:29:02 Gathering files
06.07.2015 10:29:02 Gathering full-text catalogs
06.07.2015 10:29:02 Gathering assemblies
06.07.2015 10:29:02 Gathering certificates
06.07.2015 10:29:02 Gathering asymmetric keys
06.07.2015 10:29:02 Gathering symmetric keys
06.07.2015 10:29:02 Gathering encrypted symmetric keys
06.07.2015 10:29:02 Gathering database encryption keys
06.07.2015 10:29:02 Gathering schemas
06.07.2015 10:29:02 Gathering XML schema collections
06.07.2015 10:29:02 Gathering user-defined data types
06.07.2015 10:29:02 Gathering user-defined types
06.07.2015 10:29:02 Gathering table types
06.07.2015 10:29:02 Gathering unique keys for table types
06.07.2015 10:29:02 Gathering primary keys for table types
06.07.2015 10:29:02 Gathering indexes for table types
06.07.2015 10:29:02 Gathering check constraints for table types
06.07.2015 10:29:02 Gathering default constraints for table types
06.07.2015 10:29:02 Gathering partition functions
06.07.2015 10:29:02 Gathering partition schemes
06.07.2015 10:29:02 Gathering functions
06.07.2015 10:29:02 Gathering encrypted functions
06.07.2015 10:29:02 Gathering aggregates
06.07.2015 10:29:02 Gathering procedures
06.07.2015 10:29:02 Gathering encrypted procedures
06.07.2015 10:29:02 Gathering tables
06.07.2015 10:29:02 Gathering primary keys
06.07.2015 10:29:02 Gathering unique constraints
06.07.2015 10:29:02 Gathering foreign keys
06.07.2015 10:29:02 Gathering default constraints
06.07.2015 10:29:02 Gathering check constraints
06.07.2015 10:29:02 Gathering views
06.07.2015 10:29:02 Gathering encrypted views
06.07.2015 10:29:02 Gathering indexes
06.07.2015 10:29:02 Gathering statistics
06.07.2015 10:29:02 Gathering full-text index stoplists
06.07.2015 10:29:02 Gathering search property lists
06.07.2015 10:29:02 Gathering search properties
06.07.2015 10:29:02 Gathering full-text indexes
06.07.2015 10:29:02 Gathering column store indexes
06.07.2015 10:29:02 Gathering spatial indexes
06.07.2015 10:29:02 Gathering XML indexes
06.07.2015 10:29:02 Gathering Selective XML indexes
06.07.2015 10:29:02 Gathering encrypted triggers
06.07.2015 10:29:02 Gathering triggers
06.07.2015 10:29:02 Gathering encrypted and clr ddl triggers
06.07.2015 10:29:02 Gathering ddl triggers
06.07.2015 10:29:02 Gathering synonyms
06.07.2015 10:29:02 Gathering defaults
06.07.2015 10:29:02 Gathering data constraint uddt bindings
06.07.2015 10:29:02 Gathering rules
06.07.2015 10:29:02 Gathering data constraint uddt bindings
06.07.2015 10:29:02 Gathering message types
06.07.2015 10:29:02 Gathering queues
06.07.2015 10:29:02 Gathering contracts
06.07.2015 10:29:02 Gathering services
06.07.2015 10:29:02 Gathering routes
06.07.2015 10:29:02 Gathering event notifications
06.07.2015 10:29:02 Gathering remote service bindings
06.07.2015 10:29:02 Gathering broker priorities
06.07.2015 10:29:02 Gathering database audit specifications
06.07.2015 10:29:02 Gathering signatures
06.07.2015 10:29:02 Gathering data compression options
06.07.2015 10:29:02 Gathering sequence types
06.07.2015 10:29:02 Gathering extended properties
06.07.2015 10:29:02 Scanning project for duplicate elements
06.07.2015 10:29:02 Finished duplicate element processing
06.07.2015 10:29:03 Finished importing database.
06.07.2015 10:29:03 A summary of the import was saved to the following location: C:\DevProjects\SQL\kodyazScript\kodyazScript\Import Schema Logs\kodyazScript_20150706072859.log
06.07.2015 10:29:03 Click Finish to continue...

As you see, if you are dealing with generating Create scripts for database tables, it is only a small portion of what has the Import Database tool done for you.

When you press Finish button, generated script files in .sql format will be displayed in Solution Explorer.

database object scripts generated by Visual Studio Import Database tool

Database table generate scripts are listed under Tables node just like user defined functions under Functions node, stored procedures under Stored Procedures and user views are under Views folder.

If you right-click on a table script file, and choose View Code option from context menu, SQL Create script will be displayed in main window as follows. Index creation scripts are also included in the same SQL code file.

SQL Server database object script code in Visual Studio

If as a database developer you have already download and install SQL Server Management Studio, or if you are a database administator you can try using SSMS built-in tools to generate scripts.
1) How to Script MS SQL Server 2008 Database using SQL Server Script Wizard
2) Script Data in MS SQL Server 2008 Database Tables using Generate SQL Server Script Wizard
3) How to Script Data in MS SQL Server 2012 using Generate and Publish Scripts Wizard
4) SQL Server BCP Utility with sp_HelpText to Generate Script File for Each Stored Procedure in a Database
5) Create SQL Server Database Object Script using Visual Studio 2015



SQL Server

SQL Server 2019 Installation
download SQL Server 2019
download SQL Server 2017
download SQL Server 2016
download SQL Server 2014
download SQL Server 2012
MacOS ve SQL Server 2019


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.