In Toad for Oracle you can put the cursor on the name of a object and press F4 to open it's definition.
Is there anything similar in T-SQL / SQL Server Management Studio ides?
I have developed SSMSBoost add-in for SQL Server Management Studio and it does exactly what you want. The shortcut is F2
If you want the definition of an object, the procedure sp_helptext will give that to you. As for assigning it to a keyboard shortcut in SSMS, you can do so by going to Tools → Options → Keyboard → Query Shortcuts and assigning sp_helptext to one of the available slots. Once that's done, highlight the name of an object in your query editor window, hit the assigned shortcut and it should display the definition. As someone mentioned above, sp_help will get you different information (i.e. columns, indexes, constraints, etc) if the object is a table or a view. Luckily, the same process applies to sp_help!
Related
A month or so ago I somehow managed to get a tiny widget showing in SQL Server 2008 where I could type the name of the procedure/table (never searched for anything else) and it would bring a list of matching items. I could then right click on the one I wanted -> Click (I believe) "synchronize" and it would bring the said item in the Object explorer, from where I could do whatever.
The widget I'm looking for was part of SQL Server and i was able to pin it bellow the Object Explorer.
I've no idea how I found it and where it is, but it's extremely useful for fast searching of objects.
It was NOT a Select or an SQL statement of any kind.
The SSMSBoost add-in also provides such functionality.
Maybe some screenhots are helping to remember...
As already mentioned by Creep, it could also be RedGate SQL Search:
Use the 'Object Explorer Details' window (F7).
SSMS -> View - > Object Explorer Details
I think it could be one of those (free) products : redgate sql search or dbforge sql search
I've been handed some legacy SQL Server 2005 database, and we have it running on SQL Server 2008 R2. There's a lot of reference to entities through inline SQL and no foreign keys, so I find myself repeatedly opening the T-SQL source of stored procs, which means going through the "script stored procedure as...CREATE to...new query editor window" GUI menu. Is there a way to bind this to a keyboard command?
In SSMS go to Tools -> Options and then see the screenshot for Ctrl + F1
Basically I execute shortcut Ctrl + F1 in my case
Give this a shot
EXEC sp_helptext 'sp_name'
It will work for any "code" but not tables etc.
While doing development in SQL Server Management Studio (SSMS), I frequently want to check the properties of a number of index on a specific table from within the Object Explorer:
Pulling up the index properties to see the columns included in the index, one can double-click the index name in Object Explorer, or alternatively use the Menu Key and then using Up to select Properties, and then hitting Enter.
I checked the SQL Server Management Studio Keyboard Shortcuts list, but did not manage to find the answer to my question.
Is there a one-key shortcut that could be used to pull up the index properties instead?
I have just tried to find any context menus registered in SSMS concerning Index in Object explorer, but unfortunately it looks like that it is 100% built dynamically. So it is impossible to assign a shortcut. Generally, you can assign shortcut on any command, that is registered as menu command in SSMS. But no luck here.
No, I don't believe so. Usually if someone wants that level of speed in accessing information about indexes, they'll just issue an sp_helpindex command in T-SQL or query sys.indexes for the information they want.
Say I already created my database but forgot to save the sql commands do create it.
How could I reverse engineer the code from an already existing database?
I'm using Microsoft SQL Server Express 2008.
You can do this pretty easily by using SQL Server Management Studio (SSMS) - it's available for free if you don't already have it installed.
Connect to the database
Expand out Databases > YourDataBaseName.
Right-click on the database and select the option "Script database as" then "Create To" then finally "File".
That will create the necessary scripts to recreate your database.
To script out all the tables in your database:
Right-click on the database node
Select "Tasks" then "Generate Scripts".
When the wizard appears, click Next.
Select the database. At this point you can check the "Script all objects in the selected database" which does exactly what it says, or if you leave it unchecked you will get the option later in the process to pick which items are scripted.
Click next. Now you're given some scripting options.
I'd suggest scrolling down the list and checking the option to Script Indexes/Script Triggers. You can also script the data if necessary (though I wouldn't do this if you've got a lot of data in your database).
Modify any options you'd like and click Next.
Select the database types you'd like to script (Users/Tables/Views). Click Next.
Now you've got the opportunity to select more specific items. Hit Next and repeat the process of any of your other database types.
Hit next one more time, then select where you'd like the script written to. You get the chance to review your selections.
Click Finish.
Here's a link for the 2008 version SSMS Express 2008
Your RDBMS comes with some sort of "dump" tool that will give you the structure and content of your database, in the form of SQL statements.
As others have mentioned, if you have SQL Management Studio (you should, it's free as part of SQL Server Express). Fire it up, connect to your instance then expand the Database tree.
Right click on your database and select Tasks->Generate Scripts..
Click next, then Next again (which selects all objects in the database by default), pick an output option (defaults as "Save to File"), click next and voila!
If you also want to script the data as well as the schema, in the "Set Scripting Options" window, click on the Advanced button, scroll down to "Types of data to script" (just above the Table/View Options header) and select "schema and data".
[Edit] Tested - The Generate Scripts option exists and works in the (free) 2008 R2 edition of SSMS. See the link in my comment below for the URI for the R2 version.
Anytime I use 'script table as' -> 'Insert To' (or other command), the script generated automatically places the database name in the script. Such as:
INSERT INTO [DatabaseName].[dbo].[tblToBeInserted] ...
While not a huge problem to just delete it, it has slipped by a few times and the script breaks if run on a different server with a different database name but has the same schema. (Such as running on [DatabaseName.Test])
Is there an option I can change, or can I modify the output in any way to remove this?
Assuming that you are using Microsoft SQL Server Management Studio 2005 or higher you can goto the Tools -> Options menu. On the dialog select "Scripting" from the left hand side. On the right-side in the "General Scripting Options" section there is an option called "SCRIPT USE ". You can set that to FALSE.
in SSMS 18.x, Go to the "Tools" menu and then select "Options". from the left side of the Options window select "SQL Server Object Explorer" and then "Scripting".
set "Script USE database" to False.
In SSMS, go to View -> Template Explorer, you can find a lot of templates there. Or, you can find these template .sql files from %appdata%\Microsoft\Microsoft SQL Server\100\Tools\Shell\Templates\Sql