How to edit SSMS Script Table As templates? - sql-server

In the context menu of a table in SQL Server Management Studio there are several items under the common item Script Table as:
SELECT to
INSERT to
UPDATE to
DELETE to
..
and the same for all objects, e.g. stored procedures, functions, etc.
How can I edit the templates used by that menus?

You cannot edit the templates used by SQL Server Management Studio (which would be a nice feature).
You can create your own (parameterised templates) in C:\Users\Username\AppData\Roaming\Microsoft\Microsoft SQL Server\100\Tools\Shell\Templates\Sql (for SQL Server 2008)

What do you want to do with this?
Have you seen the SSMS tools pack which adds some right click options?

Related

SSMS unable to change Table View Type in Database diagram. SSMS 17

In SQL Server Management Studio 2017, When I am creating a new diagram & adding a new Table (or adding an existing table) to the diagram,
I am unable to change the Table View type to Custom.
Also, when I am modifying Table View "Custom" to include columns such as Default Value or Description, SSMS fails to update the table view type.
I have tried connecting instances of SQL Server 2008 R2 as well as SQL Server 2016 to the studio.
Is it a bug or is there a setting which I need to change ?
Extra Info : Downloaded it from here https://learn.microsoft.com/en-us/sql/ssms/download-sql-server-management-studio-ssms
it might be you hit a bug. i've tested it using SSMS 14.0.17213.0 (17.4) and the table view custom is working fine. please check again. You may need to update your SSMS as Microsoft updates SSMS every month to provide bug fixes and add new features.
HTH

Sync with active table Microsoft SQL Server

In Visual Studio you have a function: sync with active document. This is a very handy function. Because you can see in the solution explorer where the document has been stored.
My question is: is there a similar function in Microsoft SQL Server 2014 - that you can stand with your cursor on the table name in a query and then for example with a sub menu you can see witch table is selected in the object explorer.
This is especially handy if you have for example 300 tables and you want to see the columns of that table that you have written in a query.
THank you
I am not aware of any way to do this natively in SQL Server Management Studio. However, there are several third party extensions which do have this feature.
Two of the more popular extensions:
ApexSQL Complete (free)
SQL Prompt (paid w/free trial)
Both of these tools have functionality that allows you to navigate to an object in the Object Explorer, or view the contents of the object from within the query window by hovering the mouse over the object name.
For example, this can be accomplished in ApexSQL Complete by right-clicking an object and selecting "Navigate to object".

Create Database Instance from Model

*Seems like there is some confusion. I created a SQL Server Compact Edition file and can see it from the Server Explorer. I can also right click and add tables manually. What I want to do is run the generated sqlce file to add all of the tables and columns from my model to the SDF.
-- background --
In Visual Studio 2012 (Ultimate), I designed a model using the model designer. It created an edmx file. I right clicked the model and chose "Generate Database from Model..." and created an sqlce file. My understanding is that I should be able to execute this file on an sdf somehow to create a SQL Server Compact Edition Instance of my database. I don't see the option on right click to execute the sql code, and the other option is to "Run SQL Scripts in Solution Explorer" which doesn't seem to make sense.
http://msdn.microsoft.com/en-us/library/yea4bc1b.aspx It says to drag the sqlce file to a database reference, but I'm not really sure what they mean. I have tried to drag it to the server explorer where the sdf is connected.
I tried right clicking on the sdf in the Server Explorer to do New SQL Query and pasting the sqlce in, but it seems that Create Table isn't supported.
Any ideas?
Generate Database from Model... only generates tables and relationships.
You need to have a database created already, and have it in the Database References folder. Then you drag your script file to that database reference, as described in your mentioned link.

SQL Server Mangement Studio Alter Script (2005)

Is it possible to generated ALTER sql script from the changes you perform in Server Studio. This is possible in different tools for mysql, basically you get the log of executed statements. Is similar thing possible here, or how do you go about finding out what the modification (ALTER) script is?
Thanks.
-- MB
You will be able to auto generate change scripts in SSMS. Take a look at this article, I believe it might be what you are looking for. http://www.mssqltips.com/tip.asp?tip=1723
from the article
As a part of my best practices, I always save the T-SQL scripts used for creation and modification of objects in SQL Server. When creating and modifying tables using SQL Server Management Studio designer it is easy to right click in the designer and select "Generate Change Script...", but is there a way to automatically script the creation and/or modification of tables made through of SQL Server Management Studio (SSMS) designer? This tip shows you an option that exists within SSMS to automatically generate these scripts for all table changes when using the table designer.
If you're altering a table (by right-clicking and selecting Design, then there is a button named Generate Change Script on the Table Designer toolbar.
If you're talking about changes made in a properties window, there is a script button at the top of each of those that can generate scripts for changes you make through the UI.
Not sure about SQL Server 2005, but in SQL Server Management Studio 2008 and later, you can definitely do this.
When you modify a table in the table designer (right-click on a table in your Object Explorer and pick "Design" from the menu), you can have SSMS generate the ALTER script for you by right-clicking in the designer and choosing "Generate Change Script":

SQL Server Stored Procedure Folders/Grouping

We are currently using SQL Server 2000 but will soon be moving to 2008. I am looking for a way to group related stored procedures into folders. SQL Server 2000 does not seem to have this ability and from my searches it looks like 2008 does not either. This seems like a basic feature that most users would want. Wouldn't it make sense to put all generic stored procedures that are shared across multiple projects in one folder and project specific procs in another?
It seems the way most devs do this now is by using some from of ID_SPNAME syntax and sorting them.
Grouping procs and functions by type in the UI would be nice, but Management Studio can't do it. Using SQL Server 2000, I've done what you suggest (prefixing objects with a grouping code and sorting). In 2005 and 2008, consider creating schemas to serve the same purpose, and grouping your objects in those. Note that the object names are prefixed with the schema name in the UI.
CREATE SCHEMA ShoppingCart AUTHORIZATION Joe
CREATE PROCEDURE AddItem ...
... will display in the UI as ShoppingCart.AddItem.
Schemas in Sql Server 2008
The most common way to do this (in SQL 2005/2008) is by using schemas:
HR.spCalculateEmployeeCompensation
HR.spCalculateContractorBonus
Web.spAppendWebLog
Web.spUserEndSession
Reporting.spGetCurrentYearSummary
Reporting.spGetLastMonthDetail
Not only will these visually organize themselves in the SSMS list, but you can apply different permissions to each schema.

Resources