0

When writing SQL, I constantly find myself checking the structure of a table / view or selecting the top 100 rows to get a preview of the data.

For instance, when I have something like this (and I have forgotten the structure of table2)...

SELECT
FROM table1 INNER JOIN table2 ON table1.fieldX = table2.???

I would like to highlight a table / view name and then pass it to a SQL query by passing a parameter, say table2 to either of the following 2 queries

SELECT TOP 100 * FROM table2

or

SELECT o.Type, o.Type_Desc, o.name AS ObjectName, c.name AS ColumnName
FROM sys.objects AS o INNER JOIN sys.columns AS c ON o.object_id = c.object_id
WHERE o.name = N'table2' AND o.Type IN (N'U', N'V')
ORDER BY o.name,c.column_id,c.name

I use SSMS Boost (it's my favorite SSMS addin) but can't figure out how to use functionality (Auto Replacement, Shortcut, Macros) in order to accomplish what I want here.

Has anyone ever set this up?

JoeFletch
  • 3,820
  • 1
  • 27
  • 36
  • 1
    SSMS should be enough. I have my keyboard shortcuts ctrl+3,4,5,6,7 to do something similar. simply put in your code in the shortcut text. like `SELECT TOP 100 * FROM`. and when you select the table name and press the keys, it should work. – SoulTrain Feb 25 '15 at 07:35
  • Yes, that works, but what if i wanted to get the table / view structure from `sys.object` and `sys.columns`? It appears that the highlighted text is just passed to the end of the statement. – JoeFletch Feb 25 '15 at 08:24
  • Try ALT + F1 on a highlighted table. It should get you the schema info you are looking for. – SoulTrain Feb 25 '15 at 14:54

0 Answers0