Go To Definition Like Functionality in SQL SERVER - sql-server

Is there is any Go To Definition like functionality in SQL SERVER which we use in Visual Studio. It's a little painful to browse and edit a SP or function. Any other quick way to edit will be appreciated.

Some third-party tools will help, such as:
redgate sql search (Free)
redgate sql prompt (Commercial, trialware) - very good one
others in Sql Toolbelt

No. SQL Server objects don't fit into .net namespaces or object hierarchy
You can kind of emulate it with Red Gate SQL Search in SQL Server Management Studio. Or SSMS Tools Pack, but neither of these are for Visual Studio

SQL Server 2012 seems to have this functionality. Tools --> Options --> Environment --> Keyboard --> Edit.GoToDefinition, which should be F12. If not, assign the key.

Check out dbForge SQL complete: link - useful tool, has a trial, also free version but it doesn't contain go to definition functionality, only full version does.

I use a trick. Type in any query window (SSMS 2016) the sp name you want to go to definition as you usually run it (i.e. exec sp_my_sp_name 1,2,...). Then type F11 to start debugging a couple of times until you get into the sp. Once you're inside, press stop button. I know this is not the best approach but at least you get to the sp definition quickly and faster than installing 3rd party tools or other solutions commented in this thread.
Regards

Related

How to debug T-SQL with SQL Server Management Studio 2017?

The latest changelog (18.0 Preview 7) of SQL Server Management Studio announced, that the T-SQL Debugger is deprecated.
What are the alternatives for the future? Can someone understand this decision? I fear that removing a fundamental development tool like this will effect many developers.
You just need to download the Visual Studio 2019 Community.
Once you've done that, create a new project and open the SQL Server Object Explorer (CTRL + S).
You will be able to see your list of SQL Server databases, just as you did in SQL Server Management Studio.
Finally, left click one database and select "New Query". Now you can debug T-SQL just as you did in SSMS.
But the debugger does not work with Azure SQL
It seems that Microsoft may have temporarily moved the branch of debugging
from
SSMS18 to SQLServer Data Tools (SSDT).
According to developers of DBA Stackexchange community, there is
another alternative way to debugging, since Debugger is deprecated in
SSMS18.
Here is the link that shows how to achieve debugging : How to add the Debug
button to
SSMS v18?
ALTERNATIVE: ??
Just when I thought there would be no solution to this coming out any time soon, to my surprise there might be one.
There is a tool that I've come across lately while dabbling into this
debugger thing in SSMS18 out of curiosity, which goes by the name SQL Complete.
The company Devart apparently specializes in Database products and provides toolsplug-ins for various major databases.
Here is a small video of them briefing about the debugging feature in their tool SQL Debugger in the new version of dbForge SQL Complete
It's available on Visual Studio Marketplace.
#dens is correct by going to visual studio community edition however this is half of the answer as table variable values cannot be inspected and have the placeholder as (table); This is due to Microsoft not finishing this portion of the debugger. Currently, you can only see primitive data types outputted within the Locals Tab.
The work around to see table variables when they are deleted, updated or inserted into is to utilize the output keyword with each query to output the inserted or deleted elements. Now when you step through you will see the primitive variables within the debugger logger tab called "Locals" and the table variables within the Results or T-SQL tab as you step through. unfortunately the variable name will not be next to the output however as you step through, its pretty clear which table output belongs to which variable
Furthermore, if you are debugging a stored procedure on a SQL database not on your local database, i recommend backing up a local version of the database with the developer edition of SQL server since attaching a debugger to the query will get blocked by the firewall. Then you will require sysadmin privileges and open ports which may work however it did not work within my workplace. we tried even dropping the entire firewall and nothing but good luck.

Red Gate's SQL Toolbelt or Quest's Toad for SQL Server?

We are evaluating trial versions of Red Gate’s SQL Toolbelt and Quest Software’s Toad for SQL Server. What are the main differences between these tools? The benefits of using these tools are quite obvious but we are wondering which one is more suitable for a developer and development work? Is Toad for SQL Server more focused on DBA work?
Toad for SQL Sever basically is an alternative to SQL Server Management Studio - it gives you insights into your server, databases, database object etc. and you can execute queries and explore your data. But that's about it.
Red-Gate's Toolbelt is a totally different set of tools - a toolbelt, as the name implies:
compare databases for structural or data-related differences
determine dependencies between database objects
greatly superior intellisense for SSMS and Visual Studio
package database changes into an update package (EXE or .NET assembly)
and a lot more
I don't think TOAD offers any of those capabilities, so you're really comparing apples to carrot or something here.
I can totally recommend Red Gate tools - I'm using SQL Prompt, SQL Search, SQL Compare, SQL Data Compare and SQL Packager regularly, and they just do their job in a great way. Highly recommended!
The tools from RedGate are spectacular. I don't know about Quest's Toad, but you cannot go wrong with RedGate. In fact I often end up using their products as fodder for requirements on new features for my unrelated products.
They quickly respond to questions, provide intelligent assistance, and, well, if I could marry Redgate I would get down on one knee right now.
'nuff said?
Toad, has a free "community version" 6, which indeed offers intellisense, dependencies and other things.
There are 3 levels of paying versions and they have comparison tools + many extras which I could not evaluate since I am only using the free version.
Anyway, since I started using Toad I nearly never go back to SSMS...except for the free RedGate SQL Search, which is a real time saver in some situations.

Red Gate SQL Compare vs. VS2010 Ultimate

