saving code snippets in sql server
Asked Answered
A

5

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

Arriola answered 17/11, 2010 at 13:17 Comment(0)
M
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/

Mudstone answered 11/5, 2016 at 10:27 Comment(0)
E
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.

Epizoic answered 17/11, 2010 at 13:26 Comment(0)
B
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

Bosh answered 21/10, 2013 at 1:48 Comment(1)
I can't see how to quickly create a snippet without fiddling around with XML files on disk, that would be useful.Unbosom
O
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.

Obbard answered 17/11, 2010 at 13:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.