Management Studio – Faster with multiple select

Management Studio – Faster with multiple select

In SQL Server Management Studio (SSMS for close friends) but also in a multitude of text editors (such as Notepad++ for example), you can make multiple selections.

I thought it was something everyone knew, but I realize that I often look like a magician every time I do it.

I’m delighted to pretend to be Harry Potter, but I think it’s time for this little game to stop!

Look by yourself how simple it is!

How?

You should press the keys [ALT] + [Shift] simultaneously and move your cursor [Up] and / or [Down] to select your text.

One useful case

Sometimes we have to surround our text with single quotes. (for example: to add multiple codes to an IN clause in a test query)

No need to add them one by one and make sure you do not have space at the end.
Here is the method:

Like mentioned above, this tip is not an exclusivity in SSMS, you can also do the same in many different text editor.

SSMS – Query Shortcuts : Feel like a superman developer

SSMS – Query Shortcuts : Feel like a superman developer

SSMS Query Shortcut

Dear BI Developer,

I’m pretty sure you would be happy to improve your productivity. If not, you should at least read this article to look like a superman (superwoman) developer.

When I start a new mission, the first thing I do is to set up SSMS (SQL Server Management Studio). And because I’m the kind of guy who acts like a Microsoft BI evangelist (and also for running), I replicate my configuration on my colleague’s machines.

Example

In this example – CTRL + 4 – COUNT

Select statement you want to execute, Press CTRL and 4

SSMS will give you Nb impacted rows.

In BI (and not only!), it’s very important to test if we have unexpected behavior with our joins.

Does our INNER JOIN filter too much data? Or worst, does our join multiply our result set?

A quick and easy CTRL + 4 will ensure you to respect your grain.

How to configure Management Studio

Open Management Studio, Go to Tools > Option…

Under Environment > Keyboard > Query Shortcuts

You have a list of existing shortcuts. (I don’t change them, but I neither use them too).
You should now fill each text box with a query.

(See image and table below)

Queries are available on the next section

Query Shortcuts

Do not forget to add a space after each query.

Tips

CTRL + 3

1000 First Rows

SELECT TOP 1000 * FROM

CTRL + 4

Nb Rows

SELECT COUNT(1) AS Nb FROM

CTRL + 5

All Rows

SELECT * FROM

CTRL + 6

Describe Table

EXEC sp_executesql N' SELECT schemas.name ,tables.name ,columns.name ,types.name ,columns.max_length ,columns.is_nullable ,columns.is_identity FROM sys.tables tables INNER JOIN sys.schemas schemas ON schemas.schema_id = tables.schema_id INNER JOIN sys.all_columns columns ON columns.object_id = tables.object_id INNER JOIN sys.types types ON types.system_type_id = columns.system_type_id WHERE UPPER(RTRIM(LTRIM(tables.name))) = UPPER(RTRIM(LTRIM(REPLACE(REPLACE(@objname, '']'', ''''), ''['', '''')))) ORDER BY tables.object_id, columns.column_id',N'@objname nvarchar(776)', @objname =

Select a table and show a quick description of attributes (Name, Datatype, size, nullable, identity)

CTRL + 0

All Running queries

 

a better SP_Who! List all running queries (Process ID, Status (blocked or running), users, …)

For more informations check this article

SELECT SPID = er.session_id ,BlkBy = CASE WHEN lead_blocker = 1 THEN -1 ELSE er.blocking_session_id END ,ElapsedMS = er.total_elapsed_time ,CPU = er.cpu_time ,IOReads = er.logical_reads + er.reads ,IOWrites = er.writes ,Executions = ec.execution_count ,CommandType = er.command ,LastWaitType = er.last_wait_type ,ObjectName = OBJECT_SCHEMA_NAME(qt.objectid,dbid) + '.' + OBJECT_NAME(qt.objectid, qt.dbid) ,SQLStatement = qt.text ,STATUS = ses.STATUS ,[Login] = ses.login_name ,Host = ses.host_name ,DBName = DB_Name(er.database_id) ,StartTime = er.start_time ,Protocol = con.net_transport ,transaction_isolation = CASE ses.transaction_isolation_level WHEN 0 THEN 'Unspecified' WHEN 1 THEN 'Read Uncommitted' WHEN 2 THEN 'Read Committed' WHEN 3 THEN 'Repeatable' WHEN 4 THEN 'Serializable' WHEN 5 THEN 'Snapshot' END ,ConnectionWrites = con.num_writes ,ConnectionReads = con.num_reads ,ClientAddress = con.client_net_address ,Authentication = con.auth_scheme ,DatetimeSnapshot = GETDATE() FROM sys.dm_exec_requests er LEFT JOIN sys.dm_exec_sessions ses ON ses.session_id = er.session_id LEFT JOIN sys.dm_exec_connections con ON con.session_id = ses.session_id OUTER APPLY sys.dm_exec_sql_text(er.sql_handle) AS qt OUTER APPLY ( SELECT execution_count = MAX(cp.usecounts) FROM sys.dm_exec_cached_plans cp WHERE cp.plan_handle = er.plan_handle ) ec OUTER APPLY ( SELECT lead_blocker = 1 FROM master.dbo.sysprocesses sp WHERE sp.spid IN (SELECT blocked FROM master.dbo.sysprocesses) AND sp.blocked = 0 AND sp.spid = er.session_id ) lb WHERE er.sql_handle IS NOT NULL AND er.session_id != @@SPID ORDER BY er.blocking_session_id DESC, er.logical_reads + er.reads DESC, er.session_id

SSIS – Log Execution time

SSIS – Log Execution time

This query helps you to have a better view of your SSIS Packages executions. When you run a “master job / package”, you don’t clearly see the execution time for your child packages in SSISDB Reports. With this query, now it’s possible 🙂
SSIS – Log Execution time

SSIS – Export SSIS Catalog Environments

You need to:

  • Export your SSIS Environments (Variables)
  • Replicate it on your new server
  • Assign these variables to your new project

SSIS Catalog is not complex, but we don’t really want to spend our time to copy manually our configuration from one server to another one.
Often, we don’t have access to the production environment.
The SQL Code below helps you to create a script and automate all these very ennuying steps.

I found the base line of this code on internet: http://www.sqlservercentral.com/articles/Integration+Services+(SSIS)/135173/
Jeff Jordan did a really nice work.

His code helps you to:

  • Create your SSIS Catalog folder
  • Create your SSIS Environment
  • Add SSIS Variables in your SSIS Environment

I added some extra steps:

  • Assign your SSIS Environment to your SSIS Project
  • Assign your SSIS Environment Variables to your SSIS Project Variables
  • + Some correction
  • + A super nice ASCII message when everything is done.. Who can help you to have a smile and maybe a better life. (You should trust the power of smiling 🙂 )

How does it works?

  1. Copy the SQL Script below and paste it into a new blank query in SSMS (Management studio) –> Connected to your existing server (The server who has your environment already configured / Not the new one)
  2. Configuration: Change the XXXX value in the query
    1. @folder : Folder Name (Your configured server)
    2. @env : Environment Name (Your configured server)
    3. @destination_folder_name : Folder Name (Your new server)
    4. @destination_environment_name : Environment Name (Your new server)
    5. @destination_project_name : Project Name (Your new server)
  3. Run your query and copy the result into a new blank query in SSMS. –> Connected to your new server
  4. FIRST OF ALL: You should deploy your SSIS Project!! With the Deployment wizard or Visual Studio
  5. Change the configuration information into the generated query
  6. Run the query
  7. Smile 🙂