Dindar
Dindar

Reputation: 3245

saving code snippets in sql server

There are a lot of code snippets in the internet at articles or Question and answer communities like stackoverflow which worth save them and refer to them whenever we need them. Memorizing all of them is so hard , so I'm wondering if SQL Server has such capability in order to save those code snippets on it ?

If it doesn't , How about other solution you may think?

Thank you

Upvotes: 6

Views: 11013

Answers (5)

TodorS
TodorS

Reputation: 406

Here is an update on saving SQL snippets that may be useful to the thread visitors:

T-SQL snippets were introduced in SQL Server 2012 as part of SQL Server Management Studio (SSMS).

The location of SQL snippets depends on the version of the SSMS that is used. So if SSMS 2014 is used, the default path on which snippets are: C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\SQL\Snippets\1033\

Snippets for SSMS 2016 are found under this path: C:\Program Files (x86)\Microsoft SQL Server\130\Tools\Binn\ManagementStudio\SQL\Snippets\1033\ -

The only difference is in the name of the folder that comes after the MS SQL Server folder (e.g. folder 130 for SSMS 2016, 120 for SSMS 2014.)

To save a SQL snippet the .snippet extension must be used.

See more at: http://www.sqlshack.com/sql-snippets-in-sql-server-management-studio/

Upvotes: 4

user2063329
user2063329

Reputation: 453

In SQL Server 2012 Express Advanced you can access the Code Snippets Manager from the Tools menu item. You can use this dialog to insert snippets; import/export snippets and so on.

enter image description here

Upvotes: 1

DOK
DOK

Reputation: 32841

I would definitely suggest using the built-in custom template feature (here's a link to an excellent tutorial). But sometimes you want to save notes and snippets that are not in template format.

For those situations, you could create a code snippet solution. Within that, create projects on specific topics. Then, you can add individual database scripts to those projects.

Here is an example. One project is named Queries. It contains .sql files named Select.sql, NestedSelect.sql, and so on. It may also contain text files under the Miscellaneous folder.

Other projects might be named InsertUpdate, StoredProcedures, CreateDatabase and so on.

An alternative is to use another tool such as OneNote or my personal favorite InfoSelect. I have megabytes of SQL scripts on my laptop in InfoSelect.

Upvotes: 1

CodeMonkey1313
CodeMonkey1313

Reputation: 16021

you could write a quick application that could do that for you, or you could use a VS add-in (assuming you're using VS - based on the question relating to SQL Server 2005) like CodeKeep.

Upvotes: 0

Related Questions