I used to use SQL2000 and Red Gate SQL Compare 3.2 and I was a happy camper. I wouldn't worry about tracking the changes that I make to the dev database until all the coding was done and I needed to compile a list of scripts to bring the prod db in sync with the prod.
This is where SQL Compare and to some degree, SQL Data Compare, were invaluable in
pointing out the differences and even more importantly,
helping me generate the SQLs to bring the prod db in sync with the dev db.
I see that VS2010 Ultimate allows me to compare two schemas, but does do #2? I believe it is suppose to but it ain't obvious to me how to do that.
Any kick in the right direction would be an immediate vote up or better. ty.
Yes, it does (2). To achieve this, run the comparison (Data/Schema Compare/New Schema Comparison), choose the objects you want to update, and then right click on the grid or go to the Data/Schema Compare menu and select Refresh Update script. If you can't see an upgrade script now, select Show Schema Update Script which is in the same menu.
If you want a more user-friendly and versatile tool, please consider trying SQL Compare 8! (I'm the product manager)
Caution plug,I wrote a blog entry to compare SQL Data in VS2010 Ultimate and Premium that you might wanna check out http://zubairdotnet.blogspot.com/2010/07/fun-with-vs2010-ultimate-comparing-sql.html
As far as I can tell, this tool in VS2010 Ultimate will only work with SQL Server 2005 and 2008. I tried yesterday to do a compare between my production SQL 2000 instance and a dev 2008 instance, and it flat-out said it will not work with anything prior to 2005. RedGate Compare, of course, had no issues at all.
Drop every thing, and try SQL Server Data Tools October 2013 release for Visual Studio 2012: http://msdn.microsoft.com/en-US/data/tools.aspx, choose 'Get It' and then 'Download SSDT for Visual Studio 2012', or you can go straight there on:
http://msdn.microsoft.com/en-us/jj650015
It has Schema Compare and Data Compare, and even allows SQL Server 2014 CTP2 connections.

Tools to generate SQL DDL and Content from an existing database

Does anyone know of a reasonably priced tool that will create DDL statements to create a SQL Server database and appropriate Insert statements to recreate the data? I use the Red Gate tools to do database compares (including content compares) and this comes close (I could always compare with an empty schema) but I was wondering if there was a tool that others found useful that did this in one step.
Late answer... hopefully someone will find it useful…
There is a tool from Red Gate called SQL Multi Script that can do scripting for what you need. Not sure if it existed when the question was asked though :)
Another good piece is SQL build tool from ApexSQL which can also do all kind of insert and other scripts…
Disclaimer: I’m not affiliated with any of the companies mentioned above.
Have you had a look at SQL Publishing Wizard? It will create all the DDL statements you require for all database elements (tables, views, SPs, users etc).
If you're using SQL 2008, it comes built into the management studio. More info on 2008.
SQL Publishing Wizard
Saw Austin Solonen post this tool in a somewhat related thread. Express editions appearantly don't hove Import and Export.
The database publishing wizard that is included in Visual Studio 2008 performs this function.
It is also available via CodePlex as an add-on for prior versions of Visual Studio.

Format SQL in SQL Server Management Studio

In Visual Studio & other IDEs, you can easily auto format your code with a keyboard shortcut, through the menu, or automatically as you type.
I was wondering if there is yet a way to enable this standard feature in SQL Server Management Studio?
I'm working with some large-ish stored procs that are a mangled mess of poorly formatted SQL and it'd be nice if I could just go "Select All -> Format SQL"
Late answer, but hopefully worthwhile: The Poor Man's T-SQL Formatter is an open-source (free) T-SQL formatter with complete T-SQL batch/script support (any DDL, any DML), SSMS Plugin, command-line bulk formatter, and other options.
It's available for immediate/online use at http://poorsql.com, and just today graduated to "version 1.0" (it was in beta version for a few months), having just acquired support for MERGE statements, OUTPUT clauses, and other finicky stuff.
The SSMS Add-in allows you to set your own hotkey (default is Ctrl-K, Ctrl-F, to match Visual Studio), and formats the entire script or just the code you have selected/highlighted, if any. Output formatting is customizable.
In SSMS 2008 it combines nicely with the built-in intelli-sense, effectively providing more-or-less the same base functionality as Red Gate's SQL Prompt (SQL Prompt does, of course, have extra stuff, like snippets, quick object scripting, etc).
Feedback/feature requests are more than welcome, please give it a whirl if you get the chance!
Disclosure: This is probably obvious already but I wrote this library/tool/site, so this answer is also shameless self-promotion :)
There is a special trick I discovered by accident.
Select the query you wish to format.
Ctrl+Shift+Q (This will open your query in the query designer)
Then just go OK
Voila! Query designer will format your query for you.
Caveat is that you can only do this for statements and not procedural code, but its better than nothing.
Azure Data Studio - free and from Microsoft - offers automatic formatting (ctrl + shift + p while editing -> format document). More information about Azure Data Studio here.
While this is not SSMS, it's great for writing queries, free and an official product from Microsoft. It's even cross-platform.
Short story: Just switch to Azure Data Studio to write your queries!
Beginning with SQL Server Management Studio (SSMS) 18.7, Azure Data Studio is automatically installed alongside SSMS.
Source
Update: Actually Azure Data Studio is in some way the recommended tool by Microsoft for writing queries (source)
Use Azure Data Studio if you: [..] Are mostly editing or executing
queries.
While for some reason Microsoft ignores to implement this in SSMS
I found the following site which does a pretty good job of formatting
the SQL Code:
https://www.red-gate.com/website/sql-formatter
Also
https://codebeautify.org/sqlformatter
Even though this one is also fairly nice, but the code it produces is a bit too verbose for me so my favorite is
red-gate.com

Resources