Pages

Tuesday, September 15, 2015

Working with SQL Server 2012 Script files and Projects

 SQL Server 2012 Script files and Projects :-

SSMS allows you to create and save T-SQL code in text files, typically given a .sql file extension. Like other Windows applications that open, edit, and save files, SSMS provides access to file management through the File menu and through standard toolbar buttons.
In addition to directly manipulating individual script files, SSMS provides a mechanism for initially saving groups of files together and for opening, saving, and closing them together. This mechanism uses several conceptual layers to work with T-SQL script files and related documents, and uses the Solution Explorer pane to display and control them:

Differences of  SQL Server 2012 Solution,Project and Script :-

Object
Parent
Description
Solution
None
Top-level container for projects. Stored as a text file with an .ssmssln extension, which references components contained within it. 
May contain multiple projects. 
Displayed in Solution Explorer at the top of the object hierarchy.

Project
Solution
Container for T-SQL scripts (called queries), stored database connection metadata, and miscellaneous files.
 Stored as a text file with an ssmssqlproj extension, which references component scripts and other files.

Script
Project
T-SQL script  file with a .sql extension. The core item of work in SSMS.



The benefits to using SQL Server 2012 scripts organized in projects and solutions include the ability to open multiple script files in SSMS at once. You can open the solution or project file from within SSMS or Windows Explorer.

How to Create SQL Server 2012 Solution :-

To create new solution, click the File menu and click New Project. (There is no “New Solution” command.) 

Hellotsql.blogspot.in






















Specify a name for the initial project, its parent solution, and whether you want the project to be
stored in a subfolder below the solution file in the location you indicate. Click OK to create the objects.


Hellotsql.blogspot.in

























To interact with Solution Explorer, open the pane (if necessary) from the View menu. To create a
new script that will be stored as part of the project, right-click the Queries folder in the project and click New Query.


Hellotsql.blogspot.in





















Using the New Query toolbar button or the new query commands on the File menu

This will create a new script temporarily stored with the solution in the Miscellaneous Files folder.


Hellotsql.blogspot.in

















If you wish to move an existing open query document into a solution currently open in
Solution Explorer, you will need to save the file. Then you can drag the query into the
project tree to save it in the Queries folder. This will make a copy of the script file and place
it into the solution.


Shortcut Key to Save SQL Server 2012 Query : Ctrl + S


Hellotsql.blogspot.in





HelloTsql.blogspot.in






















Differences between Save and Save All in SQL Server 2012

It is important to remember to save the solution when exiting SSMS or opening another solution in order to preserve changes to the solution's file inventory.Saving a script using the Save toolbar button or the Save <Queryname>.sql command on the File menu will only save changes to the contents of the current script file. To save the entire solution and all its files, use the Save All command on the File menu or when prompted to save the .ssmssln and .ssmssqlproj files on exit.

No comments:

Post a Comment