6

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

5 Answers 5

10

Maybe have a look at

How to: Use Templates in SQL Server Management Studio

Snippets for SQL Server Management Studio (SSMS)

Sign up to request clarification or add additional context in comments.

Comments

4

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/

Comments

1

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.

Comments

1

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

1 Comment

I can't see how to quickly create a snippet without fiddling around with XML files on disk, that would be useful.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.