Query Analyzer Tricks

  • quote:


    Another very useful editor with great find and replace tool (and regular expressions) is the freeware program Notetab Lite http://www.notetab.com. I use it all the time, very handy for formatting data from 'legacy' data sources into appropriate CSV formats for import into SQL.


    Doh! I see you've all already discussed this. I should read the whole topic forum before posting!

  • Apologies on v7. Not sure how many of them work, but QA was a 1.0 product in 7 and substantially enhanced in 2000.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    The Best of SQL Server Central.com 2002 - http://www.sqlservercentral.com/bestof/

    http://www.dkranch.net

  • Great Article - Many useful tips.

    Has anyone figured out how to expand the number of Recent Files listed to more than 4?

    Jeff451

    SQL Guru wannabe

    Jeff451SQL Guru wannabe

  • No idea, but I'll try to look.

    and thanks.

    Steve Jones

    sjones@sqlservercentral.com

    http://www.sqlservercentral.com/columnists/sjones

    The Best of SQL Server Central.com 2002 - http://www.sqlservercentral.com/bestof/

    http://www.dkranch.net

  • Possibly this is such common knowledge that everyone else already knows about it, which is why I never see it mentioned anywhere.

    Some of the most useful Query Analyzer Tricks for me are the built in Keyboard shortcuts, like the Ctl+Shift+C to comment a block of code, or Ctl+F2 to insert a bookmark (and F2 to go to the bookmark).

    The complete list can be found in the "Keyboard Shortcuts" link at the top of all of the pages in Books Online.

  • Good tips...

    Let me just correct / complement something about the extremely useful shortcuts in Tools | Customize of QA. You CAN pass 1 parameter. Just write it in QA and then press the shortcut. For example, I have CTRL+0 mapped to sp_helptext. Whenever I want to see the code for a stored procedure or a view, I just write the name, select it, and press CTRL+0.

    To see the detail for a table, you can write the name of the table, select it, and press ALT+F1.

    Sergio Soares

     

  • Great tip. I didn't know this, but it could be a great help in any custom procedures that you need to pass a parameter in on.

  • Great article.  I particularily like the tip on tempates, but don't understand how to store the custome template. Can it be placed in the Templates folders? I don't see a "create new" template menu item.

    Thanks.

  • Another useful keyboard shortcut for working with templates is CTRL+SHIFT+INS. This brings up a File Open dialog in the default templates folder and lets you choose a template. The selected template is then inserted into the current query window wherever you left the cursor.

    I like to use this when I have built a query that is going to go in a stored procedure. I put the curser below the query and insert my stored proc template. Then I use the variable replacement (CTRL+SHIFT+M) and move my query to the body of the stored procedure. A couple adjustments later I am done. (I usually don't have exactly two parameters to the procedure so that requires cleanup or additional params.) Note that this works best if you save your templates to the same location SQL Server setup installs the default templates.

    Other keyboard shortcuts for SQL Server tools can be found by typing "shortcut keys" in the index lookup in BOL. This will bring up the shortcuts for each of the client tools in the index list.

    [font="Tahoma"]Bryant E. Byrd, BSSE MCDBA MCAD[/font]
    Business Intelligence Administrator
    MSBI Administration Blog

  • Create your template just like any other SQL script. Then do a File->Save As and choose Template SQL Files (*.tql) from the Save As Type dropdown list. You can save these files anywhere you like, including the location SQL Server setup put the default templates.

    [font="Tahoma"]Bryant E. Byrd, BSSE MCDBA MCAD[/font]
    Business Intelligence Administrator
    MSBI Administration Blog

  • I love this type of article/discussion. I find tips from seasoned professionals very interesting and helpful.

    I only have one qualm about using the templates and the auto scripting features: it doesn't give me continued practice & expertise with certain TSQL code. I'm continuing to expand my memory of TSQL code and paramters and the like, and I find actually typing the stuff helps me remember it better. It's kind of like EM -- if you use the wizards, you don't get to know the TSQL code. It's not a perfect analogy, I know. :>

    But a happy middle ground can be reached. There are a lot of these features that are just a matter of efficiency and reducing errors/typos. But I can leave out of templates and the macro keys those pieces of code I want to drill into my head. This stuff is incredibly useful as an assistant (like outsourcing mundane stuff) so that I can concentrate more on the important, more-interesting code.

    BTW, I especially like the CTRL-SHIFT-M feature with the update/insert scripts QA creates. That whole variable feature is very cool.

    Thanks for the article and fantastic discussion!

  • This is MY favorite tip in QA:

    QUICKLY SCRIPTING/TESTING AN OBJECT

    If you use QA a lot, you may have noticed that in the ojbect browser you can right click on the object and you get these magical options:

    - Script Object to new window as...

    - Script Object to file as...

    - Script Object to Clipboard as...

    Would you like them in QA? Would you like them here in May? Try them! Try them and you may, I say.

    You can't even imagine how much time these things have saved me. =)

    Cheers,


    {Francisco}

  • Francisco_Lopez said:

    - Script Object to new window as...

    - Script Object to file as...

    - Script Object to Clipboard as...

    Yes, Francisco, those are sweet features! You can drag objects with the right mouse button to the query window and drop scripts on there too. I often create a stored procedure script, execute it, and refresh the object browser so that it shows up in the list. Then I can drag the object with the right button to the top of my script and add a DROP script at the beginning with near-zero effort.

    Always remember though, if you drop and recreate an object you will need to refresh the object browser. It uses object id's internally and these change when dropping/adding objects.

    [font="Tahoma"]Bryant E. Byrd, BSSE MCDBA MCAD[/font]
    Business Intelligence Administrator
    MSBI Administration Blog

  • You all probably already know this, but if you right-click an object in the browser and select Scripting Options, you can set some useful features. I like including extended properties, adding the drop command, descriptive headers, and qualify object name by its owner.

  • I had just a couple thoughts:

    1) This works great for quick reports - Go to "Tools|Options|Resutls tab", change the results output to "Tab delimited", then run your query. You can copy/paste your results directly into Excel.

    2) A code snippet for generating a comma delimited list of columns for a given table. This could be enhanced from "sp_help" and from templates:

    select ", " + [name] from syscolumns (nolock) where id=object_id(N'[tableowner].[tablename]') order by colid

    EXAMPLE from Pubs:

    select ', ' + [name] from syscolumns (nolock) where id=object_id(N'[dbo].[authors]') order by colid

    Returns

    , au_id

    , au_lname

    , au_fname

    , phone

    , address

    , city

    , state

    , zip

    , contract

Viewing 15 posts - 31 through 45 (of 54 total)

You must be logged in to reply to this topic. Login to reply