What are your five most common T-SQL commands

  • nowadays and no longer a regular TSQL practitioner (as well as the grey cells quickly dying off )

    I find the following useful......I know that it can be done, but cannot immediately recall the correct method

    so

    http://bfy.tw/1U7j

    ________________________________________________________________
    you can lead a user to data....but you cannot make them think
    and remember....every day is a school day

  • Ed Wagner (8/26/2015)


    Hugo Kornelis (8/26/2015)


    GilaMonster (8/26/2015)


    Gazareth (8/26/2015)


    But probably the most common: DELCARE left left left backspace left C 😛

    In that case, mine would be SEELCT left left backspace left L :hehe:

    Interesting. My "favorite" typo is SLEECT, yours is SEELCT. I am pretty sure that psychologists could have a field day with this... :crazy:

    Mine if FORM instead of FROM. I think we all have them.

    You're all weird.

    I type 'de' space and get 'DECLARE'.

    I type 'ssf' space and get 'SELECT * FROM'.

    It's almost like you don't have Prompt installed...

    Oh....

    Never mind.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • I do. All my colleagues and clients, whose machines I end up working on from time to time while helping/consulting, not so much.

    And you've changed snippets. de <space> gets me DEALLOCATE (which I use so very, very, very often)

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • GilaMonster (8/26/2015)


    I do. All my colleagues and clients, whose machines I end up working on from time to time while helping/consulting, not so much.

    And you've changed snippets. de <space> gets me DEALLOCATE (which I use so very, very, very often)

    Sorry. Send in a complaint. They'll fix it. Or you can locally (pain, I know).

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

  • Grant Fritchey (8/26/2015)


    Ed Wagner (8/26/2015)


    Hugo Kornelis (8/26/2015)


    GilaMonster (8/26/2015)


    Gazareth (8/26/2015)


    But probably the most common: DELCARE left left left backspace left C 😛

    In that case, mine would be SEELCT left left backspace left L :hehe:

    Interesting. My "favorite" typo is SLEECT, yours is SEELCT. I am pretty sure that psychologists could have a field day with this... :crazy:

    Mine if FORM instead of FROM. I think we all have them.

    You're all weird.

    I type 'de' space and get 'DECLARE'.

    I type 'ssf' space and get 'SELECT * FROM'.

    It's almost like you don't have Prompt installed...

    Oh....

    Never mind.

    I do have Prompt installed (on my own laptop, not on most client systems).

    I do not use its snippets function. I am now at the age where trying to memorize all the shortcuts would take me more effort than the keystrokes to correct my typos (which are all firmly embedded in muscle memory by now).

    In fact, I have disabled its snippets function because when I whip together a quick example to test something, I like to use one- or two-letter table and column names. Which Prompt would then promptly interpret as a snippet shortcut and expand. AAARRRGGHHHH!!!!


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • In my case, SELECT, UPDATE, DELETE, TRUNCATE AND INSERT

  • I look at the error log all day every day

    EXEC master.dbo.xp_readerrorlog 0, 1, NULL, NULL, NULL, NULL, N'desc'

  • Eric M Russell (8/21/2015)


    You are standing in an open field west of a white house, with a boarded front door.... Opening the small mailbox reveals a leaflet.

    > read leaflet

    "ZORK is a game of adventure, danger, and low cunning. In it you will explore some of the most amazing territory ever seen by mortals." http://www.web-adventures.org/cgi-bin/webfrotz?s=Zork1%5B/quote%5D

    Never mind T-SQL, I have just spent a very happy hour testing my memory! Result : must be getting old. Got eaten by a grue! Thanks for that, Eric:-)

  • Thanks for getting this going, Grant. It is one of the best and most entertaining threads I've seen in a while.

    My two bits:

    -- Desperately trying to find a foreign key in an undocumented database

    select table_name,column_name,data_type from INFORMATION_SCHEMA.COLUMNS where COLUMN_NAME like '%X%'

    -- Most common typos

    delect -- not my fault they put the d by the s

    groupo -- go figure

    transactioni -- maybe I was Italian in a previous life

  • Favorite name for a Temp Table when troubleshooting something that should never have made it to production...

    [font="Arial Black"]#MyHead[/font]

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • Jeff Moden (8/27/2015)


    Favorite name for a Temp Table when troubleshooting something that should never have made it to production...

    [font="Arial Black"]#MyHead[/font]

    When I want to make sure that my query tuning measurements are not impacted by the time it takes SSMS to render the results, I often redirect the results to a temporary table. And I have a standard name for that table too:

    SELECT (something)

    INTO #Oblivion

    FROM (etc)


    Hugo Kornelis, SQL Server/Data Platform MVP (2006-2016)
    Visit my SQL Server blog: https://sqlserverfast.com/blog/
    SQL Server Execution Plan Reference: https://sqlserverfast.com/epr/

  • Glad to see I'm not the only one with Morecambe's fingers (all the right notes...)!

    I often use #transient for temp results

    forgot these too:

    SET STATISTICS TIME ON & OFF

    SET STATISTICS IO ON & OFF

    And this is becoming more frequent (cheers Jeff)

    DECLARE @measure DATETIME2 = SYSDATETIME()

    ...

    SELECT DATEDIFF(ms, @measure, SYSDATETIME())

  • Hugo Kornelis (8/28/2015)


    Jeff Moden (8/27/2015)


    Favorite name for a Temp Table when troubleshooting something that should never have made it to production...

    [font="Arial Black"]#MyHead[/font]

    When I want to make sure that my query tuning measurements are not impacted by the time it takes SSMS to render the results, I often redirect the results to a temporary table. And I have a standard name for that table too:

    SELECT (something)

    INTO #Oblivion

    FROM (etc)

    I've seen #MyHead several times before, but never INTO #Oblivion. Nice! 😛

  • sp_who2

    dbcc showfilestats

    restore filelistonly from disk = ''

    restore database z from disk = '' with move 'x' to 'x', move 'y' to 'y', stats=1

    sp_readerrorlog

  • Mine are all in snippets.

    ;WITH rowCnts

    AS (

    -- Shows all user tables and row counts for the current database

    -- Remove is_ms_shipped = 0 check to include system objects

    -- i.index_id < 2 indicates clustered index (1) or hash table (0)

    SELECT o.name

    ,

    SCHEMA_NAME(o.schema_id) [schema] ,

    ddps.row_count

    FROM sys.indexes AS i

    INNER JOIN sys.objects AS o ON i.object_id = o.object_id

    INNER JOIN sys.dm_db_partition_stats AS ddps ON i.object_id = ddps.object_id

    AND i.index_id = ddps.index_id

    WHERE i.index_id < 2

    AND o.is_ms_shipped = 0

    )

    SELECT [schema] ,

    ,[row_count]

    FROM rowCnts

    /*

    WHERE

    IN ( 'InvoiceLineItem',

    'InvoicePaymentLineItem',

    'InvoiceRefundLineItem' )

    --*/

    ORDER BY [schema],

    DECLARE @search SYSNAME = 'codeset'

    SELECT s.name, t.name, c.name

    FROM sys.tables t

    INNER JOIN sys.columns c ON c.object_id = t.object_id

    INNER JOIN sys.schemas s ON s.schema_id = t.schema_id

    WHERE t.name LIKE '%' + @search + '%'

    OR c.name LIKE '%' + @search + '%'

    ORDER BY t.name, c.name

    DECLARE @search NVARCHAR(4000) = 'DPH'

    select s.name [Job Name]

    , js.step_name [Step Name]

    , js.command

    FROM msdb.dbo.sysjobs s

    INNER JOIN msdb.dbo.sysjobsteps js ON js.job_id = s.job_id

    WHERE s.name like '%' + @search + '%'

    OR js.step_name like '%' + @search + '%'

    OR js.command like '%' + @search + '%'

    SELECT UseCounts, Cacheobjtype, Objtype, TEXT, query_plan

    FROM sys.dm_exec_cached_plans cp

    CROSS APPLY sys.dm_exec_sql_text(plan_handle) sqlT

    CROSS APPLY sys.dm_exec_query_plan(plan_handle) qp

    INNER JOIN sys.objects o ON sqlT.objectid = o.object_id

    INNER JOIN sys.schemas s ON s.schema_id = o.schema_id

    WHERE o.name = 'object_name'

    AND s.name = 'schema_name';

    Derik Hammer
    @SQLHammer
    www.sqlhammer.com

Viewing 15 posts - 46 through 60 (of 63 total)

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